diff --git a/ponyconf/templates/base.html b/ponyconf/templates/base.html
index 312c63b..074719a 100644
--- a/ponyconf/templates/base.html
+++ b/ponyconf/templates/base.html
@@ -73,6 +73,9 @@
{% trans "Speakers" %}
+
+ {% trans "Volunteers" %}
+
diff --git a/volunteers/forms.py b/volunteers/forms.py
index 4ed18d1..7666d45 100644
--- a/volunteers/forms.py
+++ b/volunteers/forms.py
@@ -7,3 +7,17 @@ class ActivityForm(forms.ModelForm):
class Meta:
model = Activity
fields=['name', 'description', 'participants']
+
+
+class VolunteerFilterForm(forms.Form):
+ activity = forms.MultipleChoiceField(
+ required=False,
+ widget=forms.CheckboxSelectMultiple,
+ choices=[],
+ )
+
+ def __init__(self, *args, **kwargs):
+ site = kwargs.pop('site')
+ super().__init__(*args, **kwargs)
+ activities = Activity.objects.filter(site=site)
+ self.fields['activity'].choices = activities.values_list('slug', 'name')
diff --git a/volunteers/models.py b/volunteers/models.py
index 4c948e1..780084c 100644
--- a/volunteers/models.py
+++ b/volunteers/models.py
@@ -12,7 +12,7 @@ class Activity(models.Model):
name = models.CharField(max_length=256, verbose_name=_('Name'))
slug = AutoSlugField(populate_from='name')
description = models.TextField(blank=True, verbose_name=_('Description'))
- participants = models.ManyToManyField(User, blank=True, verbose_name=_('Participants'))
+ participants = models.ManyToManyField(User, blank=True, related_name='activities', verbose_name=_('Participants'))
class Meta:
unique_together = ('site', 'name')
diff --git a/volunteers/templates/volunteers/volunteer_list.html b/volunteers/templates/volunteers/volunteer_list.html
new file mode 100644
index 0000000..51f40cf
--- /dev/null
+++ b/volunteers/templates/volunteers/volunteer_list.html
@@ -0,0 +1,73 @@
+{% extends 'base.html' %}
+
+{% load bootstrap3 i18n %}
+
+{% block listingtab %} active{% endblock %}
+
+{% block content %}
+
+{% trans "Volunteers" %}
+
+{% trans "Show filtering options…" %}
+
+
+
+
+
+
+ {% trans "Total:" %} {{ volunteer_list|length }} {% trans "volunteer" %}{{ volunteer_list|length|pluralize }}
+
+
+
+ {% trans "Username" %} |
+ {% trans "Fullname" %} |
+ {% trans "Activities" %} |
+ |
+
+
+ {% for volunteer in volunteer_list %}
+ {% if forloop.first %}
+
+ {% endif %}
+
+ {{ volunteer.user.username }} |
+ {{ volunteer.user.get_full_name }} |
+
+ {% for activity in volunteer.user.activities.all %}
+ {{ activity }}
+ {% endfor %}
+ |
+
+ {% trans "Contact" %}
+ |
+
+
+ {% if forloop.last %}
+
+ {% endif %}
+ {% endfor %}
+
+
+{% endblock %}
+
+{% block js_end %}
+
+{% endblock %}
diff --git a/volunteers/urls.py b/volunteers/urls.py
index 9df2eac..b5146a9 100644
--- a/volunteers/urls.py
+++ b/volunteers/urls.py
@@ -5,6 +5,7 @@ from . import views
urlpatterns = [
url(r'^enrole/$', views.participate, name='participate-as-volunteer'),
+ url(r'^list/$', views.volunteer_list, name='list-volunteers'),
url(r'^activities/$', views.ActivityList.as_view(), name='list-activities'),
url(r'^activities/add/$', views.ActivityCreate.as_view(), name='add-activity'),
url(r'^activities/(?P[-\w]+)/edit/$', views.ActivityUpdate.as_view(), name='edit-activity'),
diff --git a/volunteers/views.py b/volunteers/views.py
index 54e2d2b..9c8aef2 100644
--- a/volunteers/views.py
+++ b/volunteers/views.py
@@ -5,10 +5,12 @@ from django.contrib.auth.decorators import login_required
from ponyconf.mixins import OnSiteFormMixin
+from accounts.decorators import orga_required, staff_required
from accounts.mixins import OrgaRequiredMixin, StaffRequiredMixin
+from accounts.models import Participation
from .models import Activity
-from .forms import ActivityForm
+from .forms import ActivityForm, VolunteerFilterForm
@@ -52,3 +54,22 @@ class ActivityUpdate(OrgaRequiredMixin, ActivityMixin, ActivityFormMixin, Update
class ActivityDetail(StaffRequiredMixin, ActivityMixin, DetailView):
pass
+
+
+@staff_required
+def volunteer_list(request):
+ show_filters = False
+ site = get_current_site(request)
+ filter_form = VolunteerFilterForm(request.GET or None, site=site)
+ # Filtering
+ volunteers = Participation.objects.filter(site=site,user__activities__isnull=False).order_by('pk').distinct()
+ if filter_form.is_valid():
+ data = filter_form.cleaned_data
+ if len(data['activity']):
+ show_filters = True
+ volunteers = volunteers.filter(user__activities__slug__in=data['activity'])
+ return render(request, 'volunteers/volunteer_list.html', {
+ 'volunteer_list': volunteers,
+ 'filter_form': filter_form,
+ 'show_filters': show_filters,
+ })