messages + misc

This commit is contained in:
Unknown
2018-02-09 12:59:28 +01:00
parent 3499cb7994
commit d3a169a20d
16 changed files with 136 additions and 815 deletions

View File

@ -1,6 +1,8 @@
from django.contrib.auth.decorators import login_required
from django.contrib import messages
from django.shortcuts import redirect, render
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from cookbook.forms import EditRecipeForm
from cookbook.models import Recipe, Category
@ -18,7 +20,10 @@ def recipe(request, recipe_id):
recipe_obj.keywords.clear()
recipe_obj.keywords.add(*list(form.cleaned_data['keywords']))
recipe_obj.save()
messages.add_message(request, messages.SUCCESS, _('Recipe updated'))
return redirect(reverse_lazy('edit_recipe', args=[recipe_id]))
else:
messages.add_message(request, messages.ERROR, _('Recipe update failed'))
else:
form = EditRecipeForm(instance=recipe_obj)