final style touches + settings
This commit is contained in:
parent
de85a6b334
commit
3a9e5a80ba
@ -30,7 +30,7 @@ class UserPreferenceForm(forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserPreference
|
model = UserPreference
|
||||||
fields = ('default_unit', 'theme', 'nav_color', 'default_page')
|
fields = ('default_unit', 'theme', 'nav_color', 'default_page', 'search_style')
|
||||||
|
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'),
|
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!'),
|
||||||
|
18
cookbook/migrations/0037_userpreference_search_style.py
Normal file
18
cookbook/migrations/0037_userpreference_search_style.py
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
]
|
@ -48,11 +48,18 @@ class UserPreference(models.Model):
|
|||||||
|
|
||||||
PAGES = ((SEARCH, _('Search')), (PLAN, _('Meal-Plan')), (BOOKS, _('Books')), )
|
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)
|
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
|
||||||
theme = models.CharField(choices=THEMES, max_length=128, default=FLATLY)
|
theme = models.CharField(choices=THEMES, max_length=128, default=FLATLY)
|
||||||
nav_color = models.CharField(choices=COLORS, max_length=128, default=PRIMARY)
|
nav_color = models.CharField(choices=COLORS, max_length=128, default=PRIMARY)
|
||||||
default_unit = models.CharField(max_length=32, default='g')
|
default_unit = models.CharField(max_length=32, default='g')
|
||||||
default_page = models.CharField(choices=PAGES, max_length=64, default=SEARCH)
|
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):
|
def __str__(self):
|
||||||
return self.user
|
return self.user
|
||||||
|
@ -13,6 +13,18 @@ class ImageUrlColumn(tables.Column):
|
|||||||
return None
|
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):
|
class RecipeTable(tables.Table):
|
||||||
edit = tables.TemplateColumn("<a href='{% url 'edit_recipe' record.id %}' >" + _('Edit') + "</a>")
|
edit = tables.TemplateColumn("<a href='{% url 'edit_recipe' record.id %}' >" + _('Edit') + "</a>")
|
||||||
name = tables.LinkColumn('view_recipe', args=[A('id')])
|
name = tables.LinkColumn('view_recipe', args=[A('id')])
|
||||||
|
@ -11,11 +11,9 @@
|
|||||||
{% block table %}
|
{% block table %}
|
||||||
<table {% render_attrs table.attrs class="table" %}>
|
<table {% render_attrs table.attrs class="table" %}>
|
||||||
{% for row in table.paginated_rows %}
|
{% for row in table.paginated_rows %}
|
||||||
<div class="card">
|
<div class="card" style="margin-top: 2px">
|
||||||
<div class="row no-gutters">
|
<div class="row no-gutters">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
|
|
||||||
|
|
||||||
{% if row.cells.image|length > 1 %}
|
{% if row.cells.image|length > 1 %}
|
||||||
<img src=" {{ row.cells.image }}" alt="{% trans 'Recipe Image' %}"
|
<img src=" {{ row.cells.image }}" alt="{% trans 'Recipe Image' %}"
|
||||||
class="card-img" style="object-fit: cover; height: 10vh">
|
class="card-img" style="object-fit: cover; height: 10vh">
|
||||||
|
@ -13,7 +13,7 @@ from django.utils.translation import gettext as _
|
|||||||
from cookbook.filters import RecipeFilter
|
from cookbook.filters import RecipeFilter
|
||||||
from cookbook.forms import *
|
from cookbook.forms import *
|
||||||
from cookbook.helper.permission_helper import group_required
|
from cookbook.helper.permission_helper import group_required
|
||||||
from cookbook.tables import RecipeTable
|
from cookbook.tables import RecipeTable, RecipeTableSmall
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
@ -35,7 +35,10 @@ def search(request):
|
|||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
f = RecipeFilter(request.GET, queryset=Recipe.objects.all().order_by('name'))
|
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)
|
RequestConfig(request, paginate={'per_page': 25}).configure(table)
|
||||||
|
|
||||||
return render(request, 'index.html', {'recipes': table, 'filter': f})
|
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.nav_color = form.cleaned_data['nav_color']
|
||||||
up.default_unit = form.cleaned_data['default_unit']
|
up.default_unit = form.cleaned_data['default_unit']
|
||||||
up.default_page = form.cleaned_data['default_page']
|
up.default_page = form.cleaned_data['default_page']
|
||||||
|
up.search_style = form.cleaned_data['search_style']
|
||||||
up.save()
|
up.save()
|
||||||
|
|
||||||
if 'user_name_form' in request.POST:
|
if 'user_name_form' in request.POST:
|
||||||
|
Loading…
Reference in New Issue
Block a user