Track and show the last time an email was sent for a patch
authorMagnus Hagander <magnus@hagander.net>
Sun, 18 Aug 2013 16:16:12 +0000 (18:16 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sun, 18 Aug 2013 16:16:12 +0000 (18:16 +0200)
This tracks all the emails that are sent on a patch. Note that this
currently only picks up emalis when the attach thread function is used,
since there is no cronjob that fetches this data yet. When that job
is added, it should also update this field.

pgcommitfest/commitfest/ajax.py
pgcommitfest/commitfest/models.py
pgcommitfest/commitfest/templates/commitfest.html

index 469d630f7aceed4eb8308723d2cf1bbe98869162..97d00a4a578f842223ac6180e118213e32b6e8bf 100644 (file)
@@ -106,6 +106,7 @@ def doAttachThread(cf, patch, msgid, user):
        m.save()
        parse_and_add_attachments(r, m)
        PatchHistory(patch=patch, by=user, what='Attached mail thread %s' % r[0]['msgid']).save()
+       patch.update_lastmail()
        patch.set_modified()
        patch.save()
 
@@ -119,6 +120,7 @@ def detachThread(request):
 
        thread.delete()
        PatchHistory(patch=patch, by=request.user, what='Detached mail thread %s' % request.POST['msg']).save()
+       patch.update_lastmail()
        patch.set_modified()
        patch.save()
 
index e7ac9c706edcd2b2ff073e41b5f774e1ff3e2a6d..2538e083fa630dc81d721ee1870c4e8cb5c3cd31 100644 (file)
@@ -77,6 +77,10 @@ class Patch(models.Model):
        created = models.DateTimeField(blank=False, null=False, auto_now_add=True)
        modified = models.DateTimeField(blank=False, null=False)
 
+       # Materialize the last time an email was sent on any of the threads
+       # that's attached to this message.
+       lastmail = models.DateTimeField(blank=True, null=True)
+
        # Some accessors
        @property
        def authors_string(self):
@@ -101,6 +105,15 @@ class Patch(models.Model):
                if not self.modified or newmod > self.modified:
                        self.modified = newmod
 
+       def update_lastmail(self):
+               # Update the lastmail field, based on the newest email in any of
+               # the threads attached to it.
+               threads = list(self.mailthread_set.all())
+               if len(threads) == 0:
+                       self.lastmail = None
+               else:
+                       self.lastmail = max(threads, key=lambda t:t.latestmessage).latestmessage
+
        def __unicode__(self):
                return self.name
 
index ae2f3ae1aed38c510b62034021e2d6a001623725..232dbe9842183f6c9da7d088ac15628325501b7e 100644 (file)
@@ -45,8 +45,8 @@
    <th>Status</th>
    <th>Author</th>
    <th>Reviewers</th>
-   <th>Last act</th>
-   <th>Last mail</th>
+   <th>Latest act</th>
+   <th>Latest mail</th>
   </tr>
  </thead>
  <tbody>
@@ -61,7 +61,7 @@
    <td>{{p.author_names|default:''}}</td>
    <td>{{p.reviewer_names|default:''}}</td>
    <td style="white-space: nowrap;">{{p.modified|date:"Y-m-d"}}<br/>{{p.modified|date:"H:i"}}</td>
-   <td>What?</td>
+   <td style="white-space: nowrap;">{{p.lastmail|date:"Y-m-d"}}<br/>{{p.lastmail|date:"H:i"}}</td>
   </tr>
 {%endfor%}
  </tbody>