refactor: Use integer choice for search
This commit is contained in:
parent
9fffbffdb7
commit
9ea00655d4
@ -1,7 +1,7 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportComment, ModerationAction, User, Species, \
|
from .models import AdoptionNotice, Animal, Image, ReportAdoptionNotice, ReportComment, ModerationAction, User, Species, \
|
||||||
Comment, SexChoicesWithAll
|
Comment, SexChoicesWithAll, DistanceChoices
|
||||||
from django_registration.forms import RegistrationForm
|
from django_registration.forms import RegistrationForm
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field, Hidden
|
from crispy_forms.layout import Submit, Layout, Fieldset, HTML, Row, Column, Field, Hidden
|
||||||
@ -181,12 +181,8 @@ class CustomRegistrationForm(RegistrationForm):
|
|||||||
self.helper.add_input(Submit('submit', _('Registrieren'), css_class="btn"))
|
self.helper.add_input(Submit('submit', _('Registrieren'), css_class="btn"))
|
||||||
|
|
||||||
|
|
||||||
def _get_distances():
|
|
||||||
return {i: i for i in [20, 50, 100, 200, 500]}
|
|
||||||
|
|
||||||
|
|
||||||
class AdoptionNoticeSearchForm(forms.Form):
|
class AdoptionNoticeSearchForm(forms.Form):
|
||||||
location = forms.CharField(max_length=20, label=_("Stadt"), required=False)
|
location = forms.CharField(max_length=20, label=_("Stadt"), required=False)
|
||||||
max_distance = forms.ChoiceField(choices=_get_distances, label=_("Max. Distanz"))
|
max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.ONE_HUNDRED, label=_("Suchradius"))
|
||||||
sex = forms.ChoiceField(choices=SexChoicesWithAll, label=_("Geschlecht"), required=False,
|
sex = forms.ChoiceField(choices=SexChoicesWithAll, label=_("Geschlecht"), required=False,
|
||||||
initial=SexChoicesWithAll.ALL)
|
initial=SexChoicesWithAll.ALL)
|
||||||
|
@ -539,6 +539,13 @@ class Animal(models.Model):
|
|||||||
"""Returns the url to access a detailed page for the animal."""
|
"""Returns the url to access a detailed page for the animal."""
|
||||||
return reverse('animal-detail', args=[str(self.id)])
|
return reverse('animal-detail', args=[str(self.id)])
|
||||||
|
|
||||||
|
class DistanceChoices(models.IntegerChoices):
|
||||||
|
TWENTY = 20, '20 km'
|
||||||
|
FIFTY = 50, '50 km'
|
||||||
|
ONE_HUNDRED = 100, '100 km'
|
||||||
|
TWO_HUNDRED = 200, '200 km'
|
||||||
|
FIVE_HUNDRED = 500, '500 km'
|
||||||
|
|
||||||
|
|
||||||
class Rule(models.Model):
|
class Rule(models.Model):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user