mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-24 02:39:20 -05:00
nav color theming
This commit is contained in:
@@ -29,7 +29,11 @@ class DateWidget(forms.DateInput):
|
||||
class UserPreferenceForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = UserPreference
|
||||
fields = ('theme',)
|
||||
fields = ('theme', 'nav_color')
|
||||
|
||||
help_texts = {
|
||||
'nav_color': _('Color of the top navigation bar. Not all colors work with all themes, just try them out!')
|
||||
}
|
||||
|
||||
|
||||
class ExternalRecipeForm(forms.ModelForm):
|
||||
|
||||
18
cookbook/migrations/0025_userpreference_nav_color.py
Normal file
18
cookbook/migrations/0025_userpreference_nav_color.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.2 on 2020-02-16 23:05
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0024_auto_20200216_2313'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='userpreference',
|
||||
name='nav_color',
|
||||
field=models.CharField(choices=[('PRIMARY', 'Primary'), ('SECONDARY', 'Secondary'), ('SUCCESS', 'Success'), ('INFO', 'Info'), ('WARNING', 'Warning'), ('DANGER', 'Danger'), ('LIGHT', 'Light'), ('DARK', 'Dark')], default='PRIMARY', max_length=128),
|
||||
),
|
||||
]
|
||||
@@ -4,6 +4,7 @@ from django.db import models
|
||||
|
||||
|
||||
class UserPreference(models.Model):
|
||||
# Themes
|
||||
BOOTSTRAP = 'BOOTSTRAP'
|
||||
DARKLY = 'DARKLY'
|
||||
FLATLY = 'FLATLY'
|
||||
@@ -11,8 +12,21 @@ class UserPreference(models.Model):
|
||||
|
||||
THEMES = ((BOOTSTRAP, 'Bootstrap'), (DARKLY, 'Darkly'), (FLATLY, 'Flatly'), (SUPERHERO, 'Superhero'))
|
||||
|
||||
# Nav colors
|
||||
PRIMARY = 'PRIMARY'
|
||||
SECONDARY = 'SECONDARY'
|
||||
SUCCESS = 'SUCCESS'
|
||||
INFO = 'INFO'
|
||||
WARNING = 'WARNING'
|
||||
DANGER = 'DANGER'
|
||||
LIGHT = 'LIGHT'
|
||||
DARK = 'DARK'
|
||||
|
||||
COLORS = ((PRIMARY, 'Primary'), (SECONDARY, 'Secondary'), (SUCCESS, 'Success'), (INFO, 'Info'), (WARNING, 'Warning'), (DANGER, 'Danger'), (LIGHT, 'Light'), (DARK, 'Dark'))
|
||||
|
||||
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)
|
||||
|
||||
|
||||
class Storage(models.Model):
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-primary" id="id_main_nav">
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-{% nav_color request %}" id="id_main_nav">
|
||||
<!--<a class="navbar-brand" href="{% url 'index' %}">{% trans 'Cookbook' %}</a>-->
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
|
||||
aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
{% endfor %}
|
||||
</select>
|
||||
<br/>
|
||||
<input type="submit" value="{% trans 'Save' %}" class="btn btn-success">
|
||||
<button class="btn btn-success" type="submit"><i class="fas fa-save"></i> {% trans 'Save' %}</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -23,6 +23,14 @@ def theme_url(request):
|
||||
return static('themes/flatly.min.css')
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def nav_color(request):
|
||||
try:
|
||||
return request.user.userpreference.nav_color
|
||||
except AttributeError:
|
||||
return 'primary'
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def tabulator_theme_url(request):
|
||||
try:
|
||||
|
||||
@@ -156,6 +156,7 @@ def settings(request):
|
||||
if not up:
|
||||
up = UserPreference(user=request.user)
|
||||
up.theme = form.cleaned_data['theme']
|
||||
up.nav_color = form.cleaned_data['nav_color']
|
||||
up.save()
|
||||
|
||||
if up:
|
||||
|
||||
Reference in New Issue
Block a user