2021-03-08 16:49:10 +00:00
|
|
|
""" note serializer and children thereof """
|
2020-09-17 20:02:52 +00:00
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from typing import Dict, List
|
2021-02-16 17:35:00 +00:00
|
|
|
from django.apps import apps
|
2020-09-17 20:02:52 +00:00
|
|
|
|
2020-11-28 01:58:21 +00:00
|
|
|
from .base_activity import ActivityObject, Link
|
|
|
|
from .image import Image
|
2020-09-17 20:02:52 +00:00
|
|
|
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2020-10-08 19:32:45 +00:00
|
|
|
@dataclass(init=False)
|
|
|
|
class Tombstone(ActivityObject):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" the placeholder for a deleted status """
|
|
|
|
|
|
|
|
type: str = "Tombstone"
|
2020-10-08 19:32:45 +00:00
|
|
|
|
2021-03-08 17:54:02 +00:00
|
|
|
def to_model(self, *args, **kwargs): # pylint: disable=unused-argument
|
|
|
|
""" this should never really get serialized, just searched for """
|
|
|
|
model = apps.get_model("bookwyrm.Status")
|
2021-02-16 17:35:00 +00:00
|
|
|
return model.find_existing_by_remote_id(self.id)
|
|
|
|
|
2020-10-08 19:32:45 +00:00
|
|
|
|
2020-09-17 20:02:52 +00:00
|
|
|
@dataclass(init=False)
|
|
|
|
class Note(ActivityObject):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" Note activity """
|
|
|
|
|
2020-09-17 20:02:52 +00:00
|
|
|
published: str
|
|
|
|
attributedTo: str
|
2021-03-08 16:49:10 +00:00
|
|
|
content: str = ""
|
2020-11-30 22:24:31 +00:00
|
|
|
to: List[str] = field(default_factory=lambda: [])
|
|
|
|
cc: List[str] = field(default_factory=lambda: [])
|
|
|
|
replies: Dict = field(default_factory=lambda: {})
|
2021-03-08 16:49:10 +00:00
|
|
|
inReplyTo: str = ""
|
|
|
|
summary: str = ""
|
2020-11-25 18:44:49 +00:00
|
|
|
tag: List[Link] = field(default_factory=lambda: [])
|
|
|
|
attachment: List[Image] = field(default_factory=lambda: [])
|
2020-09-17 20:02:52 +00:00
|
|
|
sensitive: bool = False
|
2021-03-08 16:49:10 +00:00
|
|
|
type: str = "Note"
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass(init=False)
|
|
|
|
class Article(Note):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" what's an article except a note with more fields """
|
|
|
|
|
2020-09-17 20:02:52 +00:00
|
|
|
name: str
|
2021-03-08 16:49:10 +00:00
|
|
|
type: str = "Article"
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
|
2020-09-29 00:26:15 +00:00
|
|
|
@dataclass(init=False)
|
|
|
|
class GeneratedNote(Note):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" just a re-typed note """
|
|
|
|
|
|
|
|
type: str = "GeneratedNote"
|
2020-09-29 00:26:15 +00:00
|
|
|
|
|
|
|
|
2020-09-17 20:02:52 +00:00
|
|
|
@dataclass(init=False)
|
|
|
|
class Comment(Note):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" like a note but with a book """
|
|
|
|
|
2020-09-17 20:02:52 +00:00
|
|
|
inReplyToBook: str
|
2021-03-08 16:49:10 +00:00
|
|
|
type: str = "Comment"
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
|
2021-01-01 19:05:49 +00:00
|
|
|
@dataclass(init=False)
|
|
|
|
class Quotation(Comment):
|
2021-03-08 17:48:25 +00:00
|
|
|
""" a quote and commentary on a book """
|
|
|
|
|
2021-01-01 19:05:49 +00:00
|
|
|
quote: str
|
2021-03-08 17:48:25 +00:00
|
|
|
type: str = "Quotation"
|
2021-01-01 19:05:49 +00:00
|
|
|
|
|
|
|
|
2020-09-17 20:02:52 +00:00
|
|
|
@dataclass(init=False)
|
|
|
|
class Review(Comment):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" a full book review """
|
|
|
|
|
2020-12-17 21:21:21 +00:00
|
|
|
name: str = None
|
2020-12-17 04:10:50 +00:00
|
|
|
rating: int = None
|
2021-03-08 16:49:10 +00:00
|
|
|
type: str = "Review"
|
2020-09-17 20:02:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass(init=False)
|
2021-01-01 19:05:49 +00:00
|
|
|
class Rating(Comment):
|
2021-03-08 17:48:25 +00:00
|
|
|
""" just a star rating """
|
2021-03-08 16:49:10 +00:00
|
|
|
|
2021-02-25 18:17:24 +00:00
|
|
|
rating: int
|
2021-01-01 19:05:49 +00:00
|
|
|
content: str = None
|
2021-03-08 17:48:25 +00:00
|
|
|
type: str = "Rating"
|