From 13f532a67b64a220f6a05cbe9d8547508ba2843a Mon Sep 17 00:00:00 2001 From: Patrick Magauran Date: Tue, 6 Feb 2024 22:21:37 -0500 Subject: [PATCH] Add serving size to recipe url so it loads with num --- cookbook/templates/recipe_view.html | 1 + cookbook/urls.py | 2 ++ cookbook/views/views.py | 6 +++--- vue/src/components/RecipeViewComponent.vue | 9 +++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index 2ec2b117..c0f62d47 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -79,6 +79,7 @@ window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}' window.RECIPE_ID = {{recipe.pk}}; + window.RECIPE_SERVINGS = '{{ servings }}' window.SHARE_UID = '{{ share }}'; window.USER_PREF = { 'use_fractions': {% if request.user.userpreference.use_fractions %} true {% else %} false {% endif %}, diff --git a/cookbook/urls.py b/cookbook/urls.py index 9566541a..954281d6 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -101,6 +101,8 @@ 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 1c12c77d..c7975dec 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, share=None): +def recipe_view(request, pk, servings=None, share=None): with scopes_disabled(): recipe = get_object_or_404(Recipe, pk=pk) @@ -171,9 +171,9 @@ def recipe_view(request, pk, 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) - + return render(request, 'recipe_view.html', - {'recipe': recipe, 'comments': comments, 'comment_form': comment_form, 'share': share, }) + {'recipe': recipe, 'comments': comments, 'comment_form': comment_form, 'share': share, 'servings': servings }) @group_required('user') diff --git a/vue/src/components/RecipeViewComponent.vue b/vue/src/components/RecipeViewComponent.vue index 07a051ad..c8317a73 100644 --- a/vue/src/components/RecipeViewComponent.vue +++ b/vue/src/components/RecipeViewComponent.vue @@ -237,6 +237,7 @@ export default { }, props: { recipe_id: Number, + def_servings: Number, recipe_obj: {type: Object, default: null}, show_context_menu: {type: Boolean, default: true}, enable_keyword_links: {type: Boolean, default: true}, @@ -320,8 +321,12 @@ export default { if (this.recipe.image === null) this.printReady() - - this.servings = this.servings_cache[this.rootrecipe.id] = this.recipe.servings + if (window.RECIPE_SERVINGS && window.RECIPE_SERVINGS !== "None") { + //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 { + this.servings = this.servings_cache[this.rootrecipe.id] = this.recipe.servings + } this.loading = false setTimeout(() => {