Skip to content

Commit

Permalink
process incoming Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Her Email committed Nov 19, 2023
1 parent d5a88b3 commit c87b199
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions journal/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions journal/models/review.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c87b199

Please sign in to comment.