drugs/core/forms.py

98 lines
2.7 KiB
Python

from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.forms import ModelForm
from mixins.restrictions import RestrictedFormMixin
from mxs.restrictions import RestrictedFormMixinStaff
from .models import Drug, Favourite, NotificationSettings, User
# Create your forms here.
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 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 CustomUserCreationForm(UserCreationForm):
class Meta:
model = User
fields = "__all__"
class DrugForm(RestrictedFormMixinStaff, ModelForm):
class Meta:
model = Drug
fields = (
"name",
"drug_class",
"common_name",
"links",
"dosages",
"timings",
"effects",
"actions",
"experiences",
)
help_texts = {
"name": "Lysergic acid diethylamide, Phenibut",
"drug_class": "Psychedelic, Sedative, Stimulant",
"common_name": "LSD",
"links": "Factsheets, posts",
"dosages": "Dosages, how much to take to get a certain effect",
"timings": (
"Timings, how long to wait to reach maximum intensity (and " "others)"
),
"effects": "Effects, what does it do on a subjective level?",
"actions": "Actions, what does it do on an objective level?",
"experiences": "Experiences, what do people experience?",
}
class FavouriteForm(RestrictedFormMixin, ModelForm):
class Meta:
model = Favourite
fields = (
"nickname",
"name",
"drug_class",
"common_name",
)
help_texts = {
"nickname": "Call it whatever you like.",
"name": "Lysergic acid diethylamide, Phenibut",
"drug_class": "Psychedelic, Sedative, Stimulant",
"common_name": "LSD",
}