minor code and doc fix

This commit is contained in:
Your Name 2023-08-29 06:00:02 +00:00 committed by Henri Dickson
parent c09e73e624
commit d6a84fb59a
4 changed files with 14 additions and 8 deletions

View file

@ -21,6 +21,13 @@ $ pre-commit install
pre-commit installed at .git/hooks/pre-commit
```
Make sure code in submodule is updated
```
git submodule update --init
```
then install requirements and pre-commit hook for `neodb-takahe` project (using a different venv is preferred)
Run Test
--------
`python3 manage.py test` will run the tests

View file

@ -152,8 +152,10 @@ class Piece(PolymorphicModel, UserOwnedObjectMixin):
else 0
)
def is_liked_by(self, user):
return self.latest_post and Takahe.post_liked_by(self.latest_post.pk, user)
def is_liked_by(self, identity):
return self.latest_post and Takahe.post_liked_by(
self.latest_post.pk, identity.pk
)
@property
def reply_count(self):

View file

@ -34,12 +34,7 @@ def like_piece_action(context, piece):
@register.simple_tag(takes_context=True)
def liked_piece(context, piece):
user = context["request"].user
return (
user
and user.is_authenticated
and piece.post_id
and Takahe.get_user_interaction(piece.post_id, user.identity.pk, "like")
)
return user and user.is_authenticated and piece.is_liked_by(user.identity)
@register.simple_tag(takes_context=True)

View file

@ -501,6 +501,8 @@ class Takahe:
@staticmethod
def get_user_interaction(post_pk: int, identity_pk: int, type: str):
if not post_pk or not identity_pk:
return None
post = Post.objects.filter(pk=post_pk).first()
if not post:
logger.warning(f"Cannot find post {post_pk}")