From 7bc09dfe89bc58121dd47c5d1db2bea4a77f32d2 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Tue, 29 Sep 2020 14:15:18 +0200 Subject: [PATCH] finishes shopping lists --- cookbook/filters.py | 8 +++++++- .../migrations/0089_shoppinglist_finished.py | 18 ++++++++++++++++++ cookbook/models.py | 1 + cookbook/serializer.py | 2 +- cookbook/tables.py | 2 +- cookbook/templates/generic/list_template.html | 2 +- cookbook/templates/shopping_list.html | 15 +++++++++++++-- cookbook/views/lists.py | 8 +++++--- 8 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 cookbook/migrations/0089_shoppinglist_finished.py diff --git a/cookbook/filters.py b/cookbook/filters.py index 91643500..6d0894d5 100644 --- a/cookbook/filters.py +++ b/cookbook/filters.py @@ -2,7 +2,7 @@ import django_filters from django.contrib.postgres.search import TrigramSimilarity from django.db.models import Q from cookbook.forms import MultiSelectWidget -from cookbook.models import Recipe, Keyword, Food +from cookbook.models import Recipe, Keyword, Food, ShoppingList from django.conf import settings from django.utils.translation import gettext as _ @@ -52,3 +52,9 @@ class IngredientFilter(django_filters.FilterSet): class Meta: model = Food fields = ['name'] + + +class ShoppingListFilter(django_filters.FilterSet): + class Meta: + model = ShoppingList + fields = ['finished'] diff --git a/cookbook/migrations/0089_shoppinglist_finished.py b/cookbook/migrations/0089_shoppinglist_finished.py new file mode 100644 index 00000000..3bad27b2 --- /dev/null +++ b/cookbook/migrations/0089_shoppinglist_finished.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.1 on 2020-09-29 11:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0088_auto_20200929_1202'), + ] + + operations = [ + migrations.AddField( + model_name='shoppinglist', + name='finished', + field=models.BooleanField(default=False), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 06d858a2..2f1309e1 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -312,6 +312,7 @@ class ShoppingList(models.Model): recipes = models.ManyToManyField(ShoppingListRecipe, blank=True) entries = models.ManyToManyField(ShoppingListEntry, blank=True) shared = models.ManyToManyField(User, blank=True, related_name='list_share') + finished = models.BooleanField(default=False) created_by = models.ForeignKey(User, on_delete=models.CASCADE) created_at = models.DateTimeField(auto_now_add=True) diff --git a/cookbook/serializer.py b/cookbook/serializer.py index b59653e2..d37c145d 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -234,7 +234,7 @@ class ShoppingListSerializer(WritableNestedModelSerializer): class Meta: model = ShoppingList - fields = ('id', 'uuid', 'note', 'recipes', 'entries', 'shared', 'created_by', 'created_at',) + fields = ('id', 'uuid', 'note', 'recipes', 'entries', 'shared', 'finished', 'created_by', 'created_at',) read_only_fields = ('id',) diff --git a/cookbook/tables.py b/cookbook/tables.py index e5c99cd9..a29a7536 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -114,7 +114,7 @@ class ShoppingListTable(tables.Table): class Meta: model = ShoppingList template_name = 'generic/table_template.html' - fields = ('id', 'created_by', 'created_at') + fields = ('id', 'finished', 'created_by', 'created_at') class InviteLinkTable(tables.Table): diff --git a/cookbook/templates/generic/list_template.html b/cookbook/templates/generic/list_template.html index b330ef32..bd69e526 100644 --- a/cookbook/templates/generic/list_template.html +++ b/cookbook/templates/generic/list_template.html @@ -9,7 +9,7 @@ {% block content %}
-

{{ title }} {% trans 'List' %} +

{{ title }} {% trans 'List' %} {% if create_url %} diff --git a/cookbook/templates/shopping_list.html b/cookbook/templates/shopping_list.html index 6b71c738..dd0bfde8 100644 --- a/cookbook/templates/shopping_list.html +++ b/cookbook/templates/shopping_list.html @@ -183,6 +183,17 @@

+
+
+ +
+ + +
+ +
+
+
@@ -450,7 +461,7 @@ console.log("proceeding to update shopping list", this.shopping_list) if (this.shopping_list_id === null) { - this.$http.post("{% url 'api:shoppinglist-list' %}", this.shopping_list, {}).then((response) => { + return this.$http.post("{% url 'api:shoppinglist-list' %}", this.shopping_list, {}).then((response) => { console.log(response) this.makeToast('{% trans 'Updated' %}', '{% trans 'Object created successfully!' %}', 'success') this.loading = false @@ -465,7 +476,7 @@ this.loading = false }) } else { - this.$http.put("{% url 'api:shoppinglist-detail' shopping_list_id %}", this.shopping_list, {}).then((response) => { + return this.$http.put("{% url 'api:shoppinglist-detail' shopping_list_id %}", this.shopping_list, {}).then((response) => { console.log(response) this.shopping_list = response.body this.makeToast('{% trans 'Updated' %}', '{% trans 'Changes saved successfully!' %}', 'success') diff --git a/cookbook/views/lists.py b/cookbook/views/lists.py index 0c0dc20d..1c272362 100644 --- a/cookbook/views/lists.py +++ b/cookbook/views/lists.py @@ -6,7 +6,7 @@ from django.shortcuts import render from django.utils.translation import gettext as _ from django_tables2 import RequestConfig -from cookbook.filters import IngredientFilter +from cookbook.filters import IngredientFilter, ShoppingListFilter from cookbook.helper.permission_helper import group_required from cookbook.models import Keyword, SyncLog, RecipeImport, Storage, Food, ShoppingList, InviteLink from cookbook.tables import KeywordTable, ImportLogTable, RecipeImportTable, StorageTable, IngredientTable, ShoppingListTable, InviteLinkTable @@ -49,10 +49,12 @@ def food(request): @group_required('user') def shopping_list(request): - table = ShoppingListTable(ShoppingList.objects.filter(created_by=request.user).all()) + f = ShoppingListFilter(request.GET, queryset=ShoppingList.objects.filter(created_by=request.user).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', {'title': _("Shopping Lists"), 'table': table, 'create_url': 'view_shopping'}) + return render(request, 'generic/list_template.html', {'title': _("Shopping Lists"), 'table': table, 'filter': f, 'create_url': 'view_shopping'}) @group_required('admin')