diff --git a/cookbook/forms.py b/cookbook/forms.py index 60c9691b1..55aa1a0ad 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -39,7 +39,7 @@ class UserPreferenceForm(forms.ModelForm): class Meta: model = UserPreference 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', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'comments' @@ -52,6 +52,7 @@ class UserPreferenceForm(forms.ModelForm): 'use_fractions': _( 'Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'), # noqa: E501 + 'use_kj': _('Display nutritional energy amounts in joules instead of calories'), # noqa: E501 'plan_share': _( 'Users with whom newly created meal plan/shopping list entries should be shared by default.'), # noqa: E501 diff --git a/cookbook/migrations/0158_userpreference_use_kj.py b/cookbook/migrations/0158_userpreference_use_kj.py new file mode 100644 index 000000000..bd2a27d79 --- /dev/null +++ b/cookbook/migrations/0158_userpreference_use_kj.py @@ -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), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 228c45be3..1e682f3a1 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -19,7 +19,8 @@ from treebeard.mp_tree import MP_Node, MP_NodeManager from django_scopes import ScopedManager, scopes_disabled from django_prometheus.models import ExportModelOperationsMixin 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): @@ -217,6 +218,7 @@ class UserPreference(models.Model, PermissionModelMixin): ) default_unit = models.CharField(max_length=32, default='g') use_fractions = models.BooleanField(default=FRACTION_PREF_DEFAULT) + use_kj = models.BooleanField(default=KJ_PREF_DEFAULT) default_page = models.CharField( choices=PAGES, max_length=64, default=SEARCH ) diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 0ccd54612..5a94412b9 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -307,6 +307,7 @@ def user_settings(request): up.ingredient_decimals = form.cleaned_data['ingredient_decimals'] # noqa: E501 up.comments = form.cleaned_data['comments'] 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.shopping_auto_sync = form.cleaned_data['shopping_auto_sync'] diff --git a/recipes/settings.py b/recipes/settings.py index ebccbfa5e..5460d4818 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -44,6 +44,7 @@ REVERSE_PROXY_AUTH = bool(int(os.getenv('REVERSE_PROXY_AUTH', False))) # default value for user preference 'comment' COMMENT_PREF_DEFAULT = bool(int(os.getenv('COMMENT_PREF_DEFAULT', True))) 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))) # minimum interval that users can set for automatic sync of shopping lists