diff --git a/events/models.py b/events/models.py index d58d1ed..1e5500d 100644 --- a/events/models.py +++ b/events/models.py @@ -4,6 +4,7 @@ import uuid from django.db import models from django.db.utils import IntegrityError +from django.db.models import Min, Max from projects.models import Project from compat.timestamp import parse_timestamp @@ -230,3 +231,15 @@ class Event(models.Model): assert re.match( r".*unique constraint failed.*events_event.*project_id.*events_event.*event_id", str(e).lower()) return None, False + + def get_digest_order_bounds(self): + if not hasattr(self, "_digest_order_bounds"): + d = Event.objects.filter(issue_id=self.issue.id).aggregate(lo=Min("digest_order"), hi=Max("digest_order")) + self._digest_order_bounds = d["lo"], d["hi"] + return self._digest_order_bounds + + def has_prev(self): + return self.digest_order > self.get_digest_order_bounds()[0] + + def has_next(self): + return self.digest_order < self.get_digest_order_bounds()[1] diff --git a/issues/templates/issues/_event_nav.html b/issues/templates/issues/_event_nav.html index 431cc7c..6d1a59b 100644 --- a/issues/templates/issues/_event_nav.html +++ b/issues/templates/issues/_event_nav.html @@ -1,5 +1,16 @@ - {% if event.digest_order > 1 %} - + {% if event.has_prev %} {# no need for 'is_first': if you can go to the left, you can go all the way to the left too #} + + + + {% else %} +