예제 #1
0
파일: vote.py 프로젝트: matoous/newz
    def apply(self):
        # find previous vote
        previous_vote = (
            CommentVote.where("user_id", self.user_id)
            .where("comment_id", self.comment_id)
            .first()
        )

        # nothing to change, shouldn't happen
        if previous_vote and previous_vote.vote_type == self.vote_type:
            return

        # undo previous vote
        if previous_vote and previous_vote.affected_attribute:
            previous_vote.del_from_cache()
            self.comment.decr(previous_vote.affected_attribute, 1)

        # apply new vote
        if self.affected_attribute:
            self.write_to_cache()
            self.comment.incr(self.affected_attribute, 1)

        # safe new vote
        if previous_vote is None:
            self.save()
        else:
            CommentVote.where("user_id", self.user_id).where(
                "comment_id", self.comment_id
            ).update({"vote_type": self.vote_type})

        # update comment if needed
        if self.comment.num_votes < 20 or self.comment.num_votes % 8 == 0:
            q.enqueue(update_comment, self.comment, result_ttl=0)
예제 #2
0
파일: vote.py 프로젝트: matoous/newz
    def apply(self):
        previous_vote = (
            LinkVote.where("user_id", self.user_id)
            .where("link_id", self.link_id)
            .first()
        )

        if previous_vote and previous_vote.vote_type == self.vote_type:
            return

        if previous_vote and previous_vote.affected_attribute:
            previous_vote.del_from_cache()
            self.link.decr(previous_vote.affected_attribute, 1)

        if self.affected_attribute:
            self.link.incr(self.affected_attribute, 1)
            self.write_to_cache()

        if previous_vote is None:
            self.save()
        else:
            LinkVote.where("user_id", self.user_id).where(
                "link_id", self.link_id
            ).update({"vote_type": self.vote_type})

        if self.link.num_votes < 20 or self.link.num_votes % 8 == 0:
            q.enqueue(JOB_update_link, self.link, result_ttl=0)
예제 #3
0
파일: comment.py 프로젝트: matoous/newz
 def commit(self):
     """
     Creates new comment and handles all tasks resulting from this action
     """
     self.save()
     self.ups = self.downs = 0
     q.enqueue(add_new_comment, self.link.id, self, result_ttl=0)
예제 #4
0
파일: user.py 프로젝트: jannishuebl/newz
    def create(self):
        """
        Creates email verification which expires after given time
        and sends email to user to verify his email
        """

        # create token
        self.token = token_urlsafe(16)

        # save token to redis for limited time
        cache.set(self._cache_key, self.user.id, ttl=PASSWORD_RESET_EXPIRE, raw=True)

        # send email with verification link
        msg = reset_email(self.user, self._url)
        q.enqueue(JOB_send_mail, msg, result_ttl=0)
예제 #5
0
파일: admin.py 프로젝트: matoous/newz
def trigger_fqs_update():
    q.enqueue(JOB_import_feed_fqs, result_ttl=0)
    return redirect("/admin")
예제 #6
0
 def commit(self):
     self.save()
     q.enqueue(JOB_add_to_queries, self, result_ttl=0)
예제 #7
0
파일: feed.py 프로젝트: matoous/newz
 def commit(self):
     self.save()
     q.enqueue(handle_new_feed, self, result_ttl=0)