Esempio n. 1
0
    def __init__(self, data, request, initial=None, prefix=None):
        from film20.core import rating_helper
        initial = initial or {}
        self.user = request.unique_user
        if not data:
            film_id = initial.get('film_id')
            actor_id = initial.get('actor_id')
            director_id = initial.get('director_id')
            type = initial.get('type')
            if self.user.id:
                r = rating_helper.get_rating(self.user,
                                             film_id=film_id,
                                             actor_id=actor_id,
                                             director_id=director_id,
                                             type=type)
                if r:
                    initial['rating'] = r

            prefix = 'rating_%d' % type
            if film_id:
                prefix += "_%d" % film_id
            if actor_id:
                prefix += "_%d" % actor_id
            if director_id:
                prefix += "_%d" % director_id

        super(SingleRatingForm, self).__init__(data,
                                               initial=initial,
                                               prefix=prefix)
Esempio n. 2
0
    def __init__(self, data, request, film, edit=False):
        from film20.core import rating_helper
        initial = {}
        if not data and request.unique_user.id:
            if edit:
                for type in (6, 7, 8, 9, 10, 11, 14, 15):
                    v = rating_helper.get_rating(user=request.unique_user, film_id=film.id, type=type)
                    if v:
                        initial['rating_%d' % type] = v

        super(FilmRatingForm, self).__init__(data, request, film, initial=initial)
Esempio n. 3
0
    def __init__(self, data, request, film, edit=False):
        from film20.core import rating_helper
        initial = {}
        if not data and request.unique_user.id:
            if edit:
                for type in (6, 7, 8, 9, 10, 11, 14, 15):
                    v = rating_helper.get_rating(user=request.unique_user,
                                                 film_id=film.id,
                                                 type=type)
                    if v:
                        initial['rating_%d' % type] = v

        super(FilmRatingForm, self).__init__(data,
                                             request,
                                             film,
                                             initial=initial)
Esempio n. 4
0
    def testResolveDuplicate( self ):
        do, cr = DuplicateFilm.objects.get_or_create( user=self.u1, filmA=self.f1, filmB=self.f2 )
        
        data = {
            'A': 'true',
            'step': '3',
        }

        self.client.login( username='******', password='******' )
        response = self.client.post( reverse( 'movie-merging-tool-resolve', args=[ do.pk ] ), data )
        self.assertEqual( response.status_code, 200 )

        self.f1 = Film.objects.get( pk=self.f1.pk )

        self.assertEqual( len(rating_helper.get_film_ratings(self.f1.id)), 4 )
        self.assertEqual( rating_helper.get_rating(self.u1, self.f1.id), 1)
Esempio n. 5
0
    def testResolveDuplicate(self):
        do, cr = DuplicateFilm.objects.get_or_create(user=self.u1,
                                                     filmA=self.f1,
                                                     filmB=self.f2)

        data = {
            'A': 'true',
            'step': '3',
        }

        self.client.login(username='******', password='******')
        response = self.client.post(
            reverse('movie-merging-tool-resolve', args=[do.pk]), data)
        self.assertEqual(response.status_code, 200)

        self.f1 = Film.objects.get(pk=self.f1.pk)

        self.assertEqual(len(rating_helper.get_film_ratings(self.f1.id)), 4)
        self.assertEqual(rating_helper.get_rating(self.u1, self.f1.id), 1)
Esempio n. 6
0
    def __init__(self, data, request, initial=None, prefix=None):
        from film20.core import rating_helper
        initial = initial or {}
        self.user = request.unique_user
        if not data:
            film_id = initial.get('film_id')
            actor_id = initial.get('actor_id')
            director_id = initial.get('director_id')
            type = initial.get('type')
            if self.user.id:
                r = rating_helper.get_rating(self.user, film_id=film_id, actor_id=actor_id, director_id=director_id, type=type)
                if r:
                    initial['rating'] = r

            prefix = 'rating_%d' % type
            if film_id:
                prefix += "_%d" % film_id
            if actor_id:
                prefix += "_%d" % actor_id
            if director_id:
                prefix += "_%d" % director_id 

        super(SingleRatingForm, self).__init__(data, initial=initial, prefix=prefix)