forms
This commit is contained in:
parent
7ab6276397
commit
b71e9fe57d
@ -3,7 +3,9 @@ from django.forms import widgets
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from emoji_picker.widgets import EmojiPickerTextInput
|
from emoji_picker.widgets import EmojiPickerTextInput
|
||||||
|
|
||||||
from .models import *
|
from .models import (Comment, Food, InviteLink, Keyword, MealPlan, Recipe,
|
||||||
|
RecipeBook, RecipeBookEntry, Storage, Sync, Unit, User,
|
||||||
|
UserPreference)
|
||||||
|
|
||||||
|
|
||||||
class SelectWidget(widgets.Select):
|
class SelectWidget(widgets.Select):
|
||||||
@ -16,7 +18,8 @@ class MultiSelectWidget(widgets.SelectMultiple):
|
|||||||
js = ('custom/js/form_multiselect.js',)
|
js = ('custom/js/form_multiselect.js',)
|
||||||
|
|
||||||
|
|
||||||
# yes there are some stupid browsers that still dont support this but i dont support people using these browsers
|
# Yes there are some stupid browsers that still dont support this but
|
||||||
|
# I dont support people using these browsers.
|
||||||
class DateWidget(forms.DateInput):
|
class DateWidget(forms.DateInput):
|
||||||
input_type = 'date'
|
input_type = 'date'
|
||||||
|
|
||||||
@ -30,20 +33,26 @@ class UserPreferenceForm(forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserPreference
|
model = UserPreference
|
||||||
fields = ('default_unit', 'use_fractions', 'theme', 'nav_color', 'sticky_navbar', 'default_page', 'show_recent', 'search_style', 'plan_share', 'ingredient_decimals', 'shopping_auto_sync', 'comments')
|
fields = (
|
||||||
|
'default_unit', 'use_fractions', 'theme', 'nav_color',
|
||||||
|
'sticky_navbar', 'default_page', 'show_recent', 'search_style',
|
||||||
|
'plan_share', 'ingredient_decimals', 'shopping_auto_sync',
|
||||||
|
'comments'
|
||||||
|
)
|
||||||
|
|
||||||
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!'), # noqa: E501
|
||||||
'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'),
|
'default_unit': _('Default Unit to be used when inserting a new ingredient into a recipe.'), # noqa: E501
|
||||||
'use_fractions': _('Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'),
|
'use_fractions': _('Enables support for fractions in ingredient amounts (e.g. convert decimals to fractions automatically)'), # noqa: E501
|
||||||
'plan_share': _('Users with whom newly created meal plan/shopping list entries should be shared by default.'),
|
'plan_share': _('Users with whom newly created meal plan/shopping list entries should be shared by default.'), # noqa: E501
|
||||||
'show_recent': _('Show recently viewed recipes on search page.'),
|
'show_recent': _('Show recently viewed recipes on search page.'), # noqa: E501
|
||||||
'ingredient_decimals': _('Number of decimals to round ingredients.'),
|
'ingredient_decimals': _('Number of decimals to round ingredients.'), # noqa: E501
|
||||||
'comments': _('If you want to be able to create and see comments underneath recipes.'),
|
'comments': _('If you want to be able to create and see comments underneath recipes.'), # noqa: E501
|
||||||
'shopping_auto_sync': _(
|
'shopping_auto_sync': _(
|
||||||
'Setting to 0 will disable auto sync. When viewing a shopping list the list is updated every set seconds to sync changes someone else might have made. Useful when shopping with multiple people but might use a little bit '
|
'Setting to 0 will disable auto sync. When viewing a shopping list the list is updated every set seconds to sync changes someone else might have made. Useful when shopping with multiple people but might use a little bit ' # noqa: E501
|
||||||
'of mobile data. If lower than instance limit it is reset when saving.'),
|
'of mobile data. If lower than instance limit it is reset when saving.' # noqa: E501
|
||||||
'sticky_navbar': _('Makes the navbar stick to the top of the page.')
|
),
|
||||||
|
'sticky_navbar': _('Makes the navbar stick to the top of the page.') # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets = {
|
widgets = {
|
||||||
@ -59,18 +68,25 @@ class UserNameForm(forms.ModelForm):
|
|||||||
fields = ('first_name', 'last_name')
|
fields = ('first_name', 'last_name')
|
||||||
|
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'first_name': _('Both fields are optional. If none are given the username will be displayed instead')
|
'first_name': _('Both fields are optional. If none are given the username will be displayed instead') # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ExternalRecipeForm(forms.ModelForm):
|
class ExternalRecipeForm(forms.ModelForm):
|
||||||
file_path = forms.CharField(disabled=True, required=False)
|
file_path = forms.CharField(disabled=True, required=False)
|
||||||
storage = forms.ModelChoiceField(queryset=Storage.objects.all(), disabled=True, required=False)
|
storage = forms.ModelChoiceField(
|
||||||
|
queryset=Storage.objects.all(),
|
||||||
|
disabled=True,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
file_uid = forms.CharField(disabled=True, required=False)
|
file_uid = forms.CharField(disabled=True, required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
fields = ('name', 'keywords', 'working_time', 'waiting_time', 'file_path', 'storage', 'file_uid')
|
fields = (
|
||||||
|
'name', 'keywords', 'working_time', 'waiting_time',
|
||||||
|
'file_path', 'storage', 'file_uid'
|
||||||
|
)
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'name': _('Name'),
|
'name': _('Name'),
|
||||||
@ -88,7 +104,10 @@ class InternalRecipeForm(forms.ModelForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
fields = ('name', 'image', 'working_time', 'waiting_time', 'servings', 'keywords')
|
fields = (
|
||||||
|
'name', 'image', 'working_time',
|
||||||
|
'waiting_time', 'servings', 'keywords'
|
||||||
|
)
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'name': _('Name'),
|
'name': _('Name'),
|
||||||
@ -106,7 +125,7 @@ class ShoppingForm(forms.Form):
|
|||||||
widget=MultiSelectWidget
|
widget=MultiSelectWidget
|
||||||
)
|
)
|
||||||
markdown_format = forms.BooleanField(
|
markdown_format = forms.BooleanField(
|
||||||
help_text=_('Include <code>- [ ]</code> in list for easier usage in markdown based documents.'),
|
help_text=_('Include <code>- [ ]</code> in list for easier usage in markdown based documents.'), # noqa: E501
|
||||||
required=False,
|
required=False,
|
||||||
initial=False
|
initial=False
|
||||||
)
|
)
|
||||||
@ -128,7 +147,10 @@ class ExportForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class ImportForm(forms.Form):
|
class ImportForm(forms.Form):
|
||||||
recipe = forms.CharField(widget=forms.Textarea, help_text=_('Simply paste a JSON export into this textarea and click import.'))
|
recipe = forms.CharField(
|
||||||
|
widget=forms.Textarea,
|
||||||
|
help_text=_('Simply paste a JSON export into this textarea and click import.') # noqa: E501
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UnitMergeForm(forms.Form):
|
class UnitMergeForm(forms.Form):
|
||||||
@ -195,21 +217,31 @@ class FoodForm(forms.ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class StorageForm(forms.ModelForm):
|
class StorageForm(forms.ModelForm):
|
||||||
username = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password'}), required=False)
|
username = forms.CharField(
|
||||||
password = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}),
|
widget=forms.TextInput(attrs={'autocomplete': 'new-password'}),
|
||||||
required=False,
|
required=False
|
||||||
help_text=_('Leave empty for dropbox and enter app password for nextcloud.'))
|
)
|
||||||
token = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}),
|
password = forms.CharField(
|
||||||
required=False,
|
widget=forms.TextInput(
|
||||||
help_text=_('Leave empty for nextcloud and enter api token for dropbox.'))
|
attrs={'autocomplete': 'new-password', 'type': 'password'}
|
||||||
|
),
|
||||||
|
required=False,
|
||||||
|
help_text=_('Leave empty for dropbox and enter app password for nextcloud.') # noqa: E501
|
||||||
|
)
|
||||||
|
token = forms.CharField(
|
||||||
|
widget=forms.TextInput(
|
||||||
|
attrs={'autocomplete': 'new-password', 'type': 'password'}
|
||||||
|
),
|
||||||
|
required=False,
|
||||||
|
help_text=_('Leave empty for nextcloud and enter api token for dropbox.') # noqa: E501
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Storage
|
model = Storage
|
||||||
fields = ('name', 'method', 'username', 'password', 'token', 'url')
|
fields = ('name', 'method', 'username', 'password', 'token', 'url')
|
||||||
|
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'url': _(
|
'url': _('Leave empty for dropbox and enter only base url for nextcloud (<code>/remote.php/webdav/</code> is added automatically)'), # noqa: E501
|
||||||
'Leave empty for dropbox and enter only base url for nextcloud (<code>/remote.php/webdav/</code> is added automatically)'),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -229,8 +261,11 @@ class SyncForm(forms.ModelForm):
|
|||||||
|
|
||||||
class BatchEditForm(forms.Form):
|
class BatchEditForm(forms.Form):
|
||||||
search = forms.CharField(label=_('Search String'))
|
search = forms.CharField(label=_('Search String'))
|
||||||
keywords = forms.ModelMultipleChoiceField(queryset=Keyword.objects.all().order_by('id'), required=False,
|
keywords = forms.ModelMultipleChoiceField(
|
||||||
widget=MultiSelectWidget)
|
queryset=Keyword.objects.all().order_by('id'),
|
||||||
|
required=False,
|
||||||
|
widget=MultiSelectWidget
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ImportRecipeForm(forms.ModelForm):
|
class ImportRecipeForm(forms.ModelForm):
|
||||||
@ -260,20 +295,29 @@ class MealPlanForm(forms.ModelForm):
|
|||||||
cleaned_data = super(MealPlanForm, self).clean()
|
cleaned_data = super(MealPlanForm, self).clean()
|
||||||
|
|
||||||
if cleaned_data['title'] == '' and cleaned_data['recipe'] is None:
|
if cleaned_data['title'] == '' and cleaned_data['recipe'] is None:
|
||||||
raise forms.ValidationError(_('You must provide at least a recipe or a title.'))
|
raise forms.ValidationError(
|
||||||
|
_('You must provide at least a recipe or a title.')
|
||||||
|
)
|
||||||
|
|
||||||
return cleaned_data
|
return cleaned_data
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MealPlan
|
model = MealPlan
|
||||||
fields = ('recipe', 'title', 'meal_type', 'note', 'servings', 'date', 'shared')
|
fields = (
|
||||||
|
'recipe', 'title', 'meal_type', 'note',
|
||||||
|
'servings', 'date', 'shared'
|
||||||
|
)
|
||||||
|
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'shared': _('You can list default users to share recipes with in the settings.'),
|
'shared': _('You can list default users to share recipes with in the settings.'), # noqa: E501
|
||||||
'note': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>')
|
'note': _('You can use markdown to format this field. See the <a href="/docs/markdown/">docs here</a>') # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets = {'recipe': SelectWidget, 'date': DateWidget, 'shared': MultiSelectWidget}
|
widgets = {
|
||||||
|
'recipe': SelectWidget,
|
||||||
|
'date': DateWidget,
|
||||||
|
'shared': MultiSelectWidget
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class InviteLinkForm(forms.ModelForm):
|
class InviteLinkForm(forms.ModelForm):
|
||||||
@ -281,11 +325,19 @@ class InviteLinkForm(forms.ModelForm):
|
|||||||
model = InviteLink
|
model = InviteLink
|
||||||
fields = ('username', 'group', 'valid_until')
|
fields = ('username', 'group', 'valid_until')
|
||||||
help_texts = {
|
help_texts = {
|
||||||
'username': _('A username is not required, if left blank the new user can choose one.')
|
'username': _('A username is not required, if left blank the new user can choose one.') # noqa: E501
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class UserCreateForm(forms.Form):
|
class UserCreateForm(forms.Form):
|
||||||
name = forms.CharField(label='Username')
|
name = forms.CharField(label='Username')
|
||||||
password = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}))
|
password = forms.CharField(
|
||||||
password_confirm = forms.CharField(widget=forms.TextInput(attrs={'autocomplete': 'new-password', 'type': 'password'}))
|
widget=forms.TextInput(
|
||||||
|
attrs={'autocomplete': 'new-password', 'type': 'password'}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
password_confirm = forms.CharField(
|
||||||
|
widget=forms.TextInput(
|
||||||
|
attrs={'autocomplete': 'new-password', 'type': 'password'}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user