from django import forms from django.contrib.auth.forms import UserCreationForm from django.core.exceptions import FieldDoesNotExist from django.forms import ModelForm from mixins.restrictions import RestrictedFormMixin from .models import Aggregator, NotificationSettings, User # flake8: noqa: E501 class NewUserForm(UserCreationForm): email = forms.EmailField(required=True) class Meta: model = User fields = ( "username", "email", "first_name", "last_name", "password1", "password2", ) def save(self, commit=True): user = super(NewUserForm, self).save(commit=False) user.email = self.cleaned_data["email"] if commit: user.save() return user class CustomUserCreationForm(UserCreationForm): class Meta: model = User fields = "__all__" class NotificationSettingsForm(RestrictedFormMixin, ModelForm): class Meta: model = NotificationSettings fields = ( "ntfy_topic", "ntfy_url", ) help_texts = { "ntfy_topic": "The topic to send notifications to.", "ntfy_url": "Custom NTFY server. Leave blank to use the default server.", } class AggregatorForm(RestrictedFormMixin, ModelForm): def __init__(self, *args, **kwargs): super(AggregatorForm, self).__init__(*args, **kwargs) self.fields["secret_id"].label = "Secret ID" class Meta: model = Aggregator fields = ( "name", "service", "secret_id", "secret_key", "poll_interval", "enabled", ) help_texts = { "name": "The name of the aggregator connection.", "service": "The aggregator service to use.", "secret_id": "The secret ID for the aggregator service.", "secret_key": "The secret key for the aggregator service.", "poll_interval": "The interval in seconds to poll the aggregator service.", "enabled": "Whether or not the aggregator connection is enabled.", }