added sharing links and appropriate tests

This commit is contained in:
vabene1111
2020-06-16 11:23:58 +02:00
parent 17946c8dac
commit dee7249347
10 changed files with 118 additions and 7 deletions

View File

@ -18,7 +18,7 @@ from django.conf import settings
from cookbook.filters import RecipeFilter
from cookbook.forms import *
from cookbook.helper.permission_helper import group_required
from cookbook.helper.permission_helper import group_required, share_link_valid
from cookbook.tables import RecipeTable, RecipeTableSmall, CookLogTable, ViewLogTable
from recipes.version import *
@ -70,9 +70,13 @@ def search(request):
return render(request, 'index.html')
@group_required('guest')
def recipe_view(request, pk):
def recipe_view(request, pk, share=None):
recipe = get_object_or_404(Recipe, pk=pk)
if not request.user.is_authenticated and not share_link_valid(recipe, share):
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
return HttpResponseRedirect(reverse('index'))
ingredients = RecipeIngredient.objects.filter(recipe=recipe)
comments = Comment.objects.filter(recipe=recipe)