示例#1
0
文件: topics.py 项目: damnever/2L
    def post(self, topic_id):
        name = self.get_argument('name', None)
        description = self.get_argument('description', None)
        rules = self.get_argument('rules', None)
        avatar = self.get_argument('avatar', None)
        why = self.get_argument('why', None)

        if not all([name, description, rules, why]):
            raise exceptions.EmptyFields()
        else:
            exists = yield gen.maybe_future(Topic.get_by_name(name))
            if exists:
                raise exceptions.TopicNameAlreadyExists()
            else:
                created_user = self.current_user
                topic = yield gen.maybe_future(
                    Topic.create(name, created_user, avatar,
                                 description, rules, why))

                # Update Gold.
                update_gold.apply_async(('new_proposal', created_user))

                # Update proposal state.
                seconds = Level['time']['proposal']
                wait = datetime.now(get_localzone()) + timedelta(seconds=seconds)
                check_proposal.apply_async((topic.id,), eta=wait)
示例#2
0
文件: posts.py 项目: damnever/2L
    def post(self, topic_id):
        title = self.get_argument('title', None)
        keywords = self.get_argument('keywords', None)
        content = self.get_argument('content', '')
        keep_silent = int(self.get_argument('keep_silent', 0))
        is_draft = int(self.get_argument('is_draft', 0))

        if not all([title, keywords]):
            raise exceptions.EmptyFields()
        else:
            can_post = yield gen.maybe_future(Topic.can_post(topic_id))
            if not can_post:
                raise exceptions.TopicIsNotAccepted
            exists = yield gen.maybe_future(Post.get_by_title(title))
            if exists:
                raise exceptions.PostTitleAlreadyExists()
            else:
                username = self.current_user
                yield gen.maybe_future(
                    Post.create(username, topic_id,
                                title, keywords, content,
                                keep_silent=keep_silent, is_draft=is_draft))

                # Update gold.
                update_gold.apply_async(('new_post', username))
示例#3
0
文件: favorite.py 项目: damnever/2L
 def delete(self, post_id):
     username = self.current_user
     f = yield gen.maybe_future(Favorite.get_by_user_post(username, post_id))
     if f:
         yield gen.maybe_future(f.delete())
         count = yield gen.maybe_future(Favorite.count_by_post(post_id))
         # Update gold.
         update_gold.apply_async(("cancel_post_be_favorite", post_id))
         raise gen.Return({"count": count})
     else:
         raise exceptions.PostHasNotBeenFavorited()
示例#4
0
文件: favorite.py 项目: damnever/2L
 def post(self, post_id):
     username = self.current_user
     f = yield gen.maybe_future(Favorite.get_by_user_post(username, post_id))
     if f:
         raise exceptions.PostAlreadyFavorited()
     else:
         yield gen.maybe_future(Favorite.create(username, post_id))
         count = yield gen.maybe_future(Favorite.count_by_post(post_id))
         # Update gold.
         update_gold.apply_async(("post_be_favorite", post_id))
         raise gen.Return({"count": count})
示例#5
0
文件: votes.py 项目: damnever/2L
    def delete(self, id_):
        if self.category == 'topic':
            t = yield gen.maybe_future(Topic.get(id_))
            if t and t.state in (-1, 1):
                raise exceptions.TopicVoteTimeHasPassed()

        username = self.current_user
        v = yield gen.maybe_future(self._get_by_user_category(username, id_))
        if v:
            yield gen.maybe_future(v.delete())
            count = yield gen.maybe_future(self._count_by_category(id_))
            # Update gold.
            update_gold.apply_async(
                ('cancel_vote', username, id_, self.category, self.vote_type))
            raise gen.Return({'count': count})
        else:
            raise exceptions.NoVoteCanBeCancel()
示例#6
0
文件: votes.py 项目: damnever/2L
    def post(self, id_):
        if self.category == 'topic':
            t = yield gen.maybe_future(Topic.get(id_))
            if t and t.state in (-1, 1):
                raise exceptions.TopicVoteTimeHasPassed()

        username = self.current_user
        v = yield gen.maybe_future(self._get_by_user_category(username, id_))
        if v:
            vote_type = self.vote_type.capitalize()
            exception = getattr(exceptions,
                                'CanNotVote{0}Again'.format(vote_type))
            raise exception()
        else:
            yield gen.maybe_future(self.table.create(username, id_))
            count = yield gen.maybe_future(self._count_by_category(id_))

            # Update gold.
            update_gold.apply_async(
                ('vote', username, id_, self.category, self.vote_type))
            raise gen.Return({'count': count})
示例#7
0
文件: comments.py 项目: damnever/2L
    def post(self, post_id):
        content = self.get_argument('content', None)

        if content is None:
            raise exceptions.EmptyFields()
        else:
            users, content = at_content(content)
            username = self.current_user
            comment = yield gen.maybe_future(
                Comment.create(username, post_id, content))

            # Update gold.
            update_gold.apply_async(('sb_2l', username, post_id))
            update_gold.apply_async(('comment', username))
            if users:
                update_gold.apply_async(('be_comment', users))

            # Notify users: be comment, someone @you.
            notify.apply_async(
                ('comment', username, post_id, content))
            if users:
                notify.apply_async(
                    ('at', username, users, post_id, content))

            raise gen.Return(comment.to_dict())
示例#8
0
文件: posts.py 项目: damnever/2L
    def delete(self, post_id):
        p = yield gen.maybe_future(Post.get(post_id))
        yield gen.maybe_future(p.delete())

        # Update gold.
        update_gold.apply_async(('delete_post', self.current_user))