From 0f50a82d73ef06e9878118945f5a9d89a4809f21 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C3=A1rio=20Hunka?=
Date: Sun, 29 Jul 2018 21:10:30 +0200
Subject: [PATCH 1/3] Add template, form and view for Volunteer create.
---
.../core/static/css/components/datepicker.css | 10 ++++
.../core/static/css/components/volunteer.css | 7 +++
pyconbalkan/core/static/js/volunteer.js | 7 +++
pyconbalkan/core/templates/base.html | 2 +
.../templates/includes/event_sidebar.html | 8 ++-
pyconbalkan/organizers/forms.py | 58 +++++++++++++++++++
.../templates/volunteers_create.html | 34 +++++++++++
pyconbalkan/organizers/views.py | 22 ++++++-
pyconbalkan/urls.py | 3 +-
9 files changed, 146 insertions(+), 5 deletions(-)
create mode 100644 pyconbalkan/core/static/css/components/datepicker.css
create mode 100644 pyconbalkan/core/static/css/components/volunteer.css
create mode 100644 pyconbalkan/core/static/js/volunteer.js
create mode 100644 pyconbalkan/organizers/forms.py
create mode 100644 pyconbalkan/organizers/templates/volunteers_create.html
diff --git a/pyconbalkan/core/static/css/components/datepicker.css b/pyconbalkan/core/static/css/components/datepicker.css
new file mode 100644
index 00000000..330eb2a9
--- /dev/null
+++ b/pyconbalkan/core/static/css/components/datepicker.css
@@ -0,0 +1,10 @@
+.ui-datepicker {
+ background-color: #32383A;
+ border: 1px solid #66AFE9;
+ border-radius: 4px;
+ box-shadow: 0 0 8px rgba(102,175,233,.6);
+ display: none;
+ margin-top: 4px;
+ padding: 10px;
+ width: 240px;
+}
\ No newline at end of file
diff --git a/pyconbalkan/core/static/css/components/volunteer.css b/pyconbalkan/core/static/css/components/volunteer.css
new file mode 100644
index 00000000..338d7fd1
--- /dev/null
+++ b/pyconbalkan/core/static/css/components/volunteer.css
@@ -0,0 +1,7 @@
+#id_country {
+ height: 40px;
+}
+
+#id_profile_picture{
+ color: white;
+}
diff --git a/pyconbalkan/core/static/js/volunteer.js b/pyconbalkan/core/static/js/volunteer.js
new file mode 100644
index 00000000..686082a4
--- /dev/null
+++ b/pyconbalkan/core/static/js/volunteer.js
@@ -0,0 +1,7 @@
+$( ".datepicker" ).datepicker({
+ changeMonth: true,
+ changeYear: true,
+ yearRange: "1900:2018"
+});
+
+$("#id_description").addClass("form-control");
diff --git a/pyconbalkan/core/templates/base.html b/pyconbalkan/core/templates/base.html
index a2009405..b357940e 100644
--- a/pyconbalkan/core/templates/base.html
+++ b/pyconbalkan/core/templates/base.html
@@ -22,6 +22,7 @@
+
@@ -37,6 +38,7 @@
+
diff --git a/pyconbalkan/core/templates/includes/event_sidebar.html b/pyconbalkan/core/templates/includes/event_sidebar.html
index 62e67ca8..15575e35 100644
--- a/pyconbalkan/core/templates/includes/event_sidebar.html
+++ b/pyconbalkan/core/templates/includes/event_sidebar.html
@@ -20,11 +20,13 @@ #{{ conference.number }}
{{ conference.get_type_display }}
- {% if conference.tickets %}
{% if conference.facebook %}
{% endif %}
{% if conference.instagram %}
{% endif %}
diff --git a/pyconbalkan/organizers/forms.py b/pyconbalkan/organizers/forms.py
new file mode 100644
index 00000000..5b4eb4a7
--- /dev/null
+++ b/pyconbalkan/organizers/forms.py
@@ -0,0 +1,58 @@
+from django import forms
+from django.db import transaction
+
+from pyconbalkan.organizers.models import Volunteer, VolunteerPhoto
+
+
+class VolunteerCreateForm(forms.ModelForm):
+ required_fields = (
+ 'full_name', 'name', 'date_of_birth', 'job',
+ 'email', 'description', 'country', 'profile_photo'
+ )
+
+ profile_picture = forms.ImageField(label='Profile Photo', required=True)
+
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
+
+ for name, field in self.fields.items():
+ self.add_required(name, field)
+ self.add_form_control(field)
+ self.label_as_placeholder(field, name)
+
+ def add_form_control(self, field):
+ old_classes = field.widget.attrs['class'] if 'class' in field.widget.attrs else ''
+ field.widget.attrs.update({'class': f'{old_classes} form-control'})
+
+ def label_as_placeholder(self, field, name):
+ placeholder = field.label if not field.required else field.label + '*'
+ field.widget.attrs.update({'placeholder': placeholder})
+
+ if name != 'profile_picture':
+ field.label = ''
+ else:
+ field.label = placeholder
+
+ def add_required(self, name, field):
+ if name in self.required_fields:
+ field.required = True
+
+ def save(self, commit=True):
+ """
+ Save both Volunteer model and VolunteerPhoto at once.
+ If more complex - maybe add formset.
+ """
+
+ with transaction.atomic():
+ instance = super().save(commit=commit)
+ VolunteerPhoto.objects.create(
+ volunteer=instance, profile_picture=self.cleaned_data['profile_picture']
+ )
+ return instance
+
+ class Meta:
+ model = Volunteer
+ exclude = ('active', 'user', 'type', 'slug', )
+ widgets = {
+ 'date_of_birth': forms.DateInput(attrs={'class': 'datepicker'}),
+ }
diff --git a/pyconbalkan/organizers/templates/volunteers_create.html b/pyconbalkan/organizers/templates/volunteers_create.html
new file mode 100644
index 00000000..8b9b0b7e
--- /dev/null
+++ b/pyconbalkan/organizers/templates/volunteers_create.html
@@ -0,0 +1,34 @@
+{% extends 'base.html' %}
+{% load static %}
+
+{% block main_content %}
+
Sign up as a Volunteer!
+
+
+ {% if success %}
+
+ {{ success | safe }}
+
+
+ {% endif %}
+
+
+ {{ form.media }}
+
+{% endblock main_content %}
+
+
+{% block scripts %}
+
+
+{% endblock %}
diff --git a/pyconbalkan/organizers/views.py b/pyconbalkan/organizers/views.py
index e0b11c0e..05a06d64 100644
--- a/pyconbalkan/organizers/views.py
+++ b/pyconbalkan/organizers/views.py
@@ -1,6 +1,8 @@
from django.shortcuts import render, get_object_or_404
from rest_framework import viewsets
+from pyconbalkan.conference.models import Conference
+from pyconbalkan.organizers.forms import VolunteerCreateForm
from pyconbalkan.organizers.models import Volunteer
from pyconbalkan.organizers.serializers import VolunteerSerializer
@@ -25,4 +27,22 @@ def organizers_listview(request):
'volunteers': volunteers,
'organizers': organizers,
}
- return render(request, 'organizers.html', context)
\ No newline at end of file
+ return render(request, 'organizers.html', context)
+
+
+def volunteers_createview(request):
+ context = {}
+
+ if request.method == 'POST':
+ form = VolunteerCreateForm(data=request.POST, files=request.FILES)
+ if form.is_valid():
+ volunteer = form.save()
+ context['success'] = f'{volunteer.full_name}, you have been successfully signed up ' \
+ f'as a volunteer!
We will contact you soon.
' \
+ f'Thank you! :)
'
+ form = VolunteerCreateForm()
+ else:
+ form = VolunteerCreateForm()
+
+ context['form'] = form
+ return render(request, 'volunteers_create.html', context)
diff --git a/pyconbalkan/urls.py b/pyconbalkan/urls.py
index 1dd0c0af..ca27eb3e 100644
--- a/pyconbalkan/urls.py
+++ b/pyconbalkan/urls.py
@@ -12,7 +12,7 @@
from pyconbalkan.news.views import *
from pyconbalkan.settings import PDF_ROOT
from pyconbalkan.speaker.views import *
-from pyconbalkan.organizers.views import organizer_view, organizers_listview
+from pyconbalkan.organizers.views import organizer_view, organizers_listview, volunteers_createview
from pyconbalkan.coc.views import coc_view, response_guide
from pyconbalkan.sponsors.views import sponsor_view, sponsoring_view, sponsors_view
from pyconbalkan.organizers.api_urls import router as organizers
@@ -49,6 +49,7 @@
path('robots.txt', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
path('organizers/
/', organizer_view, name='organizer_detail'),
path('organizers', organizers_listview, name='organizers'),
+ path('volunteers/create/', volunteers_createview, name='volunteers_create'),
path('about', about_view, name='about'),
path('contact', contact_view, name='contact'),
path('cfp', cfp_view, name='cfp'),
From 68899f4f9bd27067c57d43480f73af520c74eba9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A1tia=20Nakamura?=
Date: Mon, 27 Aug 2018 21:23:33 +0200
Subject: [PATCH 2/3] core: remove volunteers button from sidebar
---
pyconbalkan/core/templates/includes/event_sidebar.html | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/pyconbalkan/core/templates/includes/event_sidebar.html b/pyconbalkan/core/templates/includes/event_sidebar.html
index 15575e35..3943f1f4 100644
--- a/pyconbalkan/core/templates/includes/event_sidebar.html
+++ b/pyconbalkan/core/templates/includes/event_sidebar.html
@@ -22,10 +22,8 @@ #{{ conference.number }}
{% if conference.facebook %}
{% endif %}
From 9716c0d0a21ac420511dfb921cc60a1fb87b7e63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?K=C3=A1tia=20Nakamura?=
Date: Mon, 27 Aug 2018 21:24:17 +0200
Subject: [PATCH 3/3] organizers: add volunteers google forms link to
organizers page
---
pyconbalkan/organizers/templates/organizers.html | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/pyconbalkan/organizers/templates/organizers.html b/pyconbalkan/organizers/templates/organizers.html
index dab0167c..38cd734b 100644
--- a/pyconbalkan/organizers/templates/organizers.html
+++ b/pyconbalkan/organizers/templates/organizers.html
@@ -43,6 +43,14 @@
Volunteers
+
+
+
+
{% if volunteers %}
{% for volunteer in volunteers %}