From 66c0cc070a0d9df9689b157f0f5171a69b7a1ec6 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sat, 23 Apr 2022 14:43:03 +0200 Subject: [PATCH] removed old shopping list --- cookbook/filters.py | 21 +- cookbook/tables.py | 12 +- cookbook/templates/generic/list_template.html | 9 - cookbook/templates/meal_plan_new.html | 36 - cookbook/templates/shopping_list.html | 921 ------------------ cookbook/urls.py | 6 +- cookbook/views/lists.py | 35 +- cookbook/views/views.py | 37 +- vue/src/components/RecipeContextMenu.vue | 5 +- vue/src/locales/en.json | 1 - 10 files changed, 17 insertions(+), 1066 deletions(-) delete mode 100644 cookbook/templates/meal_plan_new.html delete mode 100644 cookbook/templates/shopping_list.html diff --git a/cookbook/filters.py b/cookbook/filters.py index 30d42cf7..ac377abc 100644 --- a/cookbook/filters.py +++ b/cookbook/filters.py @@ -6,7 +6,7 @@ from django.utils.translation import gettext as _ from django_scopes import scopes_disabled from cookbook.forms import MultiSelectWidget -from cookbook.models import Food, Keyword, Recipe, ShoppingList +from cookbook.models import Food, Keyword, Recipe with scopes_disabled(): class RecipeFilter(django_filters.FilterSet): @@ -60,22 +60,3 @@ with scopes_disabled(): class Meta: model = Recipe fields = ['name', 'keywords', 'foods', 'internal'] - - # class FoodFilter(django_filters.FilterSet): - # name = django_filters.CharFilter(lookup_expr='icontains') - - # class Meta: - # model = Food - # fields = ['name'] - - class ShoppingListFilter(django_filters.FilterSet): - - def __init__(self, data=None, *args, **kwargs): - if data is not None: - data = data.copy() - data.setdefault("finished", False) - super().__init__(data, *args, **kwargs) - - class Meta: - model = ShoppingList - fields = ['finished'] diff --git a/cookbook/tables.py b/cookbook/tables.py index 1829c6f5..2831c39d 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -3,8 +3,8 @@ from django.utils.html import format_html from django.utils.translation import gettext as _ from django_tables2.utils import A -from .models import (CookLog, InviteLink, Keyword, Recipe, RecipeImport, - ShoppingList, Storage, Sync, SyncLog, ViewLog) +from .models import (CookLog, InviteLink, Recipe, RecipeImport, + Storage, Sync, SyncLog, ViewLog) class ImageUrlColumn(tables.Column): @@ -121,14 +121,6 @@ class RecipeImportTable(tables.Table): fields = ('id', 'name', 'file_path') -class ShoppingListTable(tables.Table): - id = tables.LinkColumn('view_shopping', args=[A('id')]) - - class Meta: - model = ShoppingList - template_name = 'generic/table_template.html' - fields = ('id', 'finished', 'created_by', 'created_at') - class InviteLinkTable(tables.Table): link = tables.TemplateColumn( diff --git a/cookbook/templates/generic/list_template.html b/cookbook/templates/generic/list_template.html index 7d4be443..84605ce3 100644 --- a/cookbook/templates/generic/list_template.html +++ b/cookbook/templates/generic/list_template.html @@ -26,15 +26,6 @@ {% endif %} - {% if request.resolver_match.url_name in 'list_shopping_list' %} - - - - - - {% endif %} {% if filter %}
diff --git a/cookbook/templates/meal_plan_new.html b/cookbook/templates/meal_plan_new.html deleted file mode 100644 index f835d72a..00000000 --- a/cookbook/templates/meal_plan_new.html +++ /dev/null @@ -1,36 +0,0 @@ -{% extends "base.html" %} -{% load render_bundle from webpack_loader %} -{% load static %} -{% load i18n %} -{% load l10n %} - -{% block title %}{% trans 'Meal-Plan' %}{% endblock %} - -{% block content_fluid %} - -
- -
- - -{% endblock %} - - -{% block script %} - {% if debug %} - - {% else %} - - {% endif %} - - - - {% render_bundle 'meal_plan_view' %} -{% endblock %} \ No newline at end of file diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html deleted file mode 100644 index 2720d589..00000000 --- a/cookbook/templates/shopping_list.html +++ /dev/null @@ -1,921 +0,0 @@ -{% extends "base.html" %} -{% comment %} TODO: Deprecate {% endcomment %} -{% load django_tables2 %} -{% load crispy_forms_tags %} -{% load static %} -{% load i18n %} -{% block title %}{% trans "Shopping List" %}{% endblock %} -{% block extra_head %} -{% include 'include/vue_base.html' %} - - - - - - - - - - - - -{% endblock %} - -{% block content %} - -
- -

{% trans 'Shopping List' %}

