UPD: more cool participant admin stuff.
This commit is contained in:
@@ -140,4 +140,11 @@ thead input {
|
||||
content:"*";
|
||||
color: red;
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
* Used to remove the space around link like buttons (<button class="btn btn-link no-padding">).
|
||||
*/
|
||||
.no-padding {
|
||||
padding: 0px;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.test import SimpleTestCase
|
||||
|
||||
from dav_base.tests.generic import ValidatorTestMixin
|
||||
from .generic import ValidatorTestMixin
|
||||
|
||||
from ..validators import DAVNumberValidator
|
||||
|
||||
21
dav_events/migrations/0031_auto_20190604_0658.py
Normal file
21
dav_events/migrations/0031_auto_20190604_0658.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.20 on 2019-06-04 06:58
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dav_events', '0030_auto_20190603_1014'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='participant',
|
||||
name='dav_number',
|
||||
field=models.CharField(max_length=62, validators=[django.core.validators.RegexValidator('^([0-9]{1,10}/[0-9]{2,10}/)?[0-9]{1,10}(\\*[0-9]{1,10})?(\\*[0-9]{4}\\*[0-9]{4})?([* ][0-9]{8})?$', 'Ungültiges Format.')], verbose_name='DAV Mitgliednummer'),
|
||||
),
|
||||
]
|
||||
@@ -6,6 +6,8 @@ from django.utils import timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from dav_base.validators import DAVNumberValidator
|
||||
|
||||
midnight = datetime.time(00, 00, 00)
|
||||
one_day = datetime.timedelta(1)
|
||||
|
||||
@@ -32,7 +34,7 @@ class Participant(models.Model):
|
||||
phone_number = models.CharField(max_length=254,
|
||||
verbose_name=_('Telefonnummer'))
|
||||
dav_number = models.CharField(max_length=62,
|
||||
#validators=[DAVNumberValidator],
|
||||
validators=[DAVNumberValidator],
|
||||
verbose_name=_('DAV Mitgliednummer'))
|
||||
emergency_contact = models.TextField(blank=True,
|
||||
verbose_name=_('Notfall-Kontakt'))
|
||||
|
||||
@@ -219,13 +219,15 @@
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<h4>Teilnehmer (Designstudie - Das funktioniert alles noch nicht!)</h4>
|
||||
<div class="panel panel-default">
|
||||
<h4>{% trans 'Teilnehmer' %}</h4>
|
||||
{% if registrations_support %}
|
||||
<div class="panel panel-info">
|
||||
<div id="headingRegistrations" class="panel-heading" role="tab">
|
||||
<h5 class="panel-title">
|
||||
<a role="button" href="#collapseRegistrations" data-toggle="collapse" data-parent="#accordion"
|
||||
<a role="button" href="#collapseRegistrations"
|
||||
data-toggle="collapse" data-parent="#accordion"
|
||||
aria-expanded="true" aria-controls="collapseRegistrations">
|
||||
<span class="caret"></span> Anmeldungen
|
||||
<span class="caret"></span> {% trans 'Anmeldungen' %}
|
||||
</a>
|
||||
</h5>
|
||||
</div>
|
||||
@@ -236,17 +238,19 @@
|
||||
<form action="" method="post" class="form-inline">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="registration" value="{{ registration.id }}">
|
||||
{% if registration.answered %}
|
||||
<span class="text-muted disabled">
|
||||
{% endif %}
|
||||
<button type="submit" name="action" value="accept_registration"
|
||||
class="btn btn-link" title="Teilnehmer hinzufügen">
|
||||
class="btn btn-link no-padding" title="Teilnehmer hinzufügen">
|
||||
<span class="text-success">{% bootstrap_icon 'plus-sign' %}</span>
|
||||
</button>
|
||||
|
||||
<button type="submit" name="action" value="reject_registration"
|
||||
class="btn btn-link" title="Anmeldung löschen">
|
||||
class="btn btn-link no-padding" title="Anmeldung löschen">
|
||||
<span class="text-danger">{% bootstrap_icon 'minus-sign' %}</span>
|
||||
</button>
|
||||
|
||||
{% if registration.answered %}
|
||||
<span class="text-muted">
|
||||
{% endif %}
|
||||
{{ registration.get_full_name }}
|
||||
(<a href="mailto:{{ registration.email_address }}">{{ registration.email_address }}</a>,
|
||||
{{ registration.phone_number }})
|
||||
@@ -264,93 +268,101 @@
|
||||
{% endif %}
|
||||
</form>
|
||||
{% empty %}
|
||||
Keine unbestätigten Anmeldungen vorhanden
|
||||
{% trans 'Keine unbestätigten Anmeldungen vorhanden' %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
{% endif %}
|
||||
<div class="panel panel-info">
|
||||
<div id="headingAddParticipant" class="panel-heading" role="tab">
|
||||
<h5 class="panel-title">
|
||||
<a role="button" href="#collapseAddParticipant" data-toggle="collapse" data-parent="#accordion"
|
||||
<a role="button" href="#collapseAddParticipant"
|
||||
data-toggle="collapse" data-parent="#accordion"
|
||||
aria-expanded="true" aria-controls="collapseAddParticipant">
|
||||
<span class="caret"></span> weiteren Teilnehmer eintragen
|
||||
<span class="caret"></span> {% trans 'weiteren Teilnehmer eintragen' %}
|
||||
</a>
|
||||
</h5>
|
||||
</div>
|
||||
<div id="collapseAddParticipant" class="panel-collapse collapse {% if create_participant_form.errors %}in{% endif %}"
|
||||
<div id="collapseAddParticipant"
|
||||
class="panel-collapse collapse {% if create_participant_form.errors %}in{% endif %}"
|
||||
role="tabpanel" aria-labelledby="headingAddParticipant">
|
||||
<div class="panel-body">
|
||||
{% bootstrap_form_errors create_participant_form %}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.personal_names %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.family_names %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% bootstrap_field create_participant_form.address %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
{% bootstrap_field create_participant_form.postal_code %}
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
{% bootstrap_field create_participant_form.city %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.email_address %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.phone_number %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.dav_number %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.emergency_contact %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.experience %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field create_participant_form.note %}
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn btn-success">{% bootstrap_icon 'plus-sign' %} {% trans 'Teilnehmer hinzufügen' %}</button>
|
||||
{% include './includes/participant_form.html' with form=create_participant_form %}
|
||||
<button type="submit" name="action" value="create_participant" class="btn btn-success">
|
||||
{% bootstrap_icon 'plus-sign' %} {% trans 'Teilnehmer hinzufügen' %}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% for participant in participants %}
|
||||
<div class="panel panel-default">
|
||||
<div id="headingParticipant_{{ participant.id }}" class="panel-heading" role="tab">
|
||||
{% for form in participant_formset %}
|
||||
{% with participant_id=form.instance.id %}
|
||||
{% with position=form.instance.position %}
|
||||
<div class="panel {% if event.max_participants and position > event.max_participant %}panel-warning{% else %}panel-default{% endif %}">
|
||||
<div id="headingParticipant_{{ participant_id }}" class="panel-heading" role="tab">
|
||||
<h5 class="panel-title">
|
||||
<a role="button" href="#collapseParticipant_{{ participant.id }}" data-toggle="collapse" data-parent="#accordion"
|
||||
aria-expanded="true" aria-controls="collapseParticipant_{{ participant.id }}">
|
||||
<span class="caret"></span> {{ participant.position }}. {{ participant.get_full_name }}
|
||||
<a role="button" href="#collapseParticipant_{{ participant_id }}"
|
||||
data-toggle="collapse" data-parent="#accordion"
|
||||
aria-expanded="true" aria-controls="collapseParticipant_{{ participant_id }}">
|
||||
<span class="caret"></span>
|
||||
{{ position }}. {{ form.instance.get_full_name }}
|
||||
</a>
|
||||
<div class="pull-right">
|
||||
<form action="" method="post" class="form-inline">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="id" value="{{ participant_id }}">
|
||||
<button name="action" value="moveup_participant"
|
||||
title="{% trans 'Nach oben verschieben' %}"
|
||||
class="btn btn-link no-padding {% if forloop.first %}invisible{% endif %}">
|
||||
<span class="text-info">{% bootstrap_icon 'triangle-top' %}</span>
|
||||
</button>
|
||||
<button name="action" value="movedown_participant"
|
||||
title="{% trans 'Nach unten verschieben' %}"
|
||||
class="btn btn-link no-padding {% if forloop.last %}invisible{% endif %}">
|
||||
<span class="text-info">{% bootstrap_icon 'triangle-bottom' %}</span>
|
||||
</button>
|
||||
<button name="action" value="remove_participant"
|
||||
title="{% trans 'Teilnehmer löschen' %}"
|
||||
class="btn btn-link no-padding">
|
||||
<span class="text-danger">{% bootstrap_icon 'remove-circle' %}</span>
|
||||
</button>
|
||||
|
||||
{% if form.instance.paid %}
|
||||
<span class="text-success" title="Geldeingang bestätigt">
|
||||
{% bootstrap_icon 'piggy-bank' %}
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="text-danger" title="Geldeingang unbestätigt">
|
||||
{% bootstrap_icon 'piggy-bank' %}
|
||||
</span>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
</h5>
|
||||
</div>
|
||||
<div id="collapseParticipant_{{ participant.id }}" class="panel-collapse collapse"
|
||||
role="tabpanel" aria-labelledby="headingParticipant_{{ participant.id }}">
|
||||
<div id="collapseParticipant_{{ participant_id }}"
|
||||
class="panel-collapse collapse {% if form.errors %}in{% endif %}"
|
||||
role="tabpanel" aria-labelledby="headingParticipant_{{ participant_id }}">
|
||||
<div class="panel-body">
|
||||
Hier tauchen dann die Teilnehmerdaten auf
|
||||
{% bootstrap_form_errors form %}
|
||||
<form action="" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="form_prefix" value="{{ form.prefix }}">
|
||||
<input type="hidden" name="{{ form.prefix }}-id" value="{{ participant_id }}">
|
||||
{% include './includes/participant_form.html' %}
|
||||
<button type="submit" name="action" value="update_participant" class="btn btn-success">
|
||||
{% bootstrap_icon 'hdd' %} {% trans 'Speichern' %}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
{% load bootstrap3 %}
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.personal_names %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.family_names %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% bootstrap_field form.address %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-4">
|
||||
{% bootstrap_field form.postal_code %}
|
||||
</div>
|
||||
<div class="col-sm-8">
|
||||
{% bootstrap_field form.city %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.email_address %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.phone_number %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.dav_number %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.emergency_contact %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.experience %}
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
{% bootstrap_field form.note %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -7,6 +7,7 @@ from django.contrib.auth import login
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.exceptions import PermissionDenied, SuspiciousOperation, FieldDoesNotExist
|
||||
from django.db.models import Q
|
||||
from django.forms import modelformset_factory
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse, reverse_lazy
|
||||
@@ -169,22 +170,39 @@ class EventRegistrationsView(EventPermissionMixin, generic.DetailView):
|
||||
self.enforce_permission(obj)
|
||||
return obj
|
||||
|
||||
def get_form_kwargs(self):
|
||||
def get_form_kwargs(self, process_request=True):
|
||||
kwargs = {}
|
||||
if self.request.method in ('POST', 'PUT'):
|
||||
if process_request and self.request.method in ('POST', 'PUT'):
|
||||
kwargs.update({
|
||||
'data': self.request.POST,
|
||||
'files': self.request.FILES,
|
||||
})
|
||||
if 'form_prefix' in self.request.POST:
|
||||
form_prefix = self.request.POST.get('form_prefix')
|
||||
kwargs['prefix'] = form_prefix
|
||||
pk_field = form_prefix + '-id'
|
||||
else:
|
||||
pk_field = 'id'
|
||||
if pk_field in self.request.POST:
|
||||
pk = self.request.POST.get(pk_field)
|
||||
event = self.object
|
||||
kwargs['instance'] = event.participants.get(pk=pk)
|
||||
return kwargs
|
||||
|
||||
def get_create_participant_form(self):
|
||||
event = self.get_object()
|
||||
form = forms.participant.ParticipantForm(**self.get_form_kwargs())
|
||||
def get_participant_form(self, process_request=True):
|
||||
event = self.object
|
||||
form = forms.participant.ParticipantForm(**self.get_form_kwargs(process_request=process_request))
|
||||
form.instance.event = event
|
||||
form.instance.position = event.participants.count() + 1
|
||||
if not form.instance.position:
|
||||
form.instance.position = event.participants.count() + 1
|
||||
return form
|
||||
|
||||
def get_participant_formset(self):
|
||||
event = self.object
|
||||
ParticipantFormSet = modelformset_factory(models.Participant, form=forms.participant.ParticipantForm, extra=0)
|
||||
formset = ParticipantFormSet(queryset=event.participants.all())
|
||||
return formset
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventRegistrationsView, self).get_context_data(**kwargs)
|
||||
event = context.get('event')
|
||||
@@ -194,12 +212,20 @@ class EventRegistrationsView(EventPermissionMixin, generic.DetailView):
|
||||
|
||||
participants = event.participants.all()
|
||||
context['participants'] = participants
|
||||
if hasattr(event, 'registrations'):
|
||||
|
||||
if 'participant_formset' not in context:
|
||||
context['participant_formset'] = self.get_participant_formset()
|
||||
|
||||
if 'create_participant_form' not in context:
|
||||
context['create_participant_form'] = self.get_participant_form(process_request=False)
|
||||
|
||||
registrations_support = hasattr(event, 'registrations')
|
||||
context['registrations_support'] = registrations_support
|
||||
if registrations_support:
|
||||
# registrations = event.registrations.filter(answered=False)
|
||||
registrations = event.registrations.all()
|
||||
context['registrations'] = registrations
|
||||
if 'create_participant_form' not in context:
|
||||
context['create_participant_form'] = self.get_create_participant_form()
|
||||
|
||||
return context
|
||||
|
||||
def _notify_publisher(self, event, editor):
|
||||
@@ -259,6 +285,18 @@ class EventRegistrationsView(EventPermissionMixin, generic.DetailView):
|
||||
registration.answered = True
|
||||
registration.save()
|
||||
|
||||
def _swap_participants_position(self, participant1, participant2):
|
||||
event = participant1.event
|
||||
pos_tmp = event.participants.count() + 1
|
||||
pos1 = participant1.position
|
||||
pos2 = participant2.position
|
||||
participant1.position = pos_tmp
|
||||
participant1.save()
|
||||
participant2.position = pos1
|
||||
participant2.save()
|
||||
participant1.position = pos2
|
||||
participant1.save()
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
event = self.get_object()
|
||||
self.object = event
|
||||
@@ -284,15 +322,62 @@ class EventRegistrationsView(EventPermissionMixin, generic.DetailView):
|
||||
self._reject_registration(registration)
|
||||
else:
|
||||
raise FieldDoesNotExist('Event has no registrations')
|
||||
else:
|
||||
form = self.get_create_participant_form()
|
||||
elif action == 'remove_participant':
|
||||
participant_id = request.POST.get('id')
|
||||
participant = event.participants.get(id=participant_id)
|
||||
full_name = participant.get_full_name()
|
||||
position = participant.position
|
||||
participant.delete()
|
||||
qs = event.participants.filter(position__gt=position)
|
||||
for participant in qs:
|
||||
participant.position -= 1
|
||||
participant.save()
|
||||
messages.success(request, _(u'Teilnehmer gelöscht: {}'.format(full_name)))
|
||||
elif action == 'moveup_participant':
|
||||
participant_id = request.POST.get('id')
|
||||
participant = event.participants.get(id=participant_id)
|
||||
current_position = participant.position
|
||||
if current_position > 1:
|
||||
upper_position = current_position - 1
|
||||
upper_participant = event.participants.get(position=upper_position)
|
||||
self._swap_participants_position(participant, upper_participant)
|
||||
else:
|
||||
messages.error(request, 'Participant is already on first position')
|
||||
elif action == 'movedown_participant':
|
||||
participant_id = request.POST.get('id')
|
||||
participant = event.participants.get(id=participant_id)
|
||||
current_position = participant.position
|
||||
if current_position < event.participants.count():
|
||||
lower_position = current_position + 1
|
||||
lower_participant = event.participants.get(position=lower_position)
|
||||
self._swap_participants_position(participant, lower_participant)
|
||||
else:
|
||||
messages.error(request, 'Participant is already on last position')
|
||||
elif action == 'update_participant':
|
||||
form = self.get_participant_form()
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
participant = form.instance
|
||||
messages.success(request, _(u'Teilnehmer aktualisiert: {}'.format(participant.get_full_name())))
|
||||
else:
|
||||
formset = self.get_participant_formset()
|
||||
for i in range(0, len(formset)):
|
||||
orig_form = formset.forms[i]
|
||||
if orig_form.prefix == form.prefix:
|
||||
formset.forms[i] = form
|
||||
messages.error(request, _(u'Ungültige Eingabe - Siehe unten'))
|
||||
return self.render_to_response(self.get_context_data(participant_formset=formset))
|
||||
elif action == 'create_participant':
|
||||
form = self.get_participant_form()
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
participant = form.instance
|
||||
messages.success(request, _(u'Teilnehmer hinzugefügt: {}'.format(participant.get_full_name())))
|
||||
else:
|
||||
messages.error(request, _(u'irgendwas ging schief.'))
|
||||
messages.error(request, _(u'Ungültige Eingabe - Siehe unten'))
|
||||
return self.render_to_response(self.get_context_data(create_participant_form=form))
|
||||
else:
|
||||
messages.error(request, 'unsupported action: {}'.format(action))
|
||||
return HttpResponseRedirect(reverse('dav_events:registrations', kwargs={'pk': event.pk}))
|
||||
|
||||
@method_decorator(login_required)
|
||||
|
||||
@@ -9,10 +9,10 @@ from django.utils import timezone
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from dav_base.validators import DAVNumberValidator
|
||||
from dav_events.models.event import Event
|
||||
|
||||
from . import signals
|
||||
from .validators import DAVNumberValidator
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user