diff --git a/journal/models/common.py b/journal/models/common.py index 1be7d652..c5024f62 100644 --- a/journal/models/common.py +++ b/journal/models/common.py @@ -185,11 +185,11 @@ def get_by_url(cls, url_or_b62): @classmethod def update_by_ap_object(cls, owner, item, obj, post_id, visibility): - raise NotImplemented + raise NotImplementedError() @property def ap_object(self): - raise NotImplemented + raise NotImplementedError() def link_post_id(self, post_id: int): PiecePost.objects.get_or_create(piece=self, post_id=post_id) diff --git a/journal/models/review.py b/journal/models/review.py index 8b31f0c4..8aba26fa 100644 --- a/journal/models/review.py +++ b/journal/models/review.py @@ -1,9 +1,11 @@ import re +from datetime import datetime from functools import cached_property from django.db import models from django.utils import timezone from django.utils.translation import gettext_lazy as _ +from markdownify import markdownify as md from markdownx.models import MarkdownxField from catalog.models import Item @@ -47,6 +49,21 @@ def ap_object(self): "href": self.absolute_url, } + @classmethod + def update_by_ap_object(cls, owner, item, obj, post_id, visibility): + d = { + "title": obj["name"], + "body": md(obj["content"].strip()), + "local": False, + "remote_id": obj["id"], + "visibility": visibility, + "created_time": datetime.fromisoformat(obj["published"]), + "edited_time": datetime.fromisoformat(obj["updated"]), + } + p, _ = cls.objects.update_or_create(owner=owner, item=item, defaults=d) + p.link_post_id(post_id) + return p + @cached_property def mark(self): from .mark import Mark