-
- - - - - -
- {% trans 'Edit' %} -
-
- - - -{% endblock %} {% block script %} - - - - -{% endblock %} diff --git a/cookbook/urls.py b/cookbook/urls.py index 90c81d1e..32cfc7b5 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -64,10 +64,8 @@ urlpatterns = [ path('books/', views.books, name='view_books'), path('plan/', views.meal_plan, name='view_plan'), 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('shopping/new/', lists.shopping_list_new, name='view_shopping_new'), + path('shopping/latest/', lists.shopping_list, name='view_shopping_latest'), + path('shopping/', lists.shopping_list, name='view_shopping'), path('settings/', views.user_settings, name='view_settings'), path('history/', views.history, name='view_history'), path('supermarket/', views.supermarket, name='view_supermarket'), diff --git a/cookbook/views/lists.py b/cookbook/views/lists.py index 1f021354..1da69f8f 100644 --- a/cookbook/views/lists.py +++ b/cookbook/views/lists.py @@ -1,14 +1,13 @@ from datetime import datetime -from django.db.models import Q, Sum +from django.db.models import Sum from django.shortcuts import render from django.utils.translation import gettext as _ from django_tables2 import RequestConfig -from cookbook.filters import ShoppingListFilter from cookbook.helper.permission_helper import group_required -from cookbook.models import InviteLink, RecipeImport, ShoppingList, Storage, SyncLog, UserFile -from cookbook.tables import (ImportLogTable, InviteLinkTable, RecipeImportTable, ShoppingListTable, +from cookbook.models import InviteLink, RecipeImport, Storage, SyncLog, UserFile +from cookbook.tables import (ImportLogTable, InviteLinkTable, RecipeImportTable, StorageTable) @@ -41,20 +40,12 @@ def recipe_import(request): @group_required('user') def shopping_list(request): - f = ShoppingListFilter(request.GET, queryset=ShoppingList.objects.filter(space=request.space).filter( - Q(created_by=request.user) | Q(shared=request.user)).distinct().all().order_by('finished', 'created_at')) - - table = ShoppingListTable(f.qs) - RequestConfig(request, paginate={'per_page': 25}).configure(table) - return render( request, - 'generic/list_template.html', + 'shoppinglist_template.html', { - 'title': _("Shopping Lists"), - 'table': table, - 'filter': f, - 'create_url': 'view_shopping' + "title": _("Shopping List"), + } ) @@ -205,7 +196,7 @@ def custom_filter(request): def user_file(request): try: current_file_size_mb = UserFile.objects.filter(space=request.space).aggregate(Sum('file_size_kb'))[ - 'file_size_kb__sum'] / 1000 + 'file_size_kb__sum'] / 1000 except TypeError: current_file_size_mb = 0 @@ -237,15 +228,3 @@ def step(request): } } ) - - -@group_required('user') -def shopping_list_new(request): - return render( - request, - 'shoppinglist_template.html', - { - "title": _("New Shopping List"), - - } - ) diff --git a/cookbook/views/views.py b/cookbook/views/views.py index ec1553d1..25b1f1cd 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -11,9 +11,9 @@ from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.models import Group from django.contrib.auth.password_validation import validate_password from django.core.exceptions import ValidationError -from django.db.models import Avg, Q, Sum +from django.db.models import Avg, Q from django.db.models.functions import Lower -from django.http import HttpResponseRedirect, JsonResponse +from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse, reverse_lazy from django.utils import timezone @@ -27,9 +27,9 @@ from cookbook.forms import (CommentForm, Recipe, SearchPreferenceForm, ShoppingP SpaceCreateForm, SpaceJoinForm, SpacePreferenceForm, User, UserCreateForm, UserNameForm, UserPreference, UserPreferenceForm) from cookbook.helper.permission_helper import group_required, has_group_permission, share_link_valid -from cookbook.models import (Comment, CookLog, Food, FoodInheritField, InviteLink, Keyword, +from cookbook.models import (Comment, CookLog, Food, InviteLink, Keyword, MealPlan, RecipeImport, SearchFields, SearchPreference, ShareLink, - ShoppingList, Space, Unit, UserFile, ViewLog) + Space, Unit, ViewLog) from cookbook.tables import (CookLogTable, InviteLinkTable, RecipeTable, RecipeTableSmall, ViewLogTable) from cookbook.views.data import Object @@ -256,35 +256,6 @@ def meal_plan_entry(request, pk): return render(request, 'meal_plan_entry.html', {'plan': plan, 'same_day_plan': same_day_plan}) -@group_required('user') -def latest_shopping_list(request): - sl = ShoppingList.objects.filter(Q(created_by=request.user) | Q(shared=request.user)).filter(finished=False, - space=request.space).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): # TODO deprecate - html_list = request.GET.getlist('r') - - recipes = [] - for r in html_list: - r = r.replace('[', '').replace(']', '') - if len(r) < 10000 and re.match(r'^([0-9])+,([0-9])+[.]*([0-9])*$', r): - rid, multiplier = r.split(',') - if recipe := Recipe.objects.filter(pk=int(rid), space=request.space).first(): - recipes.append({'recipe': recipe.id, 'multiplier': multiplier}) - - 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') def user_settings(request): if request.space.demo: diff --git a/vue/src/components/RecipeContextMenu.vue b/vue/src/components/RecipeContextMenu.vue index 682cd6c2..67a63145 100644 --- a/vue/src/components/RecipeContextMenu.vue +++ b/vue/src/components/RecipeContextMenu.vue @@ -14,10 +14,7 @@ - - {{ $t("Add_to_Shopping") }} - - {{ $t("create_shopping_new") }} + {{ $t("Add_to_Shopping") }} {{ $t("Add_to_Plan") }} diff --git a/vue/src/locales/en.json b/vue/src/locales/en.json index 6a3f1810..f1d23db9 100644 --- a/vue/src/locales/en.json +++ b/vue/src/locales/en.json @@ -270,7 +270,6 @@ "CategoryInstruction": "Drag categories to change the order categories appear in shopping list.", "shopping_recent_days_desc": "Days of recent shopping list entries to display.", "shopping_recent_days": "Recent Days", - "create_shopping_new": "Add to NEW Shopping List", "download_pdf": "Download PDF", "download_csv": "Download CSV", "csv_delim_help": "Delimiter to use for CSV exports.",