コード例 #1
0
ファイル: contents.py プロジェクト: damnever/2L
    def get(self, topic_id):
        topic = yield gen.maybe_future(Topic.get(topic_id))
        if not topic:
            raise HTTPError(404)
        user = yield gen.maybe_future(User.get(topic.admin_id))
        up_votes = yield gen.maybe_future(TopicUpVote.count_by_topic(topic_id))
        down_votes = yield gen.maybe_future(
            TopicDownVote.count_by_topic(topic_id))

        up_voted, down_voted = False, False
        username = self.current_user
        if username is not None:
            up_voted = bool((yield gen.maybe_future(
                TopicUpVote.get_by_user_topic(username, topic_id))))
            down_voted = bool((yield gen.maybe_future(
                TopicDownVote.get_by_user_topic(username, topic_id))))
        self.render(
            'proposal.html',
            title=topic.name,
            keywords=topic.name + ', 2L',
            description=topic.description,
            id=topic.id,
            avatar=topic.avatar,
            rules=topic.rules,
            why=topic.why,
            state=topic.state,
            date=topic.date,
            user=user.username,
            #  user_avatar=user.profile.avatar,
            up_votes=up_votes,
            down_votes=down_votes,
            up_voted=int(up_voted),
            down_voted=int(down_voted),
        )
コード例 #2
0
ファイル: tasks.py プロジェクト: damnever/2L
def check_proposal(topic_id):
    from app.libs.db import db_session
    from app.models import Topic, User, TopicUpVote, TopicDownVote
    from app.settings import Gold

    user_count = User.count()
    topic = Topic.get(topic_id)
    user = User.get(topic.admin_id)
    up_votes = TopicUpVote.count_by_topic(topic_id)
    down_votes = TopicDownVote.count_by_topic(topic_id)

    # Check if the proposal can be accepted or rejected.
    if (up_votes - down_votes) > (user_count / 2):
        topic.state = 1
        user.profile.gold += Gold['proposal_accepted']
    else:
        topic.state = -1
        user.profile.gold += Gold['proposal_rejected']

    db_session.add(user)
    db_session.add(topic)
    db_session.commit()