From cf190734b21f4289d40c88c1f944693474a02ea0 Mon Sep 17 00:00:00 2001 From: Patrick Magauran Date: Tue, 13 Feb 2024 20:59:04 -0500 Subject: [PATCH] Switches to named GET Parameter for servings --- cookbook/urls.py | 2 -- cookbook/views/views.py | 5 +++-- vue/src/apps/MealPlanView/MealPlanView.vue | 2 +- vue/src/components/RecipeViewComponent.vue | 3 ++- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cookbook/urls.py b/cookbook/urls.py index 954281d6..9566541a 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -101,8 +101,6 @@ urlpatterns = [ path('export-file//', import_export.export_file, name='view_export_file'), path('view/recipe/', views.recipe_view, name='view_recipe'), - path('view/recipe/-', views.recipe_view, name='view_recipe'), - path('view/recipe/-/', views.recipe_view, name='view_recipe'), path('view/recipe//', views.recipe_view, name='view_recipe'), path('new/recipe-import//', new.create_new_external_recipe, name='new_recipe_import'), diff --git a/cookbook/views/views.py b/cookbook/views/views.py index c7975dec..6454cf0d 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -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 }) diff --git a/vue/src/apps/MealPlanView/MealPlanView.vue b/vue/src/apps/MealPlanView/MealPlanView.vue index 5119194b..dc51fa23 100644 --- a/vue/src/apps/MealPlanView/MealPlanView.vue +++ b/vue/src/apps/MealPlanView/MealPlanView.vue @@ -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) { diff --git a/vue/src/components/RecipeViewComponent.vue b/vue/src/components/RecipeViewComponent.vue index c8317a73..584d354b 100644 --- a/vue/src/components/RecipeViewComponent.vue +++ b/vue/src/components/RecipeViewComponent.vue @@ -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 {