Clean up models

removes unused function and sorts replies correctly
This commit is contained in:
Mouse Reeve 2020-12-13 11:15:42 -08:00
parent d65657882e
commit 957f0889aa
2 changed files with 6 additions and 8 deletions

View file

@ -25,8 +25,3 @@ from .site import SiteSettings, SiteInvite, PasswordReset
cls_members = inspect.getmembers(sys.modules[__name__], inspect.isclass)
activity_models = {c[1].activity_serializer.__name__: c[1] \
for c in cls_members if hasattr(c[1], 'activity_serializer')}
def to_activity(activity_json):
''' link up models and activities '''
activity_type = activity_json.get('type')
return activity_models[activity_type].to_activity(activity_json)

View file

@ -24,7 +24,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
choices=PrivacyLevels.choices
)
sensitive = fields.BooleanField(default=False)
# the created date can't be this, because of receiving federated posts
# created date is different than publish date because of federated posts
published_date = fields.DateTimeField(
default=timezone.now, activitypub_field='published')
deleted = models.BooleanField(default=False)
@ -53,7 +53,9 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
def replies(cls, status):
''' load all replies to a status. idk if there's a better way
to write this so it's just a property '''
return cls.objects.filter(reply_parent=status).select_subclasses()
return cls.objects.filter(
reply_parent=status
).select_subclasses().order_by('published_date')
@property
def status_type(self):
@ -68,7 +70,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
**kwargs
)
def to_activity(self, pure=False):
def to_activity(self, pure=False):# pylint: disable=arguments-differ
''' return tombstone if the status is deleted '''
if self.deleted:
return activitypub.Tombstone(
@ -190,6 +192,7 @@ class Review(Status):
def pure_name(self):
''' clarify review names for mastodon serialization '''
if self.rating:
#pylint: disable=bad-string-format-type
return 'Review of "%s" (%d stars): %s' % (
self.book.title,
self.rating,