예제 #1
0
파일: models.py 프로젝트: thuvh/filmmaster
    def save_activity(self, status=None, *args, **kwargs):
        """
            Creates or updates an activity related to this article
        """
        from film20.useractivity.models import UserActivity
        act = None
        # Checking if activity already exists for the given article, 
        # if so update activity
        try:
            act = UserActivity.objects.get(post = self, user = self.user)
        # otherwise, create a new one
        except UserActivity.DoesNotExist:
            act = UserActivity()
            act.user = self.user
            act.activity_type = UserActivity.TYPE_POST
            act.post = self

        act.title = self.get_title()

        if self.lead:
            act.content = self.lead
        else:
            act.content = self.body

        rf = self.related_film.all()
        # special case: one film related with article - article is a review
        if len(rf) == 1:
            act.film_title = rf[0].get_title()
            act.film = rf[0]
            act.film_permalink = rf[0].permalink
        else:
            act.film = None
            act.film_title = None
            act.film_permalink = None
        act.username = self.user.username
        act.spoilers = self.spoilers
        act.status = self.status
        act.permalink = self.get_absolute_url() # legacy
        act.number_of_comments = self.number_of_comments
        if self.featured_note or self.is_published:
            act.featured = True
        else:
            act.featured = False

        if self.publish is not None:
            act.created_at = self.publish
        act.save()
예제 #2
0
    def save_activity(self, status=None, *args, **kwargs):
        """
            Creates or updates an activity related to this article
        """
        from film20.useractivity.models import UserActivity
        act = None
        # Checking if activity already exists for the given article,
        # if so update activity
        try:
            act = UserActivity.objects.get(post=self, user=self.user)
        # otherwise, create a new one
        except UserActivity.DoesNotExist:
            act = UserActivity()
            act.user = self.user
            act.activity_type = UserActivity.TYPE_POST
            act.post = self

        act.title = self.get_title()

        if self.lead:
            act.content = self.lead
        else:
            act.content = self.body

        rf = self.related_film.all()
        # special case: one film related with article - article is a review
        if len(rf) == 1:
            act.film_title = rf[0].get_title()
            act.film = rf[0]
            act.film_permalink = rf[0].permalink
        else:
            act.film = None
            act.film_title = None
            act.film_permalink = None
        act.username = self.user.username
        act.spoilers = self.spoilers
        act.status = self.status
        act.permalink = self.get_absolute_url()  # legacy
        if self.featured_note or self.is_published:
            act.featured = True
        else:
            act.featured = False

        if self.publish is not None:
            act.created_at = self.publish
        act.save()