コード例 #1
0
ファイル: test_widgets.py プロジェクト: manlan2/filmaster
    def initialize(self):
        self.clean_data()

        # set up users
        self.u1 = User.objects.create_user('michuk',
                                           '*****@*****.**',
                                           'secret')
        self.u1.save()

        # set up film
        self.film = Film()
        self.film.id = 233
        self.film.title = "Battlefield Earth II"
        self.film.type = Object.TYPE_FILM
        self.film.permalink = "battlefirld-earth-ii"
        self.film.release_year = 2010
        self.film.save(saved_by=2)
        self.film.save_tags("tag1", LANG="pl", saved_by=2)

        # set up film
        self.film1 = Film()
        self.film1.id = 236
        self.film1.title = "Battlefield Earth III"
        self.film1.type = Object.TYPE_FILM
        self.film1.permalink = "battlefirld-earth-iii"
        self.film1.release_year = 2011
        self.film1.save(saved_by=2)
        self.film1.save_tags("tag2", LANG="pl", saved_by=2)

        # set up activities
        sr = UserActivity(user=self.u1,
                          film=self.film,
                          object=self.film,
                          content="Lorem",
                          activity_type=UserActivity.TYPE_SHORT_REVIEW,
                          featured=True)
        sr.save()

        sr1 = UserActivity()
        sr1.user = self.u1
        sr1.film = self.film1
        sr1.object = self.film1
        sr1.content = "ipsum"
        sr1.activity_type = UserActivity.TYPE_SHORT_REVIEW
        sr1.featured = True
        sr1.save()

        rating1 = UserActivity()
        rating1.activity_type = UserActivity.TYPE_RATING
        rating1.user = self.u1
        rating1.object = self.film
        rating1.featured = True
        rating1.save()

        rating2 = UserActivity()
        rating2.activity_type = UserActivity.TYPE_RATING
        rating2.user = self.u1
        rating2.object = self.film
        rating2.featured = True
        rating2.save()
コード例 #2
0
ファイル: test_widgets.py プロジェクト: thuvh/filmmaster
    def initialize(self):
        self.clean_data()

        # set up users
        self.u1= User.objects.create_user('michuk', '*****@*****.**', 'secret')
        self.u1.save()

        # set up film
        self.film = Film()
        self.film.id = 233
        self.film.title = "Battlefield Earth II"
        self.film.type = Object.TYPE_FILM
        self.film.permalink = "battlefirld-earth-ii"
        self.film.release_year = 2010
        self.film.save(saved_by=2)
        self.film.save_tags("tag1", LANG="pl", saved_by=2)

        # set up film
        self.film1 = Film()
        self.film1.id = 236
        self.film1.title = "Battlefield Earth III"
        self.film1.type = Object.TYPE_FILM
        self.film1.permalink = "battlefirld-earth-iii"
        self.film1.release_year = 2011
        self.film1.save(saved_by=2)
        self.film1.save_tags("tag2", LANG="pl", saved_by=2)

        # set up activities
        sr = UserActivity(user=self.u1, film=self.film, object=self.film,
                content="Lorem", activity_type=UserActivity.TYPE_SHORT_REVIEW,
                featured=True)
        sr.save()

        sr1 = UserActivity()
        sr1.user = self.u1
        sr1.film = self.film1
        sr1.object = self.film1
        sr1.content = "ipsum"
        sr1.activity_type = UserActivity.TYPE_SHORT_REVIEW
        sr1.featured = True
        sr1.save()

        rating1 = UserActivity()
        rating1.activity_type = UserActivity.TYPE_RATING
        rating1.user = self.u1
        rating1.object = self.film
        rating1.featured = True
        rating1.save()

        rating2 = UserActivity()
        rating2.activity_type = UserActivity.TYPE_RATING
        rating2.user = self.u1
        rating2.object = self.film
        rating2.featured = True
        rating2.save()
コード例 #3
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()
コード例 #4
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()