2023-02-19 23:56:05 +01:00
|
|
|
from django import forms
|
2023-04-05 23:29:30 +02:00
|
|
|
from django.contrib.auth.forms import UserCreationForm
|
2023-04-15 13:16:40 +02:00
|
|
|
from django.utils.safestring import mark_safe
|
2023-05-16 23:36:40 +02:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-05-17 15:35:06 +02:00
|
|
|
from friendly_captcha.fields import FrcCaptchaField
|
2023-02-19 23:56:05 +01:00
|
|
|
|
2023-04-16 00:43:56 +02:00
|
|
|
from .models import Offer, PflaenzliUser, Wish
|
2023-02-19 23:56:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
class CreateOfferForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Offer
|
2023-07-07 13:47:56 +02:00
|
|
|
fields = ['title', 'description', 'category', 'zipcode', 'image']
|
2023-04-05 23:29:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
class RegistrationForm(UserCreationForm):
|
|
|
|
class Meta(UserCreationForm.Meta):
|
|
|
|
model = PflaenzliUser
|
2023-04-09 12:38:05 +02:00
|
|
|
fields = UserCreationForm.Meta.fields + ('email', 'zipcode',)
|
2023-04-05 23:29:30 +02:00
|
|
|
|
|
|
|
captcha = FrcCaptchaField()
|
2023-04-15 13:16:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class FilterForm(forms.Form):
|
2023-07-08 17:29:36 +02:00
|
|
|
category = forms.ChoiceField(choices=Offer.FILTER_CATEGORIES, label=_("Category"))
|
2023-05-17 15:47:58 +02:00
|
|
|
text = forms.CharField(max_length=128, required=False, label=_("Search"))
|
|
|
|
zipcode = forms.CharField(max_length=4, required=False, label=_("ZIP code"))
|
|
|
|
distance = forms.IntegerField(required=False, label=_("Distance"))
|
2023-05-17 15:35:33 +02:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
2023-07-08 17:29:36 +02:00
|
|
|
# Overwrite default
|
|
|
|
self.fields['category'].initial = 'ALL'
|
|
|
|
|
2023-05-17 15:47:58 +02:00
|
|
|
# Set the translated labels with the selected language and icons for each form field
|
2023-07-07 13:47:56 +02:00
|
|
|
self.fields['category'].label = mark_safe(
|
|
|
|
f'<i class="fa-solid fa-tag"></i> {self.fields["category"].label}'
|
|
|
|
)
|
|
|
|
|
2023-05-17 15:35:33 +02:00
|
|
|
self.fields['text'].label = mark_safe(
|
2023-05-17 15:47:58 +02:00
|
|
|
f'<i class="fa-solid fa-magnifying-glass"></i> {self.fields["text"].label}'
|
2023-05-17 15:35:33 +02:00
|
|
|
)
|
|
|
|
self.fields['zipcode'].label = mark_safe(
|
2023-05-17 15:47:58 +02:00
|
|
|
f'<i class="fa-solid fa-location-dot"></i> {self.fields["zipcode"].label}'
|
2023-05-17 15:35:33 +02:00
|
|
|
)
|
|
|
|
self.fields['distance'].label = mark_safe(
|
2023-05-17 15:47:58 +02:00
|
|
|
f'<i class="fa-solid fa-signs-post"></i> {self.fields["distance"].label} (km)'
|
2023-05-17 15:35:33 +02:00
|
|
|
)
|
2023-04-16 00:43:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
class WishForm(forms.ModelForm):
|
|
|
|
class Meta:
|
|
|
|
model = Wish
|
|
|
|
fields = ['title']
|