Add KJ user preference

This commit is contained in:
xeals
2021-10-25 17:25:35 +11:00
parent e33daf7b3e
commit b1b770c9e5
5 changed files with 25 additions and 2 deletions

View File

@ -39,7 +39,7 @@ class UserPreferenceForm(forms.ModelForm):
class Meta: class Meta:
model = UserPreference model = UserPreference
fields = ( fields = (
'default_unit', 'use_fractions', 'theme', 'nav_color', 'default_unit', 'use_fractions', 'use_kj', 'theme', 'nav_color',
'sticky_navbar', 'default_page', 'show_recent', 'search_style', 'sticky_navbar', 'default_page', 'show_recent', 'search_style',
'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync',
'comments' 'comments'
@ -52,6 +52,7 @@ class UserPreferenceForm(forms.ModelForm):
'use_fractions': _( 'use_fractions': _(
'Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'), 'Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'),
# noqa: E501 # noqa: E501
'use_kj': _('Display nutritional energy amounts in joules instead of calories'), # noqa: E501
'plan_share': _( 'plan_share': _(
'Users with whom newly created meal plan/shopping list entries should be shared by default.'), 'Users with whom newly created meal plan/shopping list entries should be shared by default.'),
# noqa: E501 # noqa: E501

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2.7 on 2021-10-25 05:21
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cookbook', '0157_alter_searchpreference_trigram'),
]
operations = [
migrations.AddField(
model_name='userpreference',
name='use_kj',
field=models.BooleanField(default=False),
),
]

View File

@ -19,7 +19,8 @@ from treebeard.mp_tree import MP_Node, MP_NodeManager
from django_scopes import ScopedManager, scopes_disabled from django_scopes import ScopedManager, scopes_disabled
from django_prometheus.models import ExportModelOperationsMixin from django_prometheus.models import ExportModelOperationsMixin
from recipes.settings import (COMMENT_PREF_DEFAULT, FRACTION_PREF_DEFAULT, from recipes.settings import (COMMENT_PREF_DEFAULT, FRACTION_PREF_DEFAULT,
STICKY_NAV_PREF_DEFAULT, SORT_TREE_BY_NAME) KJ_PREF_DEFAULT, STICKY_NAV_PREF_DEFAULT,
SORT_TREE_BY_NAME)
def get_user_name(self): def get_user_name(self):
@ -217,6 +218,7 @@ class UserPreference(models.Model, PermissionModelMixin):
) )
default_unit = models.CharField(max_length=32, default='g') default_unit = models.CharField(max_length=32, default='g')
use_fractions = models.BooleanField(default=FRACTION_PREF_DEFAULT) use_fractions = models.BooleanField(default=FRACTION_PREF_DEFAULT)
use_kj = models.BooleanField(default=KJ_PREF_DEFAULT)
default_page = models.CharField( default_page = models.CharField(
choices=PAGES, max_length=64, default=SEARCH choices=PAGES, max_length=64, default=SEARCH
) )

View File

@ -307,6 +307,7 @@ def user_settings(request):
up.ingredient_decimals = form.cleaned_data['ingredient_decimals'] # noqa: E501 up.ingredient_decimals = form.cleaned_data['ingredient_decimals'] # noqa: E501
up.comments = form.cleaned_data['comments'] up.comments = form.cleaned_data['comments']
up.use_fractions = form.cleaned_data['use_fractions'] up.use_fractions = form.cleaned_data['use_fractions']
up.use_kj = form.cleaned_data['use_kj']
up.sticky_navbar = form.cleaned_data['sticky_navbar'] up.sticky_navbar = form.cleaned_data['sticky_navbar']
up.shopping_auto_sync = form.cleaned_data['shopping_auto_sync'] up.shopping_auto_sync = form.cleaned_data['shopping_auto_sync']

View File

@ -44,6 +44,7 @@ REVERSE_PROXY_AUTH = bool(int(os.getenv('REVERSE_PROXY_AUTH', False)))
# default value for user preference 'comment' # default value for user preference 'comment'
COMMENT_PREF_DEFAULT = bool(int(os.getenv('COMMENT_PREF_DEFAULT', True))) COMMENT_PREF_DEFAULT = bool(int(os.getenv('COMMENT_PREF_DEFAULT', True)))
FRACTION_PREF_DEFAULT = bool(int(os.getenv('FRACTION_PREF_DEFAULT', False))) FRACTION_PREF_DEFAULT = bool(int(os.getenv('FRACTION_PREF_DEFAULT', False)))
KJ_PREF_DEFAULT = bool(int(os.getenv('KJ_PREF_DEFAULT', False)))
STICKY_NAV_PREF_DEFAULT = bool(int(os.getenv('STICKY_NAV_PREF_DEFAULT', True))) STICKY_NAV_PREF_DEFAULT = bool(int(os.getenv('STICKY_NAV_PREF_DEFAULT', True)))
# minimum interval that users can set for automatic sync of shopping lists # minimum interval that users can set for automatic sync of shopping lists