Exemple #1
0
def clear_actors_cache( film ):
    from film20.core.film_views import MAX_ACTORS

    cache.delete_cache( cache.CACHE_FILM_ACTORS, "%s_%s_%s" % ( film.permalink, 0, MAX_ACTORS ) )
    cache.delete_cache( cache.CACHE_FILM_ACTORS, "%s_%s_%s" % ( film.permalink, MAX_ACTORS, 100 ) )

    cache.delete( cache.Key( 'film_actors', film ) )
Exemple #2
0
    def save(self, permalink=None, *args, **kwargs):
        self.updated_at = datetime.now()
        self.type = Object.TYPE_POST

        if self.permalink is None or self.permalink == '':
            self.permalink = slughifi(self.title) # FLM-164
        # case: we're publishing the article, i.e. making it publicly visible
        if self.is_public == False and self.status == Post.PUBLIC_STATUS:
            self.is_public = True
            # only update published date if this hasn't been published before
            if self.publish is None:
                self.publish = datetime.now()
#            PingbackNote(note=self).save()
        # case: we're unpublishing the article, i.e. making it invisible again
        elif self.is_public == True and self.status == Post.DRAFT_STATUS:
            self.is_public = False
        # case: we're updating an already public article
        elif self.is_public == True:
            pass
        # case: we're updating a draft article, no need to create/update activity
        else:
            pass

        # fetch from post changes: featured, published or status
        try:
            orig = Post.objects.get(id=self.pk)
            featured_note = orig.featured_note
            is_published = orig.is_published
            status = orig.status
        except:
            featured_note = None
            is_published = None
            status = None

        # if we have featured or publish post check it status changes
        status_featured_changed = False
        status_published_changed = False
        if self.featured_note:
            if self.status != status:
                status_featured_changed = True

        if self.is_published:
            if self.status != status:
                status_published_changed = True

        # invalidate cache
        if self.featured_note != featured_note or status_featured_changed:
            cache.delete_cache(CACHE_ACTIVITIES, KEY_FEATURED)
        if self.is_published != is_published or status_published_changed:
            cache.delete_cache(CACHE_ACTIVITIES, KEY_RECENT)

        super(Post, self).save(*args, **kwargs)
        self.tags = self.tag_list

        if self.status == Post.DELETED_STATUS:
            from film20.threadedcomments.models import ThreadedComment
            ThreadedComment.objects.delete_for_object(self.id)

        self.save_activity()
Exemple #3
0
    def vote(self, the_game, the_character, the_user):
        """
            Adds a single vote for the selected character in the game.
            If game is scheduled for a different day than today, it ignores
            the request.
        """

        try:
            from datetime import datetime
            today = datetime.today()
            Game.objects.get(
                id=the_game.id,
                start_date__lte=today,
                end_date__gte=today,
            )
        except Game.DoesNotExist:
            logger.debug("Game does not exisist for this contest and date.")
            return -1

        if (the_character.id == the_game.character1.id):
            the_game.character1score = the_game.character1score + 1
        elif (the_character.id == the_game.character2.id):
            the_game.character2score = the_game.character2score + 1
        else:
            logger.debug(
                "The character doesn't match any characted in the game!")
            #TODO: throw an exception
            return -2

        # if we're here it means we have found the game
        try:
            GameVote.objects.get(
                game=the_game,
                user=the_user,
            )
            logger.debug("The user have already voted for this game!")
            return -3
        except GameVote.DoesNotExist:
            # this is good
            pass

        # apply the vote
        vote = GameVote()
        vote.character = the_character
        vote.game = the_game
        vote.user = the_user
        vote.save(
        )  # this should never fail now as we check for a duplicate vote above
        logger.debug("Vote counted!")

        delete_cache(CACHE_VOTES_FOR_CHARACTER_IN_GAME,
                     "%s_%s" % (the_game.id, the_character.id))

        # if successful, it means we have voted, so now we can update the
        # vote count for given character in game as well
        the_game.save()

        return 0
Exemple #4
0
    def vote(self, the_game, the_character, the_user):
        """
            Adds a single vote for the selected character in the game.
            If game is scheduled for a different day than today, it ignores
            the request.
        """

        try:
            from datetime import datetime
            today =  datetime.today()
            Game.objects.get(
                id=the_game.id,
                start_date__lte=today,
                end_date__gte=today,
                )
        except Game.DoesNotExist:
            logger.debug("Game does not exisist for this contest and date.")
            return -1

        if(the_character.id==the_game.character1.id):
            the_game.character1score = the_game.character1score + 1
        elif (the_character.id==the_game.character2.id):
            the_game.character2score = the_game.character2score + 1
        else:
            logger.debug("The character doesn't match any characted in the game!")
            #TODO: throw an exception
            return -2

        # if we're here it means we have found the game
        try:
            GameVote.objects.get(
                game=the_game,
                user=the_user,
                )
            logger.debug("The user have already voted for this game!")
            return -3
        except GameVote.DoesNotExist:
            # this is good
            pass

        # apply the vote
        vote = GameVote()
        vote.character = the_character
        vote.game = the_game
        vote.user = the_user
        vote.save() # this should never fail now as we check for a duplicate vote above
        logger.debug("Vote counted!")

        delete_cache(CACHE_VOTES_FOR_CHARACTER_IN_GAME, "%s_%s" % (the_game.id, the_character.id))

        # if successful, it means we have voted, so now we can update the
        # vote count for given character in game as well
        the_game.save()

        return 0
Exemple #5
0
 def save(self):
     super(Item, self).save()
     logger.debug("saving item: %s" % self.id)
     delete_cache(CACHE_SHOP_ITEM_FOR_FILM, self.film.id)
Exemple #6
0
    def save(self, permalink=None, *args, **kwargs):
        self.updated_at = datetime.now()
        self.type = Object.TYPE_POST

        if self.permalink is None or self.permalink == '':
            self.permalink = slughifi(self.title)  # FLM-164
        # case: we're publishing the article, i.e. making it publicly visible
        if self.is_public == False and self.status == Post.PUBLIC_STATUS:
            self.is_public = True
            # only update published date if this hasn't been published before
            if self.publish is None:
                self.publish = datetime.now()


#            PingbackNote(note=self).save()
# case: we're unpublishing the article, i.e. making it invisible again
        elif self.is_public == True and self.status == Post.DRAFT_STATUS:
            self.is_public = False
        # case: we're updating an already public article
        elif self.is_public == True:
            pass
        # case: we're updating a draft article, no need to create/update activity
        else:
            pass

        # fetch from post changes: featured, published or status
        try:
            orig = Post.objects.get(id=self.pk)
            featured_note = orig.featured_note
            is_published = orig.is_published
            status = orig.status
        except:
            featured_note = None
            is_published = None
            status = None

        # if we have featured or publish post check it status changes
        status_featured_changed = False
        status_published_changed = False
        if self.featured_note:
            if self.status != status:
                status_featured_changed = True

        if self.is_published:
            if self.status != status:
                status_published_changed = True

        # invalidate cache
        if self.featured_note != featured_note or status_featured_changed:
            cache.delete_cache(CACHE_ACTIVITIES, KEY_FEATURED)
        if self.is_published != is_published or status_published_changed:
            cache.delete_cache(CACHE_ACTIVITIES, KEY_RECENT)

        super(Post, self).save(*args, **kwargs)
        self.tags = self.tag_list

        if self.status == Post.DELETED_STATUS:
            from film20.threadedcomments.models import ThreadedComment
            ThreadedComment.objects.delete_for_object(self.id)

        self.save_activity()