volunteers list

This commit is contained in:
Élie Bouttier 2016-10-24 13:56:55 +02:00
parent e497ab0df2
commit d988a11a71
6 changed files with 114 additions and 2 deletions

View File

@ -73,6 +73,9 @@
<li role="presentation">
<a role="menuitem" tabindex="-1" href="{% url 'list-speakers' %}"><span class="glyphicon glyphicon-user"></span>&nbsp;{% trans "Speakers" %}</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="{% url 'list-volunteers' %}"><span class="glyphicon glyphicon-thumbs-up"></span>&nbsp;{% trans "Volunteers" %}</a>
</li>
</ul>
</li>
<li class="dropdown{% block planningtab %}{% endblock %}">

View File

@ -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')

View File

@ -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')

View File

@ -0,0 +1,73 @@
{% extends 'base.html' %}
{% load bootstrap3 i18n %}
{% block listingtab %} active{% endblock %}
{% block content %}
<h1>{% trans "Volunteers" %}</h1>
<a class="btn btn-primary" role="button" data-toggle="collapse" href="#filter" aria-expanded="{{ show_filters|yesno:"true,false" }}" aria-controles="filter">{% trans "Show filtering options…" %}</a>
<br /><br />
<div class="collapse{{ show_filters|yesno:" in," }}" id="filter">
<div class="well">
<form class="form-horizontal" method="get">
{% bootstrap_form filter_form %}
<input type="submit" class="btn btn-success" value="{% trans "Filter" %}">
</form>
</div>
</div>
<table class="table table-bordered table-hover">
<caption>{% trans "Total:" %} {{ volunteer_list|length }} {% trans "volunteer" %}{{ volunteer_list|length|pluralize }}
</caption>
<thead>
<tr>
<th class="text-center">{% trans "Username" %}</th>
<th class="text-center">{% trans "Fullname" %}</th>
<th class="text-center">{% trans "Activities" %}</th>
<th class="text-center"></th>
</tr>
</thead>
{% for volunteer in volunteer_list %}
{% if forloop.first %}
<tbody>
{% endif %}
<tr class="clickable-row" data-href="{% url 'show-speaker' username=volunteer.user.username %}">
<td>{{ volunteer.user.username }}</td>
<td>{{ volunteer.user.get_full_name }}</td>
<td>
{% for activity in volunteer.user.activities.all %}
<span class="badge">{{ activity }}</span>
{% endfor %}
</td>
<td>
<a class="btn btn-{% if volunteer.conversation.messages.last.author == volunteer.user %}primary{% else %}default{% endif %}" href="{% url 'conversation' volunteer.user.username %}">{% trans "Contact" %}</a>
</td>
</tr>
</li>
{% if forloop.last %}
</tbody>
{% endif %}
{% endfor %}
</table>
{% endblock %}
{% block js_end %}
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".clickable-row").click(function() {
window.location = $(this).data("href");
});
var anchor = window.location.hash.replace("#", "");
if (anchor == "filter") {
$("#filter").collapse('show');
}
});
</script>
{% endblock %}

View File

@ -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<slug>[-\w]+)/edit/$', views.ActivityUpdate.as_view(), name='edit-activity'),

View File

@ -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,
})