feat: Add basic bulma form to add adoptions
This commit is contained in:
		@@ -22,6 +22,15 @@ class DateInput(forms.DateInput):
 | 
			
		||||
    input_type = 'date'
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BulmaAdoptionNoticeForm(forms.ModelForm):
 | 
			
		||||
    template_name = "fellchensammlung/forms/form_snippets.html"
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = AdoptionNotice
 | 
			
		||||
        fields = ['name', "group_only", "further_information", "description", "searching_since", "location_string",
 | 
			
		||||
                  "organization"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AdoptionNoticeForm(forms.ModelForm):
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
        if 'in_adoption_notice_creation_flow' in kwargs:
 | 
			
		||||
@@ -127,8 +136,9 @@ class ImageForm(forms.ModelForm):
 | 
			
		||||
        self.helper.form_method = 'post'
 | 
			
		||||
 | 
			
		||||
        if in_flow:
 | 
			
		||||
           submits= Div(Submit('submit', _('Speichern')),
 | 
			
		||||
                      Submit('save-and-add-another', _('Speichern und weiteres Foto hinzufügen')), css_class="container-edit-buttons")
 | 
			
		||||
            submits = Div(Submit('submit', _('Speichern')),
 | 
			
		||||
                          Submit('save-and-add-another', _('Speichern und weiteres Foto hinzufügen')),
 | 
			
		||||
                          css_class="container-edit-buttons")
 | 
			
		||||
        else:
 | 
			
		||||
            submits = Fieldset(Submit('submit', _('Speichern')), css_class="container-edit-buttons")
 | 
			
		||||
        self.helper.layout = Layout(
 | 
			
		||||
@@ -140,7 +150,6 @@ class ImageForm(forms.ModelForm):
 | 
			
		||||
            submits
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = Image
 | 
			
		||||
        fields = ('image', 'alt_text')
 | 
			
		||||
@@ -181,7 +190,8 @@ class CustomRegistrationForm(RegistrationForm):
 | 
			
		||||
    class Meta(RegistrationForm.Meta):
 | 
			
		||||
        model = User
 | 
			
		||||
 | 
			
		||||
    captcha = forms.CharField(validators=[animal_validator], label=_("Nenne eine bekannte Tierart"), help_text=_("Bitte nenne hier eine bekannte Tierart (z.B. ein Tier das an der Leine geführt wird). Das Fragen wir dich um sicherzustellen, dass du kein Roboter bist."))
 | 
			
		||||
    captcha = forms.CharField(validators=[animal_validator], label=_("Nenne eine bekannte Tierart"), help_text=_(
 | 
			
		||||
        "Bitte nenne hier eine bekannte Tierart (z.B. ein Tier das an der Leine geführt wird). Das Fragen wir dich um sicherzustellen, dass du kein Roboter bist."))
 | 
			
		||||
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
@@ -197,5 +207,6 @@ class AdoptionNoticeSearchForm(forms.Form):
 | 
			
		||||
 | 
			
		||||
    sex = forms.ChoiceField(choices=SexChoicesWithAll, label=_("Geschlecht"), required=False,
 | 
			
		||||
                            initial=SexChoicesWithAll.ALL)
 | 
			
		||||
    max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.ONE_HUNDRED, label=_("Suchradius"))
 | 
			
		||||
    max_distance = forms.ChoiceField(choices=DistanceChoices, initial=DistanceChoices.ONE_HUNDRED,
 | 
			
		||||
                                     label=_("Suchradius"))
 | 
			
		||||
    location_string = forms.CharField(max_length=100, label=_("Stadt"), required=False)
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,28 @@
 | 
			
		||||
{% extends "fellchensammlung/base_bulma.html" %}
 | 
			
		||||
{% load i18n %}
 | 
			
		||||
{% load crispy_forms_tags %}
 | 
			
		||||
 | 
			
		||||
{% block title %}<title>{% translate "Vermittlung hinzufügen" %}</title>{% endblock %}
 | 
			
		||||
 | 
			
		||||
{% block content %}
 | 
			
		||||
    <h1>{% translate "Vermitteln" %}</h1>
 | 
			
		||||
    <div class="notification">
 | 
			
		||||
        <button class="delete"></button>
 | 
			
		||||
        <p>
 | 
			
		||||
            {% url 'terms-of-service' as rules_url %}
 | 
			
		||||
            {% trans "Regeln" as rules_text %}
 | 
			
		||||
            {% blocktranslate with rules_link='<a href="'|add:rules_url|add:'">'|add:rules_text|add:'</a>'|safe %}
 | 
			
		||||
                Bitte mach dich zunächst mit unseren {{ rules_link }} vertraut. Dann trage hier die ersten Informationen ein.
 | 
			
		||||
                Wenn du Details und Fotos zu den Tieren hinzufügen willst oder ihr Geschlecht und Geburtsdatum anpassen
 | 
			
		||||
                willst,
 | 
			
		||||
                kannst du das im nächsten Schritt tun.
 | 
			
		||||
            {% endblocktranslate %}
 | 
			
		||||
        </p>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <form method="post" enctype="multipart/form-data">
 | 
			
		||||
        {% csrf_token %}
 | 
			
		||||
        {{ form }}
 | 
			
		||||
        <button class="button is-primary" type="submit">{% translate "Speichern" %}</button>
 | 
			
		||||
    </form>
 | 
			
		||||
{% endblock %}
 | 
			
		||||
@@ -53,6 +53,7 @@ urlpatterns = [
 | 
			
		||||
    path("bulma/map/", views.map_bulma, name="map-bulma"),
 | 
			
		||||
    # ex: /vermitteln/
 | 
			
		||||
    path("vermitteln/", views.add_adoption_notice, name="add-adoption"),
 | 
			
		||||
    path("bulma/vermitteln/", views.add_adoption_notice_bulma, name="add-adoption-bulma"),
 | 
			
		||||
 | 
			
		||||
    path("ueber-uns/", views.about, name="about"),
 | 
			
		||||
    path("bulma/ueber-uns/", views.about_bulma, name="about-bulma"),
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,8 @@ from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, Moderatio
 | 
			
		||||
    ImportantLocation
 | 
			
		||||
from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageForm, ReportAdoptionNoticeForm, \
 | 
			
		||||
    CommentForm, ReportCommentForm, AnimalForm, \
 | 
			
		||||
    AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal
 | 
			
		||||
    AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal, \
 | 
			
		||||
    BulmaAdoptionNoticeForm
 | 
			
		||||
from .models import Language, Announcement
 | 
			
		||||
from .tools import i18n
 | 
			
		||||
from .tools.geo import GeoAPI, zoom_level_for_radius
 | 
			
		||||
@@ -310,6 +311,47 @@ def add_adoption_notice(request):
 | 
			
		||||
    return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def add_adoption_notice_bulma(request):
 | 
			
		||||
    if request.method == 'POST':
 | 
			
		||||
        form = BulmaAdoptionNoticeForm(request.POST)
 | 
			
		||||
 | 
			
		||||
        if form.is_valid():
 | 
			
		||||
            an_instance = form.save(commit=False)
 | 
			
		||||
            an_instance.owner = request.user
 | 
			
		||||
 | 
			
		||||
            if request.user.trust_level >= TrustLevel.MODERATOR:
 | 
			
		||||
                an_instance.set_active()
 | 
			
		||||
            else:
 | 
			
		||||
                an_instance.set_unchecked()
 | 
			
		||||
 | 
			
		||||
            # Get the species and number of animals from the form
 | 
			
		||||
            species = form.cleaned_data["species"]
 | 
			
		||||
            sex = form.cleaned_data["sex"]
 | 
			
		||||
            num_animals = form.cleaned_data["num_animals"]
 | 
			
		||||
            date_of_birth = form.cleaned_data["date_of_birth"]
 | 
			
		||||
            for i in range(0, num_animals):
 | 
			
		||||
                Animal.objects.create(owner=request.user,
 | 
			
		||||
                                      name=f"{species} {i + 1}", adoption_notice=an_instance, species=species, sex=sex,
 | 
			
		||||
                                      date_of_birth=date_of_birth)
 | 
			
		||||
 | 
			
		||||
            """Log"""
 | 
			
		||||
            Log.objects.create(user=request.user, action="add_adoption_notice",
 | 
			
		||||
                               text=f"{request.user} hat Vermittlung {an_instance.pk} hinzugefügt")
 | 
			
		||||
 | 
			
		||||
            """Spin up a task that adds the location and notifies search subscribers"""
 | 
			
		||||
            post_adoption_notice_save.delay(an_instance.id)
 | 
			
		||||
 | 
			
		||||
            """Subscriptions"""
 | 
			
		||||
            # Automatically subscribe user that created AN to AN
 | 
			
		||||
            Subscriptions.objects.create(owner=request.user, adoption_notice=an_instance)
 | 
			
		||||
 | 
			
		||||
            return redirect(reverse("adoption-notice-detail", args=[an_instance.pk]))
 | 
			
		||||
    else:
 | 
			
		||||
        form = BulmaAdoptionNoticeForm()
 | 
			
		||||
    return render(request, 'fellchensammlung/forms/bulma-form-add-adoption.html', {'form': form})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@login_required
 | 
			
		||||
def adoption_notice_add_animal(request, adoption_notice_id):
 | 
			
		||||
    # Only users that are mods or owners of the adoption notice are allowed to add to it
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user