Navigation: fix for missing events

Now that we have eviction, events may disappear. Deal with it:

* event-specific 404 that still allows for navigation
* first/last buttons
* navigation to prev/next when prev/next is not just 1 step away
* don't use HttpRedirect for "lookup based" views
    in principle, the thing you were looking for might go missing in-between
    drawback: these URLs are not "stable"
This commit is contained in:
Klaas van Schelven
2024-07-19 11:03:08 +02:00
parent aec78f6318
commit b76e474ef1
6 changed files with 180 additions and 34 deletions

View File

@@ -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]