From e83a49075bf57c09579fc14b9e10637e17cd35f5 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Fri, 23 Oct 2020 14:18:42 +0100 Subject: nice tweaks to the profile page --- ctrack/templates/users/user_detail.html | 70 ++++++++++++++++++++++++++++----- ctrack/users/views.py | 12 +++++- 2 files changed, 71 insertions(+), 11 deletions(-) (limited to 'ctrack') diff --git a/ctrack/templates/users/user_detail.html b/ctrack/templates/users/user_detail.html index 5314f20..e991a25 100644 --- a/ctrack/templates/users/user_detail.html +++ b/ctrack/templates/users/user_detail.html @@ -4,20 +4,61 @@ {% block title %}User: {{ object.username }}{% endblock %} {% block content %} + + + +
-

{{ object.name }}

{% if object.name %} -

{{ object.name }}

+

{{ object.name }}

{% else %} -

Email: {{ object.email }}

+

{{ object.username }}

{% endif %}
+
+
+

Lead inspector

+
    + {% for oes in lead_oes %} +
  • + {{ oes.name }}
    + + + + + {% if oes.get_people|length > 1 %} + {{ oes.get_people.0 }} + {{ oes.get_people.0.mobile }} [...] + {% else %} + {% for person in oes.get_people %} + {{ person }} ({{ person.mobile }}) + {% endfor %} + {% endif %} + {{ oes.submode }} +
  • + {% endfor %} +
+
+
+ {#{% if object == request.user %}#} {##} {#
#} @@ -36,20 +77,29 @@

Recent Events

- +
- - - + + + + + {% for event in all_events %} - - - + + + + + {% endfor %} diff --git a/ctrack/users/views.py b/ctrack/users/views.py index de3f4d1..693318b 100644 --- a/ctrack/users/views.py +++ b/ctrack/users/views.py @@ -1,3 +1,4 @@ +import datetime import itertools from django.contrib import messages @@ -7,6 +8,7 @@ from django.urls import reverse from django.utils.translation import ugettext_lazy as _ from django.views.generic import DetailView, RedirectView, UpdateView +from ctrack.organisations.models import Organisation from ctrack.register.models import SingleDateTimeEvent, CAFSingleDateEvent, CAFTwinDateEvent User = get_user_model() @@ -23,15 +25,23 @@ class UserDetailView(DetailView): # we have to pass 'username' as the argument when testing UserDetailView because of this. slug_url_kwarg = "username" + def _comp_dates(self, event): + if isinstance(event.date, datetime.datetime): + return event.date.date() + else: + return event.date + def get_context_data(self, **kwargs): context = super().get_context_data() user = self.request.user + lead_oes = Organisation.objects.filter(lead_inspector=user).order_by("name") _single_date_events = SingleDateTimeEvent.objects.filter(user=user).all() _caf_single_date_events = CAFSingleDateEvent.objects.all() _caf_twin_date_events = CAFTwinDateEvent.objects.all() _combined = list(itertools.chain(_caf_twin_date_events, _caf_single_date_events, _single_date_events)) - all_events = sorted(_combined, key=lambda x: x.date, reverse=True) + all_events = sorted(_combined, key=self._comp_dates, reverse=True) context["all_events"] = all_events + context["lead_oes"] = lead_oes return context -- cgit v1.2.3
TypeEventCommentsTypeDateEventOrganisationComments
{{ event.type_descriptor }}{{ event.short_description }}{{ event.comments }} + {{ event.type_descriptor }} + {% if event.private %} + PRIVATE + {% endif %} + {{ event.date|date:"d M Y" }}{{ event.short_description }}{{ event.organisation }}{{ event.comments }}