mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 16:09:44 +00:00
Add JSON export
This commit is contained in:
parent
022d36041c
commit
5699f8234a
3 changed files with 27 additions and 2 deletions
|
|
@ -16,7 +16,8 @@
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from flask import Blueprint, flash, redirect, render_template, request, url_for
|
from flask import (Blueprint, flash, redirect, render_template, jsonify,
|
||||||
|
request, url_for)
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import (Form, StringField, DecimalField, TextAreaField, FieldList,
|
from wtforms import (Form, StringField, DecimalField, TextAreaField, FieldList,
|
||||||
FormField, SelectField)
|
FormField, SelectField)
|
||||||
|
|
@ -223,6 +224,16 @@ def info(id):
|
||||||
return render_template('recipes/info.html', recipe=get_doc_or_404(id))
|
return render_template('recipes/info.html', recipe=get_doc_or_404(id))
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/info/<id>/json')
|
||||||
|
def info_json(id):
|
||||||
|
recipe = get_doc_or_404(id)
|
||||||
|
# Remove fields specific not intended for export
|
||||||
|
recipe.pop('_id')
|
||||||
|
recipe.pop('_rev')
|
||||||
|
recipe.pop('$type')
|
||||||
|
return jsonify(recipe)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/delete/<id>', methods=('POST',))
|
@bp.route('/delete/<id>', methods=('POST',))
|
||||||
@login_required
|
@login_required
|
||||||
def delete(id):
|
def delete(id):
|
||||||
|
|
|
||||||
|
|
@ -173,5 +173,6 @@
|
||||||
</div>
|
</div>
|
||||||
{{ render_delete_modal(url_for('recipes.delete', id=recipe._id), 'deleteRecipe', recipe.name) }}
|
{{ render_delete_modal(url_for('recipes.delete', id=recipe._id), 'deleteRecipe', recipe.name) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="row small mt-4">Recipe revision: {{ recipe._rev }}</div>
|
<div class="row mt-4"><a href="{{ url_for('recipes.info_json', id=recipe._id) }}">Export JSON</a></div>
|
||||||
|
<div class="row">Recipe revision: {{ recipe._rev }}</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,19 @@ def test_info(client):
|
||||||
assert b'Awesome Lager' in response.data
|
assert b'Awesome Lager' in response.data
|
||||||
|
|
||||||
|
|
||||||
|
def test_info_json(client):
|
||||||
|
"""Test success in retrieving a JSON recipe."""
|
||||||
|
# Validate 404
|
||||||
|
response = client.get('/recipes/info/thisdoesnotexist/json')
|
||||||
|
assert response.status_code == 404
|
||||||
|
|
||||||
|
# Validate response for existing doc
|
||||||
|
response = client.get('/recipes/info/awesome-lager/json')
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.is_json
|
||||||
|
assert response.get_json()['name'] == 'Awesome Lager'
|
||||||
|
|
||||||
|
|
||||||
def test_yeast_form_doc(app):
|
def test_yeast_form_doc(app):
|
||||||
"""Evaluates conditionals in generation of doc from a yeast form."""
|
"""Evaluates conditionals in generation of doc from a yeast form."""
|
||||||
yeast = YeastForm()
|
yeast = YeastForm()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue