From 3a9e5a80baea7befd5f31dc38017a2b12ee7364e Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sat, 2 May 2020 12:48:22 +0200 Subject: [PATCH] final style touches + settings --- cookbook/forms.py | 2 +- .../0037_userpreference_search_style.py | 18 ++++++++++++++++++ cookbook/models.py | 7 +++++++ cookbook/tables.py | 12 ++++++++++++ cookbook/templates/recipes_table.html | 4 +--- cookbook/views/views.py | 8 ++++++-- 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 cookbook/migrations/0037_userpreference_search_style.py diff --git a/cookbook/forms.py b/cookbook/forms.py index 84c14ae1..8a2e3e8f 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -30,7 +30,7 @@ class UserPreferenceForm(forms.ModelForm): class Meta: model = UserPreference - fields = ('default_unit', 'theme', 'nav_color', 'default_page') + fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'search_style') help_texts = { 'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'), diff --git a/cookbook/migrations/0037_userpreference_search_style.py b/cookbook/migrations/0037_userpreference_search_style.py new file mode 100644 index 00000000..c90e3fed --- /dev/null +++ b/cookbook/migrations/0037_userpreference_search_style.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-05-02 10:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0036_auto_20200427_1800'), + ] + + operations = [ + migrations.AddField( + model_name='userpreference', + name='search_style', + field=models.CharField(choices=[('SMALL', 'Small'), ('LARGE', 'Large')], default='LARGE', max_length=64), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 1e0f400a..ce25d1e7 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -48,11 +48,18 @@ class UserPreference(models.Model): PAGES = ((SEARCH, _('Search')), (PLAN, _('Meal-Plan')), (BOOKS, _('Books')), ) + # Search Style + SMALL = 'SMALL' + LARGE = 'LARGE' + + SEARCH_STYLE = ((SMALL, _('Small')), (LARGE, _('Large')),) + user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True) theme = models.CharField(choices=THEMES, max_length=128, default=FLATLY) nav_color = models.CharField(choices=COLORS, max_length=128, default=PRIMARY) default_unit = models.CharField(max_length=32, default='g') default_page = models.CharField(choices=PAGES, max_length=64, default=SEARCH) + search_style = models.CharField(choices=SEARCH_STYLE, max_length=64, default=LARGE) def __str__(self): return self.user diff --git a/cookbook/tables.py b/cookbook/tables.py index a23d3be2..a0466c9a 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -13,6 +13,18 @@ class ImageUrlColumn(tables.Column): return None +class RecipeTableSmall(tables.Table): + id = tables.LinkColumn('edit_recipe', args=[A('id')]) + name = tables.LinkColumn('view_recipe', args=[A('id')]) + all_tags = tables.Column( + attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}}) + + class Meta: + model = Recipe + template_name = 'generic/table_template.html' + fields = ('id', 'name', 'all_tags') + + class RecipeTable(tables.Table): edit = tables.TemplateColumn("" + _('Edit') + "") name = tables.LinkColumn('view_recipe', args=[A('id')]) diff --git a/cookbook/templates/recipes_table.html b/cookbook/templates/recipes_table.html index 61838540..2822861a 100644 --- a/cookbook/templates/recipes_table.html +++ b/cookbook/templates/recipes_table.html @@ -11,11 +11,9 @@ {% block table %} {% for row in table.paginated_rows %} -
+
- - {% if row.cells.image|length > 1 %} {% trans 'Recipe Image' %} diff --git a/cookbook/views/views.py b/cookbook/views/views.py index d953f84d..1c7fb2b8 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -13,7 +13,7 @@ from django.utils.translation import gettext as _ from cookbook.filters import RecipeFilter from cookbook.forms import * from cookbook.helper.permission_helper import group_required -from cookbook.tables import RecipeTable +from cookbook.tables import RecipeTable, RecipeTableSmall def index(request): @@ -35,7 +35,10 @@ def search(request): if request.user.is_authenticated: f = RecipeFilter(request.GET, queryset=Recipe.objects.all().order_by('name')) - table = RecipeTable(f.qs) + if request.user.userpreference.search_style == UserPreference.LARGE: + table = RecipeTable(f.qs) + else: + table = RecipeTableSmall(f.qs) RequestConfig(request, paginate={'per_page': 25}).configure(table) return render(request, 'index.html', {'recipes': table, 'filter': f}) @@ -193,6 +196,7 @@ def settings(request): up.nav_color = form.cleaned_data['nav_color'] up.default_unit = form.cleaned_data['default_unit'] up.default_page = form.cleaned_data['default_page'] + up.search_style = form.cleaned_data['search_style'] up.save() if 'user_name_form' in request.POST: