Exemplo n.º 1
0
    def find_story_by_id(self, story_id: str, raise_exception: bool = False):
        condition = Q(id=story_id)

        story = super(UserStoryManager,
                      self).get_queryset().filter(condition).first()
        if not story and raise_exception:
            raise UcDomainException(f"Can't find story with id: {story_id}")

        return story
Exemplo n.º 2
0
    def find_post_by_id(self, post_id: str, raise_exception: bool = False):
        condition = Q(id=post_id)

        post = super(PostManager,
                     self).get_queryset().filter(condition).first()
        if not post and raise_exception:
            raise UcDomainException(f"Can't find post with id: {post_id}")

        return post
Exemplo n.º 3
0
    def find_account_by_id(self,
                           account_id: str,
                           raise_exception: bool = False):
        condition = Q(id=account_id)

        account = super(AccountManager,
                        self).get_queryset().filter(condition).first()
        if not account and raise_exception:
            raise UcDomainException(
                f"Can't find account with id: {account_id}")
        return account
Exemplo n.º 4
0
    def find_account_by_username(self,
                                 username: str,
                                 raise_exception: bool = False):
        condition = Q(username=username)

        account = super(AccountManager,
                        self).get_queryset().filter(condition).first()

        if not account and raise_exception:
            raise UcDomainException(f"Username {username} not found.")

        return account
    def find_comment_by_id(self,
                           comment_id: str,
                           raise_exception: bool = False):
        condition = Q(id=comment_id)

        comment = (super(UserCommentPostManager,
                         self).get_queryset().filter(condition).first())

        if not comment and raise_exception:
            raise UcDomainException(
                f"Can't find comment with id: {comment_id}")

        return comment
    def find_by_account_and_comment(self,
                                    account,
                                    comment,
                                    raise_exception: bool = False):
        condition = Q(sender=account, comment=comment)

        user_react_comment = (super(
            UserReactCommentManager,
            self).get_queryset().filter(condition).first())

        if not user_react_comment and raise_exception:
            raise UcDomainException(f"Can't find user react comment.")

        return user_react_comment
 def save(self, *args, **kwargs) -> None:
     if self.target_id == self.source_id:
         raise UcDomainException("Invalid data.")
     return super().save(*args, **kwargs)
 def save(self, *args, **kwargs) -> None:
     if not (self.media_url or self.content):
         raise UcDomainException("Invalid data")
     return super().save(*args, **kwargs)