-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Oprettelse af frivillig forespørgsel uden login
2 fejl: Listen med afdelinger er både m checkboxe (korrekt), og radiobuttons (forkerte) Besked om success vises også efter login
- Loading branch information
Showing
11 changed files
with
196 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from django import forms | ||
from crispy_forms.helper import FormHelper | ||
from crispy_forms.layout import Layout, Fieldset, Hidden, Div, Field, Submit | ||
|
||
from members.models.volunteerrequest import VolunteerRequest | ||
|
||
from members.models.department import Department | ||
|
||
from django.forms.widgets import CheckboxSelectMultiple | ||
from django.utils.html import format_html | ||
|
||
|
||
class CustomCheckboxSelectMultiple(CheckboxSelectMultiple): | ||
def render(self, name, value, attrs=None, choices=()): | ||
output = [] | ||
for option in self.choices: | ||
obj = option[1] | ||
address = f"{obj.name} (" | ||
if obj.address.descriptiontext: | ||
address += f"{obj.address.descriptiontext} " | ||
if obj.address.streetname: | ||
address += f"{obj.address.streetname} " | ||
if obj.address.housenumber: | ||
address += f"{obj.address.housenumber}, " | ||
if obj.address.zipcode: | ||
address += f"{obj.address.zipcode} " | ||
if obj.address.city: | ||
address += f"{obj.address.city}" | ||
address += ")" | ||
output.append( | ||
format_html( | ||
'<label><input type="checkbox" name="{}" value="{}"> {}</label>', | ||
name, | ||
option[0], | ||
address, | ||
) | ||
) | ||
return format_html("<div>{}</div>", format_html("".join(output))) | ||
|
||
|
||
class VolunteerRequestForm(forms.ModelForm): | ||
department_list = forms.ModelMultipleChoiceField( | ||
queryset=Department.objects.filter(closed_dtm__isnull=True) | ||
.order_by("id") | ||
.distinct(), | ||
widget=CustomCheckboxSelectMultiple(), | ||
required=True, | ||
label="Vælg Afdeling(er)x", | ||
) | ||
|
||
class Meta: | ||
model = VolunteerRequest | ||
fields = [ | ||
"name", | ||
"email", | ||
"phone", | ||
"age", | ||
"zip", | ||
"info_reference", | ||
"info_whishes", | ||
"department_list", | ||
] | ||
|
||
def __init__(self, *args, **kwargs): | ||
print("INIT") | ||
super(VolunteerRequestForm, self).__init__(*args, **kwargs) | ||
self.fields["department_list"].label_from_instance = self.label_from_instance | ||
self.helper = FormHelper() | ||
self.helper.form_method = "post" | ||
self.helper.layout = Layout( | ||
Hidden("form_id", "volunteer_requestForm", id="id_form_id"), | ||
Fieldset( | ||
"Frivilliges oplysninger", | ||
Div( | ||
Div(Field("name"), css_class="col-md-12"), | ||
Div(Field("email"), css_class="col-md-12"), | ||
Div(Field("phone"), css_class="col-md-4"), | ||
Div(Field("age"), css_class="col-md-4"), | ||
Div(Field("zip"), css_class="col-md-4"), | ||
Div(Field("info_reference"), css_class="col-md-12"), | ||
Div(Field("info_whishes"), css_class="col-md-12"), | ||
Div(Field("department_list"), css_class="col-md-12"), | ||
css_class="row", | ||
), | ||
), | ||
Submit("submit", "Opret", css_class="btn-success"), | ||
) | ||
|
||
def label_from_instance(self, obj): | ||
address = f"{obj.name} [{obj.id}](" | ||
if obj.address.descriptiontext is not None: | ||
address += f"{obj.address.descriptiontext} " | ||
if obj.address.streetname is not None: | ||
address += f"{obj.address.streetname} " | ||
if obj.address.housenumber is not None: | ||
address += f"{obj.address.housenumber}, " | ||
if obj.address.zipcode is not None: | ||
address += f"{obj.address.zipcode} " | ||
if obj.address.city is not None: | ||
address += f"{obj.address.city}" | ||
if address is not None: | ||
address = f"({address})" | ||
return f"{obj.name} {address}" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Generated by Django 4.2.11 on 2024-11-25 15:26 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("members", "0047_volunteerrequest_volunteerrequestdepartment_and_more"), | ||
("members", "0060_alter_union_options"), | ||
] | ||
|
||
operations = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% extends 'members/base.html' %} | ||
{% block content %} | ||
<div class="alert alert-success"> | ||
<h1>Volunteer Request Submitted</h1> | ||
<p>Your volunteer request has been submitted successfully!</p> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.