コード例 #1
0
ファイル: logic.py プロジェクト: Apkawa/nyasha
    def send_personal_messgae(self, username, message):
        from models import BlackList
        from views import send_alert, render_to_string
        message = message.strip()
        if not message:
            raise BlogInterfaceError("Empty message.")

        user = UserInterface(self.user).get_user(username=username)

        if username == self.user.username:
            raise BlogInterfaceError("No send to self")

        if BlackList.objects.filter(
                user=user, blacklisted_user=self.user).exists():
            raise BlogInterfaceError(
                    "Sorry, you can't send private message to this user")

        context = {}
        context['from_user'] = self.user
        context['user'] = user
        context['message'] = message
        #TODO: add pm like psto
        personal_message = render_to_string(
                'jabber/personal_message.txt', context)
        send_alert(user, personal_message)
コード例 #2
0
ファイル: logic.py プロジェクト: Apkawa/nyasha
    def subscribe_toggle_command(self,
                                post_pk=None,
                                username=None,
                                tagname=None,
                                delete=False):
        '''
        S #123 - Subscribe to message replies
        S @username - Subscribe to user's blog
        S *tag - Subscribe to tag
        U #123 - Unsubscribe from comments
        U @username - Unsubscribe from user's blog
        U *tag - Unsubscribe from tag
        '''
        from blog.models import Tag, Subscribed
        from blog.views import send_alert

        user = self.user
        kw = {}
        kw['user'] = user
        if post_pk:
            post = PostInterface(self.user).get_post(post_id=post_pk)
            kw['subscribed_post'] = post

        if username:
            s_user = UserInterface(self.user).get_user(username=username)
            kw['subscribed_user'] = s_user
            if user.pk == s_user:
                raise BlogInterfaceError("Not subscribe on self")

        if tagname:
            #TODO: use TagInterface
            try:
                tag = Tag.objects.get(name=tagname)
                kw['subscribed_tag'] = tag
            except Tag.DoesNotExist:
                raise BlogInterfaceError("Tag not found.")

        print kw
        if not delete:
            subscribe, created = Subscribed.admin_objects.get_or_create(**kw)
            if not created and not subscribe.is_deleted:
                raise BlogInterfaceError('Already subscribed.')
            else:
                if subscribe.is_deleted:
                    subscribe.is_deleted = False
                    subscribe.save()
                if username:
                    if created:
                        send_alert(s_user,
                            "@%s subscribed to your blog!" % self.user.username)
                    return 'Subscribed to @%s!' % username
                elif post_pk:
                    return 'Subscribed (%i replies).' % post.comments.count()
                elif tagname:
                    return 'Subscribed to *%s.' % tagname
        else:
            Subscribed.objects.filter(**kw).update(is_deleted=True)
            return 'Unsubscribed!'