Skip to content

Commit

Permalink
WIP: add collection (related to chartes#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carine Dengler committed Nov 23, 2022
1 parent 9a26947 commit 80fada2
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions app/api/collection/facade.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from app.api.abstract_facade import JSONAPIAbstractChangeloggedFacade
from app.api.user.facade import UserFacade
from app.models import Collection
Expand Down Expand Up @@ -68,6 +70,16 @@ def get_children_resources(self, rel_facade=None):

@property
def resource(self):
if not self.obj.documents_including_children:
date_min = datetime.datetime.now().strftime("%Y-%m-%d")
date_max = date_min
else:
creation = [
doc.creation for doc in self.obj.documents_including_children
if doc.creation
]
date_min = min(creation)
date_max = max(creation)

resource = {
**self.resource_identifier,
Expand All @@ -76,8 +88,8 @@ def resource(self):
"path": [c.title for c in self.obj.parents] + [self.obj.title],
"description": self.obj.description,
"nb_docs": len(self.obj.documents_including_children),
"date_min": min([doc.creation for doc in self.obj.documents_including_children if doc.creation]),
"date_max": max([doc.creation for doc in self.obj.documents_including_children if doc.creation])
"date_min": date_min,
"date_max": date_max
},
"meta": self.meta,
"links": {
Expand Down Expand Up @@ -151,3 +163,12 @@ def remove_from_index(self, propagate):
if data["payload"]["id"] != self.id and data["payload"]["type"] != self.TYPE:
data["payload"]["collections"] = [l for l in data["payload"]["collections"] if l.get("id") != self.id]
SearchIndexManager.add_to_index(index=data["index"], id=data["id"], payload=data["payload"])

@staticmethod
def create_resource(model, obj_id, attributes, related_resources):
return JSONAPIAbstractChangeloggedFacade.create_resource(
model,
obj_id,
attributes,
related_resources
)

0 comments on commit 80fada2

Please # to comment.