From 7624c3d69b026e19e1fa6bfaf0ed7dd88efd1e9c Mon Sep 17 00:00:00 2001 From: heinzel Date: Thu, 3 Dec 2020 15:50:47 +0100 Subject: [PATCH] Added restore from trash feature --- .../dav_event_office/event_detail.html | 19 +++-- .../dav_events/event_registrations.html | 81 +++++++++++++------ dav_events/views/events.py | 25 ++++++ 3 files changed, 92 insertions(+), 33 deletions(-) diff --git a/dav_event_office/templates/dav_event_office/event_detail.html b/dav_event_office/templates/dav_event_office/event_detail.html index 4235d70..ede551e 100644 --- a/dav_event_office/templates/dav_event_office/event_detail.html +++ b/dav_event_office/templates/dav_event_office/event_detail.html @@ -175,13 +175,16 @@ {% with position=participant.position %}
{% bootstrap_icon 'question-sign' %}
@@ -486,12 +489,18 @@ Wichtig: das System verschickt keine Bestätigung an dich oder den neuen Teilneh {% for registration in registrations_answered %}
    @@ -509,13 +518,20 @@ Wichtig: das System verschickt keine Bestätigung an dich oder den neuen Teilneh {% bootstrap_icon 'info-sign' %} -   - - {% bootstrap_icon 'question-sign' %} - + + {% if has_permission_update_registration %} +
+
+ {% csrf_token %} + + +
+
+ {% endif %}
{% endfor %}
@@ -541,6 +557,14 @@ auf {% if registration.status.accepted %}Plus{% else %}Minus{% endif %} geklickt
{% for participant in participants_trash %}
+ +   {{ participant.get_full_name }} ({{ participant.email_address }}, @@ -562,13 +586,20 @@ auf {% if registration.status.accepted %}Plus{% else %}Minus{% endif %} geklickt {% endif %} -   - - {% bootstrap_icon 'question-sign' %} - + + {% if has_permission_update_participants %} +
+
+ {% csrf_token %} + + +
+
+ {% endif %}
{% endfor %}
diff --git a/dav_events/views/events.py b/dav_events/views/events.py index 08f41fb..b9ccdb7 100644 --- a/dav_events/views/events.py +++ b/dav_events/views/events.py @@ -299,6 +299,11 @@ class EventRegistrationsView(EventPermissionMixin, generic.DetailView): def _reject_registration(self, registration): registration.rejected() + def _reset_registration(self, registration): + registration.status.accepted = None + registration.status.answered = False + registration.status.save() + def _swap_participants_position(self, participant1, participant2): event = participant1.event pos_tmp = event.participants.count() + 1 @@ -347,6 +352,14 @@ class EventRegistrationsView(EventPermissionMixin, generic.DetailView): self._reject_registration(registration) else: raise FieldDoesNotExist('Event has no registrations') + elif action == 'untrash_registration': + self.enforce_permission(event, permission='update-registration') + if hasattr(event, 'registrations'): + registration_id = request.POST.get('registration') + registration = event.registrations.get(id=registration_id) + self._reset_registration(registration) + else: + raise FieldDoesNotExist('Event has no registrations') elif action == 'confirm_payment': self.enforce_permission(event, permission='payment') participant_id = request.POST.get('id') @@ -374,6 +387,18 @@ class EventRegistrationsView(EventPermissionMixin, generic.DetailView): participant.save() messages.success(request, _(u'Teilnehmer in den Papierkorb verschoben: {}'.format(trashed.get_full_name()))) + elif action == 'untrash_participant': + self.enforce_permission(event, permission='update-participants') + trashed_id = request.POST.get('id') + trashed = event.trashed_participants.get(id=trashed_id) + trashed.position = event.participants.count() + 1 + + data = trashed.get_data_dict() + del data['trashed_at'] + participant = models.Participant.objects.create(**data) + trashed.delete() + + messages.success(request, _(u'Teilnehmer zurückgeholt: {}'.format(participant.get_full_name()))) elif action == 'moveup_participant': self.enforce_permission(event, permission='update-participants') participant_id = request.POST.get('id')