Add serving size to recipe url so it loads with num
This commit is contained in:
parent
29438109a6
commit
13f532a67b
@ -79,6 +79,7 @@
|
|||||||
|
|
||||||
window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}'
|
window.CUSTOM_LOCALE = '{{ request.LANGUAGE_CODE }}'
|
||||||
window.RECIPE_ID = {{recipe.pk}};
|
window.RECIPE_ID = {{recipe.pk}};
|
||||||
|
window.RECIPE_SERVINGS = '{{ servings }}'
|
||||||
window.SHARE_UID = '{{ share }}';
|
window.SHARE_UID = '{{ share }}';
|
||||||
window.USER_PREF = {
|
window.USER_PREF = {
|
||||||
'use_fractions': {% if request.user.userpreference.use_fractions %} true {% else %} false {% endif %},
|
'use_fractions': {% if request.user.userpreference.use_fractions %} true {% else %} false {% endif %},
|
||||||
|
@ -101,6 +101,8 @@ urlpatterns = [
|
|||||||
path('export-file/<int:pk>/', import_export.export_file, name='view_export_file'),
|
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>', 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('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'),
|
path('new/recipe-import/<int:import_id>/', new.create_new_external_recipe, name='new_recipe_import'),
|
||||||
|
@ -130,7 +130,7 @@ def no_perm(request):
|
|||||||
return render(request, 'no_perm_info.html')
|
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():
|
with scopes_disabled():
|
||||||
recipe = get_object_or_404(Recipe, pk=pk)
|
recipe = get_object_or_404(Recipe, pk=pk)
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ def recipe_view(request, pk, share=None):
|
|||||||
ViewLog.objects.create(recipe=recipe, created_by=request.user, space=request.space)
|
ViewLog.objects.create(recipe=recipe, created_by=request.user, space=request.space)
|
||||||
|
|
||||||
return render(request, 'recipe_view.html',
|
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')
|
@group_required('user')
|
||||||
|
@ -237,6 +237,7 @@ export default {
|
|||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
recipe_id: Number,
|
recipe_id: Number,
|
||||||
|
def_servings: Number,
|
||||||
recipe_obj: {type: Object, default: null},
|
recipe_obj: {type: Object, default: null},
|
||||||
show_context_menu: {type: Boolean, default: true},
|
show_context_menu: {type: Boolean, default: true},
|
||||||
enable_keyword_links: {type: Boolean, default: true},
|
enable_keyword_links: {type: Boolean, default: true},
|
||||||
@ -320,8 +321,12 @@ export default {
|
|||||||
|
|
||||||
|
|
||||||
if (this.recipe.image === null) this.printReady()
|
if (this.recipe.image === null) this.printReady()
|
||||||
|
if (window.RECIPE_SERVINGS && window.RECIPE_SERVINGS !== "None") {
|
||||||
this.servings = this.servings_cache[this.rootrecipe.id] = this.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 {
|
||||||
|
this.servings = this.servings_cache[this.rootrecipe.id] = this.recipe.servings
|
||||||
|
}
|
||||||
this.loading = false
|
this.loading = false
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user