diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-21 20:54:26 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-10-21 20:54:26 +0100 |
commit | b0cb4e453f060c174c14e896767c3cb89b1d6531 (patch) | |
tree | 8c475b9819b46c7b612c5c91df868408509e05a7 | |
parent | ecd2c19b265e3974707da0d9b8e260749dcf4a9f (diff) |
bit of a hack to get notes to sort alongside objects with actual date attributes - here we add one for the sort and remove it after
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_detail.html | 2 | ||||
-rw-r--r-- | ctrack/organisations/views.py | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index fe744fe..fef5892 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -88,7 +88,7 @@ <div class="card bg-light"> <div class="card-body"> <div class="card-title" style="font-size: 1.1rem;"> - Engagements & Compliance Events + Notes & Events </div> <div class="mb-2"> <svg width="1em" height="1em" viewBox="0 0 16 16" class="bi bi-calendar-month" fill="currentColor" diff --git a/ctrack/organisations/views.py b/ctrack/organisations/views.py index 324f933..1fbefde 100644 --- a/ctrack/organisations/views.py +++ b/ctrack/organisations/views.py @@ -8,11 +8,11 @@ from django.db.models import Q from django.http import HttpResponseRedirect from django.shortcuts import get_object_or_404, render from django.urls import reverse, reverse_lazy +from django.utils import timezone from django.views.generic import CreateView, DetailView, FormView, ListView from ctrack.caf.models import CAF, EssentialService -from ctrack.register.models import EngagementEvent - +from ctrack.register.models import EngagementEvent, NoteEvent from .forms import AddressInlineFormSet, IncidentReportForm, OrganisationCreateForm from .models import IncidentReport, Organisation, Person from .utils import filter_private_events @@ -114,17 +114,22 @@ class OrganisationDetailView(PermissionRequiredMixin, DetailView): cafs = org.caf_set.all() # simple datetime events for org + # TODO - a note is not getting registered on org detail page after renamed datetime field so fix! + notes = NoteEvent.objects.filter(user=self.request.user) _sdes = [ filter_private_events( person.get_single_datetime_events(), self.request.user ) for person in peoples ] - flat_sdes = sorted( - list(itertools.chain.from_iterable(_sdes)), - key=lambda e: e.date, - reverse=True, - ) + _all = list(itertools.chain(list(itertools.chain.from_iterable(_sdes)), notes)) + for x in _all: + if isinstance(x, NoteEvent): + setattr(x, "date", timezone.now()) + flat_sdes = sorted(_all, key=lambda e: e.date, reverse=True) + for x in flat_sdes: + if isinstance(x, NoteEvent): + delattr(x, "date") # Some events will not involve a participant, which is what ties an event to an organisation. # Because we want to list events to an organisation here we must related it via the CAF object too... |