Switches to named GET Parameter for servings

This commit is contained in:
Patrick Magauran 2024-02-13 20:59:04 -05:00
parent a9a3dd6e51
commit cf190734b2
4 changed files with 6 additions and 6 deletions

View File

@ -101,8 +101,6 @@ urlpatterns = [
path('export-file/<int:pk>/', import_export.export_file, name='view_export_file'),
path('view/recipe/<int:pk>', views.recipe_view, name='view_recipe'),
path('view/recipe/<int:pk>-<int:servings>', views.recipe_view, name='view_recipe'),
path('view/recipe/<int:pk>-<int:servings>/<slug:share>', views.recipe_view, name='view_recipe'),
path('view/recipe/<int:pk>/<slug:share>', views.recipe_view, name='view_recipe'),
path('new/recipe-import/<int:import_id>/', new.create_new_external_recipe, name='new_recipe_import'),

View File

@ -130,7 +130,7 @@ def no_perm(request):
return render(request, 'no_perm_info.html')
def recipe_view(request, pk, servings=None, share=None):
def recipe_view(request, pk, share=None):
with scopes_disabled():
recipe = get_object_or_404(Recipe, pk=pk)
@ -171,7 +171,8 @@ def recipe_view(request, pk, servings=None, share=None):
created_at__gt=(timezone.now() - timezone.timedelta(minutes=5)),
space=request.space).exists():
ViewLog.objects.create(recipe=recipe, created_by=request.user, space=request.space)
if request.method == "GET":
servings = request.GET.get("servings")
return render(request, 'recipe_view.html',
{'recipe': recipe, 'comments': comments, 'comment_form': comment_form, 'share': share, 'servings': servings })

View File

@ -394,7 +394,7 @@ export default {
methods: {
getRecipeURL: function (recipe, servings) {
return this.resolveDjangoUrl("view_recipe",`${recipe.id}-${servings}`)
return this.resolveDjangoUrl("view_recipe",`${recipe.id}?servings=${servings}`)
},
openRecipe: function (recipe, servings) {

View File

@ -321,7 +321,8 @@ export default {
if (this.recipe.image === null) this.printReady()
if (window.RECIPE_SERVINGS && window.RECIPE_SERVINGS !== "None") {
window.RECIPE_SERVINGS = Number(window.RECIPE_SERVINGS)
if (window.RECIPE_SERVINGS && ! isNaN(window.RECIPE_SERVINGS)) {
//I am not sure this is the best way. This overwrites our servings cache, which may not be intended?
this.servings = window.RECIPE_SERVINGS
} else {