allow choosing output format of shopping list
This commit is contained in:
parent
43d03ed17d
commit
c98dbd065e
@ -73,11 +73,16 @@ class InternalRecipeForm(forms.ModelForm):
|
|||||||
widgets = {'keywords': MultiSelectWidget}
|
widgets = {'keywords': MultiSelectWidget}
|
||||||
|
|
||||||
|
|
||||||
class RecipeForm(forms.Form):
|
class ShoppingForm(forms.Form):
|
||||||
recipe = forms.ModelMultipleChoiceField(
|
recipe = forms.ModelMultipleChoiceField(
|
||||||
queryset=Recipe.objects.all(),
|
queryset=Recipe.objects.all(),
|
||||||
widget=MultiSelectWidget
|
widget=MultiSelectWidget
|
||||||
)
|
)
|
||||||
|
markdown_format = forms.BooleanField(
|
||||||
|
help_text=_('Include <code>- [ ]</code> in list for easier usage in markdown based documents.'),
|
||||||
|
required=False,
|
||||||
|
initial=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UnitMergeForm(forms.Form):
|
class UnitMergeForm(forms.Form):
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
<!--// @formatter:off-->
|
<!--// @formatter:off-->
|
||||||
<textarea id="id_list" style="height: 50vh" class="form-control">{% for i in ingredients %}- [ ] {{ i.amount.normalize }} {{ i.unit }} {{ i.ingredient.name }} {% endfor %}</textarea>
|
<textarea id="id_list" style="height: 50vh" class="form-control">{% for i in ingredients %}{% if markdown_format %}- [ ]{% endif %} {{ i.amount.normalize }} {{ i.unit }} {{ i.ingredient.name }} {% endfor %}</textarea>
|
||||||
<!--// @formatter:on-->
|
<!--// @formatter:on-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -117,10 +117,13 @@ def meal_plan(request):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def shopping_list(request):
|
def shopping_list(request):
|
||||||
|
markdown_format = True
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = RecipeForm(request.POST)
|
form = ShoppingForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
recipes = form.cleaned_data['recipe']
|
recipes = form.cleaned_data['recipe']
|
||||||
|
markdown_format = form.cleaned_data['markdown_format']
|
||||||
else:
|
else:
|
||||||
recipes = []
|
recipes = []
|
||||||
else:
|
else:
|
||||||
@ -132,7 +135,7 @@ def shopping_list(request):
|
|||||||
if Recipe.objects.filter(pk=int(r)).exists():
|
if Recipe.objects.filter(pk=int(r)).exists():
|
||||||
recipes.append(int(r))
|
recipes.append(int(r))
|
||||||
|
|
||||||
form = RecipeForm(initial={'recipe': recipes})
|
form = ShoppingForm(initial={'recipe': recipes})
|
||||||
|
|
||||||
ingredients = []
|
ingredients = []
|
||||||
|
|
||||||
@ -148,7 +151,7 @@ def shopping_list(request):
|
|||||||
else:
|
else:
|
||||||
ingredients.append(ri)
|
ingredients.append(ri)
|
||||||
|
|
||||||
return render(request, 'shopping_list.html', {'ingredients': ingredients, 'recipes': recipes, 'form': form})
|
return render(request, 'shopping_list.html', {'ingredients': ingredients, 'recipes': recipes, 'form': form, 'markdown_format': markdown_format})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
Loading…
Reference in New Issue
Block a user