Skip to content

Commit ff62b67

Browse files
maroshmkaKátia Nakamura
authored andcommitted
Add template, form and view for Volunteer create. (#105)
* Add template, form and view for Volunteer create. * core: remove volunteers button from sidebar * organizers: add volunteers google forms link to organizers page
1 parent ad88bb8 commit ff62b67

File tree

10 files changed

+152
-5
lines changed

10 files changed

+152
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.ui-datepicker {
2+
background-color: #32383A;
3+
border: 1px solid #66AFE9;
4+
border-radius: 4px;
5+
box-shadow: 0 0 8px rgba(102,175,233,.6);
6+
display: none;
7+
margin-top: 4px;
8+
padding: 10px;
9+
width: 240px;
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#id_country {
2+
height: 40px;
3+
}
4+
5+
#id_profile_picture{
6+
color: white;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$( ".datepicker" ).datepicker({
2+
changeMonth: true,
3+
changeYear: true,
4+
yearRange: "1900:2018"
5+
});
6+
7+
$("#id_description").addClass("form-control");

pyconbalkan/core/templates/base.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<link rel="stylesheet" href="{% static 'css/_fonts.css' %}">
2222
<link rel="stylesheet" href="{% static 'css/components/event-sidebar.css' %}">
2323
<link rel="stylesheet" href="{% static 'css/components/page.css' %}">
24+
<link rel="stylesheet" href="{% static 'css/components/datepicker.css' %}">
2425
<link rel="stylesheet" href="{% static 'css/components/post.css' %}">
2526
<link rel="stylesheet" href="{% static 'css/components/title.css' %}">
2627
<link rel="stylesheet" href="{% static 'css/components/button.css' %}">
@@ -36,6 +37,7 @@
3637
<link rel="stylesheet" href="{% static 'css/components/page.css' %}">
3738
<link rel="stylesheet" href="{% static 'css/components/post.css' %}">
3839
<link rel="stylesheet" href="{% static 'css/components/sponsors.css' %}">
40+
<link rel="stylesheet" href="{% static 'css/components/volunteer.css' %}">
3941
<link rel="stylesheet" href="{% static 'css/components/title.css' %}">
4042
<link rel="stylesheet" href="{% static 'css/components/timetable.css' %}">
4143
<link rel="stylesheet" href="{% static 'css/helpers/spacing.css' %}">

pyconbalkan/core/templates/includes/event_sidebar.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ <h1>#{{ conference.number }}</h1>
2020
{{ conference.get_type_display }}
2121
</p>
2222

23-
{% if conference.tickets %}
2423
<div class="event-button__wrapper">
25-
<a class="button button--yellow mb-xs-40 event-button" href="{{ conference.tickets }}" target="_blank" role="button">Join Us!</a>
24+
{% if conference.tickets %}
25+
<a class="button button--yellow mb-xs-80" href="{{ conference.tickets }}" target="_blank" role="button">Join Us!</a>
26+
{% endif %}
2627
</div>
27-
{% endif %}
2828
<div class="social__links mb-xs-20">
2929
{% if conference.facebook %}<a href="{{ conference.facebook }}" class="facebook" target="_blank"></a>{% endif %}
3030
{% if conference.instagram %}<a href="{{ conference.instagram }}" class="instagram" target="_blank"></a>{% endif %}

pyconbalkan/organizers/forms.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from django import forms
2+
from django.db import transaction
3+
4+
from pyconbalkan.organizers.models import Volunteer, VolunteerPhoto
5+
6+
7+
class VolunteerCreateForm(forms.ModelForm):
8+
required_fields = (
9+
'full_name', 'name', 'date_of_birth', 'job',
10+
'email', 'description', 'country', 'profile_photo'
11+
)
12+
13+
profile_picture = forms.ImageField(label='Profile Photo', required=True)
14+
15+
def __init__(self, **kwargs):
16+
super().__init__(**kwargs)
17+
18+
for name, field in self.fields.items():
19+
self.add_required(name, field)
20+
self.add_form_control(field)
21+
self.label_as_placeholder(field, name)
22+
23+
def add_form_control(self, field):
24+
old_classes = field.widget.attrs['class'] if 'class' in field.widget.attrs else ''
25+
field.widget.attrs.update({'class': f'{old_classes} form-control'})
26+
27+
def label_as_placeholder(self, field, name):
28+
placeholder = field.label if not field.required else field.label + '*'
29+
field.widget.attrs.update({'placeholder': placeholder})
30+
31+
if name != 'profile_picture':
32+
field.label = ''
33+
else:
34+
field.label = placeholder
35+
36+
def add_required(self, name, field):
37+
if name in self.required_fields:
38+
field.required = True
39+
40+
def save(self, commit=True):
41+
"""
42+
Save both Volunteer model and VolunteerPhoto at once.
43+
If more complex - maybe add formset.
44+
"""
45+
46+
with transaction.atomic():
47+
instance = super().save(commit=commit)
48+
VolunteerPhoto.objects.create(
49+
volunteer=instance, profile_picture=self.cleaned_data['profile_picture']
50+
)
51+
return instance
52+
53+
class Meta:
54+
model = Volunteer
55+
exclude = ('active', 'user', 'type', 'slug', )
56+
widgets = {
57+
'date_of_birth': forms.DateInput(attrs={'class': 'datepicker'}),
58+
}

pyconbalkan/organizers/templates/organizers.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ <h2 class="title title--white title--medium title--uppercase mt-xs-20 mb-xs-80">
4343
<h1 class="centered">Volunteers</h1>
4444
<hr class="line line__centered">
4545

46+
<div class="card">
47+
<a class="button button--yellow mb-xs-40 event-button" href="https://docs.google.com/forms/d/e/1FAIpQLSdJO6rP5jtHvpioYWMoimIRaQx-W7TR3uLmeu-hFg-ad4ZpgA/viewform" target="_blank">
48+
Join PyCon Balkan as a Volunteer!
49+
</a>
50+
</div>
51+
<div class="event-button__wrapper">
52+
53+
</div>
4654
{% if volunteers %}
4755
<div class="card">
4856
{% for volunteer in volunteers %}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{% extends 'base.html' %}
2+
{% load static %}
3+
4+
{% block main_content %}
5+
<h1 class="title title--yellow mb-xs-40">Sign up as a Volunteer!</h1>
6+
<hr class="line line--blue line--short line--spaced">
7+
8+
{% if success %}
9+
<h2 class="success-message">
10+
{{ success | safe }}
11+
</h2>
12+
<hr class="line line--blue line--short line--spaced">
13+
{% endif %}
14+
15+
<form class="form" action="{% url 'volunteers_create' %}" method="POST"
16+
enctype="multipart/form-data" novalidate>
17+
<div class="form-group">
18+
{% csrf_token %}
19+
{{ form.as_p }}
20+
<input class="button button--blue button--push button--fullwidth " type="submit"
21+
value="Submit"/>
22+
</div>
23+
</form>
24+
{{ form.media }}
25+
26+
{% endblock main_content %}
27+
28+
29+
{% block scripts %}
30+
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
31+
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
32+
crossorigin="anonymous"></script>
33+
<script src="{% static 'js/volunteer.js' %}" type="text/javascript"></script>
34+
{% endblock %}

pyconbalkan/organizers/views.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from django.shortcuts import render, get_object_or_404
22
from rest_framework import viewsets
33

4+
from pyconbalkan.conference.models import Conference
5+
from pyconbalkan.organizers.forms import VolunteerCreateForm
46
from pyconbalkan.organizers.models import Volunteer
57
from pyconbalkan.organizers.serializers import VolunteerSerializer
68

@@ -25,4 +27,22 @@ def organizers_listview(request):
2527
'volunteers': volunteers,
2628
'organizers': organizers,
2729
}
28-
return render(request, 'organizers.html', context)
30+
return render(request, 'organizers.html', context)
31+
32+
33+
def volunteers_createview(request):
34+
context = {}
35+
36+
if request.method == 'POST':
37+
form = VolunteerCreateForm(data=request.POST, files=request.FILES)
38+
if form.is_valid():
39+
volunteer = form.save()
40+
context['success'] = f'{volunteer.full_name}, you have been successfully signed up ' \
41+
f'as a volunteer! <br> We will contact you soon. <br><br> ' \
42+
f'Thank you! :)<br>'
43+
form = VolunteerCreateForm()
44+
else:
45+
form = VolunteerCreateForm()
46+
47+
context['form'] = form
48+
return render(request, 'volunteers_create.html', context)

pyconbalkan/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pyconbalkan.news.views import *
1313
from pyconbalkan.settings import PDF_ROOT
1414
from pyconbalkan.speaker.views import *
15-
from pyconbalkan.organizers.views import organizer_view, organizers_listview
15+
from pyconbalkan.organizers.views import organizer_view, organizers_listview, volunteers_createview
1616
from pyconbalkan.coc.views import coc_view, response_guide
1717
from pyconbalkan.sponsors.views import sponsor_view, sponsoring_view, sponsors_view
1818
from pyconbalkan.organizers.api_urls import router as organizers
@@ -50,6 +50,7 @@
5050
path('robots.txt', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
5151
path('organizers/<slug:slug>/', organizer_view, name='organizer_detail'),
5252
path('organizers', organizers_listview, name='organizers'),
53+
path('volunteers/create/', volunteers_createview, name='volunteers_create'),
5354
path('about', about_view, name='about'),
5455
path('contact', contact_view, name='contact'),
5556
path('cfp', cfp_view, name='cfp'),

0 commit comments

Comments
 (0)