Commits

Luke Plant committed 7abdf7c Merge

Merged from default

Comments (0)

Files changed (3)

cciw/officers/models.py

 # -*- coding: utf-8 -*-
+from datetime import datetime
+import re
+
 from django.conf import settings
 from django.contrib.auth.models import User
 from django.db import models
         except ReferenceForm.DoesNotExist:
             return None
 
+    log_datetime_format = "%Y-%m-%d %H:%M:%S"
+
+    @property
+    def last_requested(self):
+        """
+        Returns the last date the reference was requested,
+        or None if it is not known.
+        """
+        # Parse the comments field:
+        dt = None
+        for l in self.comments.split("\n"):
+            m = re.match("Reference requested by .* on (\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})", l)
+            if m is not None:
+                dt = datetime.strptime(m.groups()[0], self.log_datetime_format)
+        return dt
+
+    def log_request_made(self, user, date):
+        self.comments = self.comments + \
+            ("\nReference requested by user %s via online system on %s\n" % \
+                 (user.username, date.strftime(self.log_datetime_format)))
+
     class Meta:
         verbose_name = "Reference Metadata"
         verbose_name_plural = verbose_name

cciw/officers/views.py

                 except smtplib.SMTPException:
                     return email_sending_failed_response()
                 ref.requested = True
-                ref.comments = ref.comments + \
-                    ("\nReference requested by user %s via online system on %s\n" % \
-                         (request.user.username, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
+                ref.log_request_made(request.user, datetime.datetime.now())
                 ref.save()
                 return close_window_response()
         elif 'setemail' in request.POST:

templates/cciw/officers/manage_reference.html

 {% else %}
 {% if ref.requested %}
 <div class="ok"><strong>Requested</strong></div>
+  {% if ref.last_requested %}
+  <div>Last requested: <b> {{ ref.last_requested|timesince }} ago</b></div>
+  {% endif %}
 {% else %}
 <div><strong>Not requested</strong></div>
 {% endif %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.