Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 27, 2024
1 parent b39ec58 commit 0d651b5
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions catalog/book/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class EditionSchema(EditionInSchema, BaseSchema):


class Edition(Item):
works: models.ManyToManyField["Work", "Edition"]
category = ItemCategory.Book
url_path = "book"

Expand Down
2 changes: 2 additions & 0 deletions catalog/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .utils import DEFAULT_ITEM_COVER, item_cover_path, resource_cover_path

if TYPE_CHECKING:
from journal.models import Collection
from users.models import User


Expand Down Expand Up @@ -247,6 +248,7 @@ class ItemSchema(BaseSchema, ItemInSchema):


class Item(PolymorphicModel, SoftDeleteMixin):
collections: QuerySet["Collection"]
url_path = "item" # subclass must specify this
type = None # subclass must specify this
child_class = None # subclass may specify this to allow link to parent item
Expand Down
1 change: 1 addition & 0 deletions catalog/podcast/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class PodcastSchema(PodcastInSchema, BaseSchema):


class Podcast(Item):
episodes: models.QuerySet["PodcastEpisode"]
category = ItemCategory.Podcast
child_class = "PodcastEpisode"
url_path = "podcast"
Expand Down
2 changes: 1 addition & 1 deletion catalog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def retrieve(request, item_path, item_uuid):


def episode_data(request, item_uuid):
item = get_object_or_404(Item, uid=get_uuid_or_404(item_uuid))
item = get_object_or_404(Podcast, uid=get_uuid_or_404(item_uuid))
qs = item.episodes.all().order_by("-pub_date")
if request.GET.get("last"):
qs = qs.filter(pub_date__lt=request.GET.get("last"))
Expand Down
1 change: 1 addition & 0 deletions journal/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def ap_object(self):


class Collection(List):
members: models.QuerySet[CollectionMember]
url_path = "collection"
MEMBER_CLASS = CollectionMember
catalog_item = models.OneToOneField(
Expand Down
3 changes: 3 additions & 0 deletions journal/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
if TYPE_CHECKING:
from takahe.models import Post

from .like import Like


class VisibilityType(models.IntegerChoices):
Public = 0, _("Public")
Expand Down Expand Up @@ -112,6 +114,7 @@ def q_item_in_category(item_category: ItemCategory):


class Piece(PolymorphicModel, UserOwnedObjectMixin):
likes: models.QuerySet["Like"]
url_path = "p" # subclass must specify this
uid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True)
local = models.BooleanField(default=True)
Expand Down
4 changes: 3 additions & 1 deletion journal/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class UserOwnedObjectMixin:
"""

if TYPE_CHECKING:
owner: ForeignKey[APIdentity, Piece]
owner: ForeignKey[Piece, APIdentity]
# owner: ForeignKey[APIdentity, Piece]
owner_id: int
visibility: int

def is_visible_to(
Expand Down
1 change: 1 addition & 0 deletions journal/models/shelf.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ class Shelf(List):
class Meta:
unique_together = [["owner", "shelf_type"]]

members: models.QuerySet[ShelfMember]
MEMBER_CLASS = ShelfMember
items = models.ManyToManyField(Item, through="ShelfMember", related_name="+")
shelf_type = models.CharField(
Expand Down
3 changes: 2 additions & 1 deletion takahe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ def visibility_n2t(visibility: int, post_public_mode: int) -> Visibilities:
@staticmethod
def post_collection(collection: "Collection"):
existing_post = collection.latest_post
user = collection.owner.user
owner: APIdentity = collection.owner
user = owner.user
if not user:
raise ValueError(f"Cannot find user for collection {collection}")
visibility = Takahe.visibility_n2t(
Expand Down

0 comments on commit 0d651b5

Please sign in to comment.