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}
|
||||
|
||||
|
||||
class RecipeForm(forms.Form):
|
||||
class ShoppingForm(forms.Form):
|
||||
recipe = forms.ModelMultipleChoiceField(
|
||||
queryset=Recipe.objects.all(),
|
||||
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):
|
||||
|
@ -26,7 +26,7 @@
|
||||
<div class="row">
|
||||
<div class="col col-md-12">
|
||||
<!--// @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-->
|
||||
</div>
|
||||
</div>
|
||||
|
@ -117,10 +117,13 @@ def meal_plan(request):
|
||||
|
||||
@login_required
|
||||
def shopping_list(request):
|
||||
markdown_format = True
|
||||
|
||||
if request.method == "POST":
|
||||
form = RecipeForm(request.POST)
|
||||
form = ShoppingForm(request.POST)
|
||||
if form.is_valid():
|
||||
recipes = form.cleaned_data['recipe']
|
||||
markdown_format = form.cleaned_data['markdown_format']
|
||||
else:
|
||||
recipes = []
|
||||
else:
|
||||
@ -132,7 +135,7 @@ def shopping_list(request):
|
||||
if Recipe.objects.filter(pk=int(r)).exists():
|
||||
recipes.append(int(r))
|
||||
|
||||
form = RecipeForm(initial={'recipe': recipes})
|
||||
form = ShoppingForm(initial={'recipe': recipes})
|
||||
|
||||
ingredients = []
|
||||
|
||||
@ -148,7 +151,7 @@ def shopping_list(request):
|
||||
else:
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user