diff --git a/cookbook/static/manifest/shopping-cart-192.png b/cookbook/static/manifest/shopping-cart-192.png new file mode 100644 index 00000000..11d69652 Binary files /dev/null and b/cookbook/static/manifest/shopping-cart-192.png differ diff --git a/cookbook/static/manifest/webmanifest b/cookbook/static/manifest/webmanifest index c33f63f3..1a236978 100644 --- a/cookbook/static/manifest/webmanifest +++ b/cookbook/static/manifest/webmanifest @@ -35,10 +35,17 @@ }, { "name": "Shopping", - "short_name": "Shopping List", + "short_name": "Shopping", "description": "View your shopping lists", "url": "/list/shopping-list/", - "icons": [{ "src": "/static/manifest/icon-192.png", "sizes": "192x192" }] + "icons": [{ "src": "/static/manifest/shopping-cart-192.png", "sizes": "192x192" }] + }, + { + "name": "Latest Shopping List", + "short_name": "Shopping List", + "description": "View the latest shopping list", + "url": "/shopping/latest/", + "icons": [{ "src": "/static/manifest/shopping-cart-192.png", "sizes": "192x192" }] } ] } diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html index c0643a77..5020e70c 100644 --- a/cookbook/templates/shopping_list.html +++ b/cookbook/templates/shopping_list.html @@ -394,7 +394,11 @@ data: { shopping_list_id: {% if shopping_list_id %}{{ shopping_list_id }}{% else %}null{% endif %}, loading: true, - edit_mode: false, + {% if edit %} + edit_mode: true, + {% else %} + edit_mode: false, + {% endif %} export_text_prefix: '', //TODO add userpreference recipe_query: '', recipes: [], diff --git a/cookbook/urls.py b/cookbook/urls.py index 5d211e1a..e64c77ad 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -48,6 +48,7 @@ urlpatterns = [ path('plan/entry/', views.meal_plan_entry, name='view_plan_entry'), path('shopping/', views.shopping_list, name='view_shopping'), path('shopping/', views.shopping_list, name='view_shopping'), + path('shopping/latest', views.latest_shopping_list, name='view_shopping_latest'), path('settings/', views.user_settings, name='view_settings'), path('history/', views.history, name='view_history'), path('test/', views.test, name='view_test'), diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 57cf0e31..c9d22ad0 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -25,7 +25,7 @@ from cookbook.forms import (CommentForm, Recipe, RecipeBookEntryForm, User, UserPreferenceForm) from cookbook.helper.permission_helper import group_required, share_link_valid, has_group_permission from cookbook.models import (Comment, CookLog, InviteLink, MealPlan, - RecipeBook, RecipeBookEntry, ViewLog) + RecipeBook, RecipeBookEntry, ViewLog, ShoppingList) from cookbook.tables import (CookLogTable, RecipeTable, RecipeTableSmall, ViewLogTable) from recipes.settings import DEMO @@ -232,6 +232,16 @@ def meal_plan_entry(request, pk): ) +@group_required('user') +def latest_shopping_list(request): + sl = ShoppingList.objects.filter(Q(created_by=request.user) | Q(shared=request.user)).filter(finished=False).order_by('-created_at').first() + + if sl: + return HttpResponseRedirect(reverse('view_shopping', kwargs={'pk': sl.pk}) + '?edit=true') + else: + return HttpResponseRedirect(reverse('view_shopping') + '?edit=true') + + @group_required('user') def shopping_list(request, pk=None): raw_list = request.GET.getlist('r') @@ -244,11 +254,9 @@ def shopping_list(request, pk=None): if recipe := Recipe.objects.filter(pk=int(rid)).first(): recipes.append({'recipe': recipe.id, 'multiplier': multiplier}) - return render( - request, - 'shopping_list.html', - {'shopping_list_id': pk, 'recipes': recipes} - ) + edit = True if 'edit' in request.GET and request.GET['edit'] == 'true' else False + + return render(request, 'shopping_list.html', {'shopping_list_id': pk, 'recipes': recipes, 'edit': edit}) @group_required('guest')