Collections: use the member stokens for filtering based on stoken

While at it, also generalised the stoken handling to be generic and
extendible.
This commit is contained in:
Tom Hacohen
2020-05-27 12:13:54 +03:00
parent 1f18f4e50b
commit d93a5d3f06
2 changed files with 21 additions and 17 deletions

View File

@@ -17,6 +17,7 @@ from pathlib import Path
from django.db import models
from django.conf import settings
from django.core.validators import RegexValidator
from django.db.models import Q
from django.utils.functional import cached_property
from django.utils.crypto import get_random_string
@@ -51,12 +52,14 @@ class Collection(models.Model):
@cached_property
def stoken(self):
last_revision = CollectionItemRevision.objects.filter(item__collection=self).last()
if last_revision is None:
# FIXME: what is the etag for None? Though if we use the revision for collection it should be shared anyway.
return None
stoken = Stoken.objects.filter(
Q(collectionitemrevision__item__collection=self) | Q(collectionmember__collection=self)
).order_by('id').last()
return last_revision.stoken.uid
if stoken is None:
raise Exception('stoken is None. Should never happen')
return stoken.uid
class CollectionItem(models.Model):