From 0e79282e4dee8d7ea878525415ece39ecd88f6b5 Mon Sep 17 00:00:00 2001 From: henrikskog Date: Tue, 20 Aug 2024 18:54:58 +0200 Subject: [PATCH] Dashboard tab for showing registration history --- apps/events/dashboard/views.py | 13 ++ apps/events/signals.py | 26 ++-- templates/events/dashboard/details.html | 6 + .../details/registration-history.html | 127 ++++++++++++++++++ 4 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 templates/events/dashboard/details/registration-history.html diff --git a/apps/events/dashboard/views.py b/apps/events/dashboard/views.py index 2bf9a6bf4..c8a17c063 100644 --- a/apps/events/dashboard/views.py +++ b/apps/events/dashboard/views.py @@ -1,9 +1,11 @@ +import json from collections import OrderedDict from datetime import datetime, time, timedelta from django.contrib import messages from django.contrib.auth.decorators import login_required from django.contrib.contenttypes.models import ContentType +from django.core import serializers from django.core.exceptions import PermissionDenied from django.forms.models import modelformset_factory from django.http import HttpResponse, JsonResponse @@ -29,6 +31,7 @@ Attendee, CompanyEvent, Event, + EventUserAction, Reservation, Reservee, ) @@ -324,6 +327,16 @@ def event_details(request, event_id, active_tab="details"): context["active_tab"] = active_tab context["form"] = dashboard_forms.CreateEventForm(instance=event, user=request.user) + # History of event for analytics pane + registration_history = EventUserAction.objects.filter(event=event) + print(registration_history) + context["registration_history"] = registration_history + context["registration_history_json"] = json.dumps( + serializers.serialize("json", registration_history) + ) + context["event_registration_start"] = event.attendance_event.registration_start + context["event_registration_end"] = event.attendance_event.registration_end + extras = {} if event.is_attendance_event() and event.attendance_event.extras: for extra in event.attendance_event.extras.all(): diff --git a/apps/events/signals.py b/apps/events/signals.py index f97aaae03..0d4b92163 100644 --- a/apps/events/signals.py +++ b/apps/events/signals.py @@ -1,18 +1,18 @@ -# from django.db.models.signals import post_delete, post_save -# from django.dispatch import receiver +from django.db.models.signals import post_delete, post_save +from django.dispatch import receiver -# from .models import Attendee, EventUserAction +from .models import Attendee, EventUserAction -# @receiver(signal=post_save, sender=Attendee) -# def handle_payment_relation_status_change(sender, instance: Attendee, **kwargs): -# EventUserAction.objects.create( -# user=instance.user, event=instance.event.event, type="register" -# ) +@receiver(signal=post_save, sender=Attendee) +def handle_attendee_creation(sender, instance: Attendee, **kwargs): + EventUserAction.objects.create( + user=instance.user, event=instance.event.event, type="register" + ) -# @receiver(signal=post_delete, sender=Attendee) -# def handle_payment_transaction_status_change(sender, instance: Attendee, **kwargs): -# EventUserAction.objects.create( -# user=instance.user, event=instance.event.event, type="unregister" -# ) +@receiver(signal=post_delete, sender=Attendee) +def handle_attendee_deletion(sender, instance: Attendee, **kwargs): + EventUserAction.objects.create( + user=instance.user, event=instance.event.event, type="unregister" + ) diff --git a/templates/events/dashboard/details.html b/templates/events/dashboard/details.html index a2bbfda4f..d84d3dfae 100644 --- a/templates/events/dashboard/details.html +++ b/templates/events/dashboard/details.html @@ -82,6 +82,9 @@

{{ event }}

  • Bedrifter
  • +
  • + Påmeldingshistorikk +
  • @@ -145,6 +148,9 @@

    {% include "events/dashboard/details/company.html" %}
    +
    + {% include "events/dashboard/details/registration-history.html" %} +
    {% endblock content %} diff --git a/templates/events/dashboard/details/registration-history.html b/templates/events/dashboard/details/registration-history.html new file mode 100644 index 000000000..f4b95fc4a --- /dev/null +++ b/templates/events/dashboard/details/registration-history.html @@ -0,0 +1,127 @@ +
    +
    + +
    +
    + + +{% block js %} + + +{% endblock %} + +
    +
    +
    +
    +

    Historikk

    +
    +
    +
    + + + + + + + + + + + {% for registration in registration_history reversed %} + + + + + + + {% endfor %} + +
    #TidspunktRegistrert årstall for brukerHandling
    {{ forloop.counter }}{{ registration.timestamp }}{{ registration.user.year }}{{ registration.type }}
    +
    +
    +
    +
    +
    \ No newline at end of file