2024-05-10 11:54:16 +00:00
|
|
|
import datetime
|
|
|
|
|
2024-03-20 08:19:58 +00:00
|
|
|
from django import forms
|
2024-05-30 07:57:20 +00:00
|
|
|
|
2024-05-30 13:46:51 +00:00
|
|
|
from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportComment, ModerationAction, User, Species, \
|
|
|
|
Comment
|
2024-04-07 09:33:41 +00:00
|
|
|
from django_registration.forms import RegistrationForm
|
2024-04-20 06:06:20 +00:00
|
|
|
from crispy_forms.helper import FormHelper
|
2024-05-10 11:54:16 +00:00
|
|
|
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field
|
2024-04-20 06:06:20 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-05-10 11:54:16 +00:00
|
|
|
from notfellchen.settings import MEDIA_URL
|
|
|
|
|
2024-03-20 08:19:58 +00:00
|
|
|
|
|
|
|
class DateInput(forms.DateInput):
|
|
|
|
input_type = 'date'
|
|
|
|
|
|
|
|
|
|
|
|
class AdoptionNoticeForm(forms.ModelForm):
|
2024-04-20 06:06:20 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2024-05-31 07:58:55 +00:00
|
|
|
if 'in_adoption_notice_creation_flow' in kwargs:
|
|
|
|
in_flow = kwargs.pop('in_adoption_notice_creation_flow')
|
|
|
|
else:
|
|
|
|
in_flow = False
|
2024-04-20 06:06:20 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
2024-04-20 06:40:04 +00:00
|
|
|
|
|
|
|
self.helper.form_id = 'form-adoption-notice'
|
2024-04-20 06:06:20 +00:00
|
|
|
self.helper.form_class = 'card'
|
|
|
|
self.helper.form_method = 'post'
|
|
|
|
|
2024-05-31 07:58:55 +00:00
|
|
|
if in_flow:
|
|
|
|
submit = Submit('save-and-add-another-animal', _('Speichern und Tiere hinzufügen'))
|
|
|
|
|
|
|
|
else:
|
|
|
|
submit = Submit('submit', _('Submit'))
|
|
|
|
|
2024-04-20 06:40:16 +00:00
|
|
|
self.helper.layout = Layout(
|
|
|
|
Fieldset(
|
|
|
|
_('Vermittlungsdetails'),
|
|
|
|
'name',
|
|
|
|
'group_only',
|
|
|
|
'searching_since',
|
2024-05-31 08:58:57 +00:00
|
|
|
'location_string',
|
2024-04-20 06:40:16 +00:00
|
|
|
'description',
|
|
|
|
'further_information',
|
|
|
|
),
|
2024-05-31 07:58:55 +00:00
|
|
|
submit)
|
2024-04-20 06:06:20 +00:00
|
|
|
|
2024-03-20 08:19:58 +00:00
|
|
|
class Meta:
|
|
|
|
model = AdoptionNotice
|
2024-05-31 08:58:57 +00:00
|
|
|
fields = ['name', "group_only", "further_information", "description", "searching_since", "location_string"]
|
2024-05-30 08:48:57 +00:00
|
|
|
|
2024-03-20 08:19:58 +00:00
|
|
|
|
2024-05-30 13:49:32 +00:00
|
|
|
class AnimalForm(forms.ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2024-05-31 07:58:55 +00:00
|
|
|
if 'in_adoption_notice_creation_flow' in kwargs:
|
|
|
|
adding = kwargs.pop('in_adoption_notice_creation_flow')
|
2024-05-30 14:57:47 +00:00
|
|
|
else:
|
|
|
|
adding = False
|
2024-05-30 13:49:32 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_class = 'form-animal'
|
2024-05-30 14:57:47 +00:00
|
|
|
if adding:
|
|
|
|
self.helper.add_input(Submit('save-and-add-another-animal', _('Speichern und weiteres Tier hinzufügen')))
|
|
|
|
self.helper.add_input(Submit('save-and-finish', _('Speichern und beenden')))
|
|
|
|
else:
|
|
|
|
self.helper.add_input(Submit('submit', _('Speichern')))
|
|
|
|
|
2024-05-30 13:49:32 +00:00
|
|
|
class Meta:
|
|
|
|
model = Animal
|
|
|
|
fields = ["name", "date_of_birth", "species", "sex", "description"]
|
|
|
|
|
|
|
|
|
2024-03-20 12:40:00 +00:00
|
|
|
class ImageForm(forms.ModelForm):
|
2024-05-10 11:54:16 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2024-05-31 08:56:43 +00:00
|
|
|
if 'in_flow' in kwargs:
|
|
|
|
in_flow = kwargs.pop('in_flow')
|
|
|
|
else:
|
|
|
|
in_flow = False
|
2024-05-10 11:54:16 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_id = 'form-animal-photo'
|
|
|
|
self.helper.form_class = 'card'
|
|
|
|
self.helper.form_method = 'post'
|
2024-05-31 08:56:43 +00:00
|
|
|
if in_flow:
|
|
|
|
self.helper.add_input(Submit('save-and-add-another', _('Speichern und weiteres Foto hinzufügen')))
|
|
|
|
self.helper.add_input(Submit('submit', _('Speichern')))
|
|
|
|
else:
|
|
|
|
self.helper.add_input(Submit('submit', _('Submit')))
|
2024-05-10 11:54:16 +00:00
|
|
|
|
2024-03-20 12:40:00 +00:00
|
|
|
class Meta:
|
|
|
|
model = Image
|
2024-05-31 11:51:14 +00:00
|
|
|
fields = ('image', 'alt_text')
|
2024-03-22 11:45:50 +00:00
|
|
|
|
|
|
|
|
2024-05-30 13:46:51 +00:00
|
|
|
class ReportAdoptionNoticeForm(forms.ModelForm):
|
2024-03-22 11:45:50 +00:00
|
|
|
class Meta:
|
2024-05-30 13:46:51 +00:00
|
|
|
model = ReportAdoptionNotice
|
|
|
|
fields = ('reported_broken_rules', 'user_comment')
|
|
|
|
|
|
|
|
|
|
|
|
class ReportCommentForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = ReportComment
|
|
|
|
fields = ('reported_broken_rules', 'user_comment')
|
2024-03-22 11:45:50 +00:00
|
|
|
|
2024-05-30 12:39:28 +00:00
|
|
|
|
2024-05-30 12:37:15 +00:00
|
|
|
class CommentForm(forms.ModelForm):
|
2024-05-30 12:39:28 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.helper = FormHelper()
|
|
|
|
self.helper.form_class = 'form-comments'
|
|
|
|
self.helper.add_input(Submit('submit', _('Kommentieren')))
|
|
|
|
|
2024-05-30 12:37:15 +00:00
|
|
|
class Meta:
|
|
|
|
model = Comment
|
|
|
|
fields = ('text',)
|
2024-03-22 11:45:50 +00:00
|
|
|
|
2024-05-30 12:39:28 +00:00
|
|
|
|
2024-03-22 11:45:50 +00:00
|
|
|
class ModerationActionForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = ModerationAction
|
|
|
|
fields = ('action', 'public_comment', 'private_comment')
|
2024-04-07 09:33:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CustomRegistrationForm(RegistrationForm):
|
2024-04-07 09:41:37 +00:00
|
|
|
class Meta(RegistrationForm.Meta):
|
|
|
|
model = User
|
2024-05-31 11:48:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _get_distances():
|
|
|
|
return {i: i for i in [10, 20, 50, 100, 200, 500]}
|
|
|
|
|
|
|
|
|
|
|
|
class AdoptionNoticeSearchForm(forms.Form):
|
|
|
|
postcode = forms.CharField(max_length=20, label=_("Postleitzahl"))
|
|
|
|
max_distance = forms.ChoiceField(choices=_get_distances, label=_("Max. Distanz"))
|