Skip to content

Commit

Permalink
Oprettelse af frivillig forespørgsel uden login
Browse files Browse the repository at this point in the history
2 fejl:
Listen med afdelinger er både m checkboxe (korrekt), og radiobuttons (forkerte)
Besked om success vises også efter login
  • Loading branch information
mhewel committed Nov 25, 2024
1 parent 01ca1cc commit 092f064
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 251 deletions.
6 changes: 2 additions & 4 deletions members/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .person_form import PersonForm
from .signup_form import signupForm
from .volunteer_signup_form import vol_signupForm
from .volunteer_request_new_form import volunteerRequestNewForm
from .volunteer_request_form import VolunteerRequestForm
from .admin_signup_form import adminSignupForm
from .activity_signup_form import ActivitySignupForm
from .activity_invite_decline_form import ActivivtyInviteDeclineForm
Expand All @@ -13,7 +13,5 @@
signupForm,
vol_signupForm,
adminSignupForm,
volunteerRequestNewForm,
volunteer_request_new_form,

VolunteerRequestForm,
]
103 changes: 103 additions & 0 deletions members/forms/volunteer_request_form.py
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}"
156 changes: 0 additions & 156 deletions members/forms/volunteer_request_new_form.py

This file was deleted.

13 changes: 13 additions & 0 deletions members/migrations/0061_merge_20241125_1626.py
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 = []
2 changes: 1 addition & 1 deletion members/templates/members/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a id="login-logout" href="{% url 'person_logout' %}">Log ud</a>
{% else %}
<a href="{% url "account_create" %}">Tilmeld barn</a>
<a href="{% url "volunteer_signup" %}">Bliv frivillig</a>
<a href="{% url "volunteer_request" %}">Bliv frivillig</a>
<a id="login-logout" href="{% url 'person_login' %}{% if not 'logout' in request.path %}?next={{request.path}}{% endif %}">Log ind</a>
{% endif %}
<a href="https://codingpirates.dk" target="_blank">
Expand Down
24 changes: 19 additions & 5 deletions members/templates/members/volunteer_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
{% block content %}
<div class="alert alert-secondary">
<h1>Ønsker du at være frivillig - og ikke allerede oprettet i medlemssystemet ?</h1>
<p>Hvis du har børn der er tilmeldt i systemet og allerede er oprettet som familie, så log blot på jeres familie side med den email du opskrev dig med, da du tilmeldte dig. Her kan du også tilføje flere personer, hvis det f.eks. er din partner der har tilmeldt børnene men du nu selv vil være med som frivillig.</p>
<p>Hvis du har børn der er tilmeldt i systemet og allerede er oprettet som familie,
så log blot på jeres familie side med den email du opskrev dig med, da du tilmeldte dig<br>
Her kan du også tilføje flere personer, hvis det f.eks. er din partner der har tilmeldt børnene men du nu selv vil være med som frivillig.</p>
<p>
Denne formular er tænkt til frivillige, der ikke har børn der er medlemmer i Coding Pirates.
</p>
</div>
<div class="card">
<div class="card-body">
{% crispy vol_signupform %}
</div>
<div class="card">
<div class="card-body">
{% if messages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}">
{{ message }}
</div>
{% endfor %}
{% endif %}

<form method="post">
{% csrf_token %}
{{ volunteer_request_form|crispy }}
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
{% endblock %}
7 changes: 7 additions & 0 deletions members/templates/members/volunteer_request_created.html
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 %}
13 changes: 8 additions & 5 deletions members/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.urls import re_path
from django.views.generic import TemplateView

from members.views import (
AccountCreate,
Activities,
Expand All @@ -14,13 +16,12 @@
PersonUpdate,
QuickpayCallback,
SupportMembership,
VolunteerRequestNew,
volunteer_request_view,
WaitingListSetSubscription,
departmentView,
paymentGatewayErrorView,
userCreated,
volunteerSignup,
VolunteerRequestNew,
)
from django.contrib.auth import views as auth_views
from graphene_django.views import GraphQLView
Expand Down Expand Up @@ -76,10 +77,12 @@
re_path(r"^membership/$", Membership, name="membership"),
re_path(r"^support_membership/$", SupportMembership, name="support_membership"),
re_path(r"^volunteer$", volunteerSignup, name="volunteer_signup"),
# re_path(r"^volunteer_request_new/$", VolunteerRequestNew, name="volunteer_request_new"),
re_path(r"^volunteer_request/$", volunteer_request_view, name="volunteer_request"),
re_path(
r"^new_vr/$", VolunteerRequestNew, name="volunteer_request_new_form"
), # name="volunteer_request_new"),
r"^volunteer_request_created/$",
TemplateView.as_view(template_name="members/volunteer_request_created.html"),
name="volunteer_request_created",
),
re_path(r"^user_created/$", userCreated, name="user_created"),
re_path(r"^admin_signup/$", AdminSignup, name="admin_signup"),
re_path(r"^family/$", FamilyDetails, name="family_detail"),
Expand Down
Loading

0 comments on commit 092f064

Please sign in to comment.