Compare commits
No commits in common. "bc440dfa2ab071a32a73043a13b6aa4efa99d0a6" and "f38fb8d410d45a7c4fa1e9b8bfa8c38dbbaf2482" have entirely different histories.
bc440dfa2a
...
f38fb8d410
|
|
@ -1,4 +1,4 @@
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404
|
||||||
from .models import Recipe, Version, Ingredient
|
from .models import Recipe, Version, Ingredient
|
||||||
from .forms import RecipeForm, VersionForm, IngredientFormSet
|
from .forms import RecipeForm, VersionForm, IngredientFormSet
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
@ -72,16 +72,6 @@ def add_recipe(request):
|
||||||
def edit_recipe(request, slug):
|
def edit_recipe(request, slug):
|
||||||
recipe = get_object_or_404(Recipe, slug=slug)
|
recipe = get_object_or_404(Recipe, slug=slug)
|
||||||
|
|
||||||
# It is assumed every recipe has at least one version
|
|
||||||
if not request.user.is_superuser:
|
|
||||||
users = set()
|
|
||||||
|
|
||||||
for version in recipe.versions.all(): # type: ignore
|
|
||||||
users.add(version.user)
|
|
||||||
|
|
||||||
if len(users) > 1 or (len(users) == 1 and next(iter(users)) != request.user):
|
|
||||||
return redirect(f"/accounts/login/?next={request.path}")
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = RecipeForm(request.POST, instance=recipe, prefix=RECIPE_FORM_PREFIX)
|
form = RecipeForm(request.POST, instance=recipe, prefix=RECIPE_FORM_PREFIX)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
|
|
@ -123,9 +113,6 @@ def edit_version(request, slug_recipe, slug_version):
|
||||||
recipe = get_object_or_404(Recipe, slug=slug_recipe)
|
recipe = get_object_or_404(Recipe, slug=slug_recipe)
|
||||||
version = get_object_or_404(Version, recipe=recipe, slug=slug_version)
|
version = get_object_or_404(Version, recipe=recipe, slug=slug_version)
|
||||||
|
|
||||||
if version.user != request.user and not request.user.is_superuser:
|
|
||||||
return redirect(f"/accounts/login/?next={request.path}")
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
version_form = VersionForm(request.POST, prefix=VERSION_FORM_PREFIX, instance=version, author_placeholder=get_name_of_user(request.user))
|
version_form = VersionForm(request.POST, prefix=VERSION_FORM_PREFIX, instance=version, author_placeholder=get_name_of_user(request.user))
|
||||||
ingredients_formset = IngredientFormSet(request.POST, queryset=version.ingredients.all(), prefix=INGREDIENTS_FORMSET_PREFIX) # type: ignore
|
ingredients_formset = IngredientFormSet(request.POST, queryset=version.ingredients.all(), prefix=INGREDIENTS_FORMSET_PREFIX) # type: ignore
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
{% if next %}
|
{% if next %}
|
||||||
<section>
|
<section>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<p>You are not authorized to access this site. Please log in with an account with the necessary permissions.</p>
|
<p>You are not authorized to access this site. Please inform Benjamin to get the corresponding authorization or log in with an account with the necessary permissions.</p>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Please log in to view this site.</p>
|
<p>Please log in to view this site.</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue