48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
from django import forms
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
from django.utils.safestring import mark_safe
|
|
from django.utils.translation import gettext_lazy as _
|
|
from friendly_captcha.fields import FrcCaptchaField
|
|
|
|
from .models import Offer, PflaenzliUser, Wish
|
|
|
|
|
|
class CreateOfferForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Offer
|
|
fields = ['title', 'description', 'zipcode', 'image']
|
|
|
|
|
|
class RegistrationForm(UserCreationForm):
|
|
class Meta(UserCreationForm.Meta):
|
|
model = PflaenzliUser
|
|
fields = UserCreationForm.Meta.fields + ('email', 'zipcode',)
|
|
|
|
captcha = FrcCaptchaField()
|
|
|
|
|
|
class FilterForm(forms.Form):
|
|
text = forms.CharField(max_length=128, required=False)
|
|
zipcode = forms.CharField(max_length=4, required=False)
|
|
distance = forms.IntegerField(required=False)
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
# Set the translated labels by session language with icons for each form field
|
|
self.fields['text'].label = mark_safe(
|
|
f'<i class="fa-solid fa-magnifying-glass"></i> {_("Search")}'
|
|
)
|
|
self.fields['zipcode'].label = mark_safe(
|
|
f'<i class="fa-solid fa-location-dot"></i> {_("ZIP code")}'
|
|
)
|
|
self.fields['distance'].label = mark_safe(
|
|
f'<i class="fa-solid fa-signs-post"></i> {_("Distance")} (km)'
|
|
)
|
|
|
|
|
|
class WishForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Wish
|
|
fields = ['title']
|