当前位置: 首页>>代码示例>>Python>>正文


Python Film.save方法代码示例

本文整理汇总了Python中film20.core.models.Film.save方法的典型用法代码示例。如果您正苦于以下问题:Python Film.save方法的具体用法?Python Film.save怎么用?Python Film.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在film20.core.models.Film的用法示例。


在下文中一共展示了Film.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: initialize

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def initialize(self):
        self.clean_data()

        film1 = Film()
        film1.id = 1
        film1.title = "Battlefield Earth"
        film1.type = Object.TYPE_FILM
        film1.permalink = "battlefield-earth-i"
        film1.release_year = 2010
        film1.save()
        self.film1 = film1

        film2 = Film()
        film2.id = 2
        film2.title = "Battlefield Earth II"
        film2.type = Object.TYPE_FILM
        film2.permalink = "battlefield-earth-ii"
        film2.release_year = 2001
        film2.save()
        self.film2 = film2

        item = Item()
        item.film = film1
        item.external_id = '232323'
        item.url_product = 'http://www.amazonka.pl/2046_wong-kar-wai,99900073479.bhtml'
        item.save()
        self.item1 = item
开发者ID:thuvh,项目名称:filmmaster,代码行数:29,代码来源:test_shop.py

示例2: test_filmindb

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def test_filmindb(self):
        """
            Test failed fetch movie in db
        """
        self.initialize()

        self.client.login(username=self.user.username, password='secret')

        film_to_import = FilmToImport(user = self.user,
                                  title = 'Elektroniczny Morderca',
                                  imdb_url = 'http://www.imdb.com/title/tt0088247/',
					              imdb_id='0088247',
                                  status=FilmToImport.ACCEPTED)

        film_to_import.save()

        film = Film()
        film.title = "The Terminator"
        film.type = Object.TYPE_FILM
        film.imdb_code = "0088247"
        film.permalink = "the-terminator"
        film.release_year = 1984
        film.save()

        run(False, False, False, False, False, True, "http")

        film_to_import = FilmToImport.objects.get(title = 'Elektroniczny Morderca')
        self.assertEqual(film_to_import.attempts, 1)
        self.assertEqual(film_to_import.status, FilmToImport.ALREADY_IN_DB)
开发者ID:thuvh,项目名称:filmmaster,代码行数:31,代码来源:test_imdb_fetcher.py

示例3: FilmBasketTestCase

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
class FilmBasketTestCase( TestCase ):

    def setUp( self ):
        self.user = User.objects.create_user( "user", "[email protected]", "user" )

        self.film = Film( type=1, permalink='przypadek', imdb_code=111, status=1, version=1, \
                            release_year=1999, title='Przypadek' )
        self.film.save()



    def tearDown( self ):
        User.objects.all().delete()
        Film.objects.all().delete()
        Rating.objects.all().delete()
        BasketItem.objects.all().delete()

    def testRatingRemoveFromWishlist( self ):

        BasketItem.objects.create( film=self.film, wishlist=BasketItem.DYING_FOR, user=self.user )

        self.assertEqual( len( BasketItem.user_basket( self.user ) ), 1 )

        Rating.objects.create( type=Rating.TYPE_FILM, film=self.film, rating=5, 
                                parent=self.film, user=self.user)
    
        bi = BasketItem.objects.get( film=self.film, user=self.user )
        self.assertTrue( bi.wishlist is None )
开发者ID:thuvh,项目名称:filmmaster,代码行数:30,代码来源:tests.py

示例4: testQueueCommand

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def testQueueCommand( self ):
        f = Film( type=1, permalink='przypadek', imdb_code=111, status=1, version=1, \
                 release_year=1999, title='Przypadek' )
        f.save()
        f.delete()
    
        self.assertEqual( QueuedItem.objects.count(), 3 )

        call_command( 'update_index_queue' )
        
        self.assertEqual( QueuedItem.objects.count(), 1 )
开发者ID:,项目名称:,代码行数:13,代码来源:

示例5: initialize

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def initialize(self):

        self.clean_data()

        film = Film()
        film.title = "The Terminator"
        film.type = Object.TYPE_FILM
        film.imdb_code = "0088247"
        film.permalink = "the-terminator"
        film.release_year = 1984
        film.save()
        self.film = film
开发者ID:yangjiandong,项目名称:filmaster,代码行数:14,代码来源:test_tmdb_fetcher.py

示例6: SimilarFilmsTestCase

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
class SimilarFilmsTestCase( TestCase ):

    def setUp( self ):
        self.u1 = User.objects.create_user( "user1", "[email protected]", "user" )
        self.u2 = User.objects.create_user( "user2", "[email protected]", "user" )
        self.u3 = User.objects.create_user( "user3", "[email protected]", "user" )

        self.f1 = Film()
        self.f1.title = "Battlefield Earth"
        self.f1.type = Film.TYPE_FILM
        self.f1.permalink = "battlefirld-earth"
        self.f1.release_year = 208
        self.f1.production_country_list = "USA"
        self.f1.save()

        self.f2 = Film()
        self.f2.title = "Battlefield Earth II"
        self.f2.type = Film.TYPE_FILM
        self.f2.permalink = "battlefirld-earth-ii"
        self.f2.release_year = 2010
        self.f2.production_country_list = "USA"
        self.f2.save()

    def tearsDown( self ):
        Film.objects.all().delete()
        SimilarFilm.objects.all().delete()

    def test_votes( self ):
        SimilarFilm.add_vote( user=self.u1, film_a=self.f1, film_b=self.f2 )#1
        SimilarFilm.add_vote( user=self.u2, film_a=self.f1, film_b=self.f2 )#2
        SimilarFilm.add_vote( user=self.u3, film_a=self.f1, film_b=self.f2 )#3
        
        SimilarFilm.add_vote( user=self.u3, film_a=self.f2, film_b=self.f1 )#4
        

        self.assertEqual( SimilarFilm.objects.filter( film_a=self.f1 ).count(), 1 )
        
        similar = SimilarFilm.objects.get( film_a=self.f1 )
        self.assertEqual( similar.number_of_votes, 3 )

        SimilarFilm.remove_vote( user=self.u1, film_a=self.f1, film_b=self.f2 )#2

        similar = SimilarFilm.objects.get( film_a=self.f1 )
        self.assertEqual( similar.number_of_votes, 2 )

        SimilarFilm.remove_vote( user=self.u2, film_a=self.f1, film_b=self.f2 )#1

        similar = SimilarFilm.objects.get( film_a=self.f1 )
        self.assertEqual( similar.number_of_votes, 1 )

        SimilarFilm.remove_vote( user=self.u3, film_a=self.f1, film_b=self.f2 )#1

        self.assertEqual( SimilarFilm.objects.filter( film_a=self.f1 ).count(), 0 )
开发者ID:yangjiandong,项目名称:filmaster,代码行数:55,代码来源:test_similar_films.py

示例7: testImdbCodes

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def testImdbCodes( self ):
        from film20.import_films.update_imdb_codes import update_all_imdb_codes

        f1 = Film( type=1, imdb_code="199123", release_year=2008, title="The Incredible Hulk" )
        f1.save()

        f2 = Film( type=1, imdb_code="333332", release_year=1992, title="The Godfather Trilogy: 1901-1980" )
        f2.save()
 
        f3 = Film( type=1, imdb_code="343454", release_year=2007, title="Youth Without Youth" )
        f3.save()

        f4 = Film( type=1, imdb_code="343sd4", release_year=1007, title="Fake Movie" )
        f4.save()

        update_all_imdb_codes()

        self.failUnlessEqual( Film.objects.get( pk=f1.pk ).imdb_code, "0800080" )
        self.assertTrue( Film.objects.get( pk=f1.pk ).verified_imdb_code )
        
        self.failUnlessEqual( Film.objects.get( pk=f2.pk ).imdb_code, "0150742" )
        self.assertTrue( Film.objects.get( pk=f2.pk ).verified_imdb_code )

        self.failUnlessEqual( Film.objects.get( pk=f3.pk ).imdb_code, "0481797" )
        self.assertTrue( Film.objects.get( pk=f3.pk ).verified_imdb_code )

        self.failUnlessEqual( Film.objects.get( pk=f4.pk ).imdb_code, "343sd4" )
        self.assertFalse( Film.objects.get( pk=f4.pk ).verified_imdb_code )
开发者ID:thuvh,项目名称:filmmaster,代码行数:30,代码来源:tests.py

示例8: testFixCountries

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def testFixCountries( self ):
        from film20.import_films.update_countries import update_all_films

        f1 = Film( type=1, imdb_code="123", release_year=2002, title="Fake 1",
            production_country_list="FrancePolandGermanyUK," )
        f1.save()

        f2 = Film( type=1, imdb_code="456", release_year=2010, title="Fake 2", 
            production_country_list="USAUKUnited Arab Emirates," )
        f2.save()

        f3 = Film( type=1, imdb_code="789", release_year=2010, title="Fake 3", 
            production_country_list="USA" )
        f3.save()

        f4 = Film( type=1, imdb_code="111", release_year=2010, title="Fake 4", 
            production_country_list="UK, Aasdasd asdas, ," )
        f4.save()

        update_all_films()

        self.failUnlessEqual( Film.objects.get( pk=f1.pk ).production_country_list, 
                       "France,Poland,Germany,UK" )
        self.failUnlessEqual( Film.objects.get( pk=f2.pk ).production_country_list, 
                       "USA,UK,United Arab Emirates" )
        self.failUnlessEqual( Film.objects.get( pk=f3.pk ).production_country_list, 
                       "USA" )
        self.failUnlessEqual( Film.objects.get( pk=f4.pk ).production_country_list, 
                       "UK" )
开发者ID:yangjiandong,项目名称:filmaster,代码行数:31,代码来源:tests.py

示例9: RequestTestCase

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
class RequestTestCase(TestCase):
    fixtures = ['test_users.json']
    def setUp(self):
        self.user = User.objects.get(username='bob')
        self.user.set_password('bob')
        self.user.save()
        
        self.film = Film(type=1, permalink='przypadek', imdb_code=111, status=1, version=1, 
            release_year=1999, title='Przypadek', popularity=1, popularity_month=1)
        self.film.save()
        
        self.person = Person(type=2, permalink='jerzy-stuhr', imdb_code=112, status=1, version=1, 
            name='Jerzy', surname='Stuhr')
        self.person.save()

    
    def test_index(self):
        response = self.client.get('/')
        self.failUnlessEqual(response.status_code, 200)

    def test_film(self):
        response = self.client.get('/film/przypadek/')
        self.failUnlessEqual(response.status_code, 200)

    def test_film_authorized(self):
        self.client.login(username='bob', password='bob')
        response = self.client.get('/film/przypadek/')
        self.assertTrue(response.context['request'].user.is_authenticated())
        self.failUnlessEqual(response.status_code, 200)

    def test_person(self):
        response = self.client.get(self.person.get_absolute_url())
        self.assertEquals(response.status_code, 200)
    
    def test_person_authorized(self):
        self.client.login(username='bob', password='bob')
        response = self.client.get(self.person.get_absolute_url())
        self.assertEquals(response.status_code, 200)

    def tearDown(self):
        Person.objects.all().delete()
        Film.objects.all().delete()
开发者ID:thuvh,项目名称:filmmaster,代码行数:44,代码来源:test_request.py

示例10: test_watching_notification

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def test_watching_notification(self):
        """
            Testing notifications for different types of activities (posts, short reviews and threads)
        """
        self.initialize()        
        activity = UserActivity.objects.get_for_object(self.post1)

        # create two comments for blog post by two different users 
        t = ThreadedComment(user=self.u2,
                                comment="This is a comment",
                                content_object=activity, 
                                type=Object.TYPE_COMMENT)
        t.save() 
        t = ThreadedComment(user=self.u3,
                                comment="This is also a comment",
                                content_object=activity, 
                                type=Object.TYPE_COMMENT)
        t.save() 
        
        # create film and a short review and a comment to it
        f1 = Film(type=1, permalink='przypadek', imdb_code=111, status=1, version=1, 
            release_year=1999, title='Przypadek', popularity=1, popularity_month=1)
        f1.save()
        sr = ShortReview(user=self.u1, review_text="This is a short review", object = f1, type=Object.TYPE_SHORT_REVIEW)
        sr.save()
        activity2 = UserActivity.objects.get_for_object(sr)
        t = ThreadedComment(user=self.u2,
                                comment="This is a comment to a short review",
                                content_object=activity2, 
                                type=Object.TYPE_COMMENT)
        t.save()

        # assert all is fine
        watching_objects = Watching.objects.all() 
        self.assertEquals(len(watching_objects), 5) # number of unique comments in threads should be equal to watching objects

        reply_notices = notification.Notice.objects.filter(notice_type__label='reply')

        # TODO: uncommend and fix in http://jira.filmaster.org/browse/FLM-1116
        self.assertEquals(len(reply_notices), 4) # number of notices
开发者ID:thuvh,项目名称:filmmaster,代码行数:42,代码来源:test_watching.py

示例11: testQueuedItem

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def testQueuedItem( self ):
        self.assertEqual( QueuedItem.objects.count(), 1 )
        self.assertTrue( isinstance( QueuedItem.objects.all()[0].content_object, User ) )
 
        f = Film( type=1, permalink='przypadek', imdb_code=111, status=1, version=1, \
                 release_year=1999, title='Przypadek' )
        f.save()
        
        self.assertEqual( QueuedItem.objects.count(), 3 )
        self.assertTrue( isinstance( QueuedItem.objects.all()[1].content_object, Film ) )
        
        modified_at = QueuedItem.objects.all()[1].modified_at

        f.title = 'Przypadek - test'
        f.save()

        self.assertEqual( QueuedItem.objects.count(), 3 )
        self.assertTrue( QueuedItem.objects.all()[1].modified_at > modified_at )

        f.delete()

        self.assertEqual( QueuedItem.objects.all()[1].action_type, QueuedItem.ACTION_REMOVED )
        self.assertEqual( QueuedItem.objects.count(), 3 )
开发者ID:,项目名称:,代码行数:25,代码来源:

示例12: TmdbFetcherTestCase

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
class TmdbFetcherTestCase(TestCase):

    def test_fetcher(self):

        title = "The Terminator"
        url = "http://www.themoviedb.org/movie/218"
        year = 1984
        synopsis = "In the post-apocalyptic future, reigning tyrannical supercomputers teleport a cyborg assassin known as the \"Terminator\" back to 1984 to snuff Sarah Connor, whose unborn son is destined to lead insurgents against 21st century mechanical hegemony. Meanwhile, the human-resistance movement dispatches a lone warrior to safeguard Sarah. Can he stop the virtually indestructible killing machine?"

        fetcher = TmdbSynopsisFetcher()
        urls = fetcher.get_movie_urls(title, year)
        synopses = fetcher.get_movie_synopses(urls[0]['url'])

        self.assertEquals(synopses[0]['synopsis'], synopsis)
        self.assertEquals(synopses[0]['url'], url)
        self.assertEquals(synopses[0]['author'], "TMDb")
        self.assertEquals(synopses[0]['distributor'], False)
        self.assertEquals(synopses[0]['title'], title)

    def test_save_searchkeys(self):
        """
            Test saving searchkeys for localized film
        """
        self.film = Film()
        self.film.title = u"Olympia - Fest der Schönheit"
        self.film.type = Object.TYPE_FILM
        self.film.permalink = "olympia-2-teil-fest-der-schoenheit"
        self.film.release_year = 1938
        self.film.save()

        fetch_synopses_for_films([self.film,], fetcher="tmdb")

        loc_film = FilmLocalized.objects.all()[0]

        self.assertEquals(loc_film.description is None, True)
        self.assertEquals(loc_film.fetched_description is None, False)
开发者ID:thuvh,项目名称:filmmaster,代码行数:38,代码来源:test_synopsis.py

示例13: setUp

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
    def setUp(self):
        """
        setup user
        """
        self.u1 = User(username='michuk', email='[email protected]')
        self.u1.save()

        Film.objects.filter(imdb_code__lt=1000).delete()

        f1 = Film(type=1, permalink='we-live-in-public', imdb_code=111, status=1, version=1,
            release_year=2009, title='We live in public', popularity=1, popularity_month=1)
        f1.save()
        # wrong year, should NOT match, only matches when year exact or different by 1
        f2 = Film(type=1, permalink='krotki-film-o-zabijaniu', imdb_code=112, status=1, version=1,
        release_year=1980, title='Krotki film o zabijaniu', popularity=1, popularity_month=1)
        f2.save()
        f3 = Film(type=1, permalink='xiao-cai-feng', imdb_code=113, status=1, version=1,
        release_year=2002, title='Xiao cai feng', popularity=1, popularity_month=1)
        f3.save()
        films = Film.objects.all()
        print "films in database: " + str(len(films))
开发者ID:thuvh,项目名称:filmmaster,代码行数:23,代码来源:test_imdb.py

示例14: CommandsTestCase

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
class CommandsTestCase( TestCase ):

    def setUp( self ):

        # set up films
        self.film1 = Film()
        self.film1.title = "Battlefield Earth II"
        self.film1.type = Object.TYPE_FILM
        self.film1.permalink = "battlefirld-earth-ii"
        self.film1.release_year = 2010
        self.film1.production_country_list = "USA"
        self.film1.save()
        self.film1.save_tags( "sciencie-fiction komedia test1 test2", LANG="pl", saved_by=2)

        self.film2 = Film()
        self.film2.title = "Battlefield Earth III"
        self.film2.type = Object.TYPE_FILM
        self.film2.permalink = "battlefirld-earth-iii"
        self.film2.release_year = 2011
        self.film2.production_country_list = "USA"
        self.film2.save()
        self.film2.save_tags("sciencie-fiction komedia test1", LANG="pl", saved_by=2)

        self.film3 = Film()
        self.film3.title = "Battlefield Earth IV"
        self.film3.type = Object.TYPE_FILM
        self.film3.permalink = "battlefirld-earth-iv"
        self.film3.release_year = 2012
        self.film3.production_country_list = "Italy"
        self.film3.save()
        self.film3.save_tags("sciencie-fiction komedia test3 test5", LANG="pl", saved_by=2)

        self.film4 = Film()
        self.film4.title = "Battlefield Earth V"
        self.film4.type = Object.TYPE_FILM
        self.film4.permalink = "battlefirld-earth-v"
        self.film4.release_year = 2013
        self.film4.production_country_list = "UK"
        self.film4.save()
        self.film4.save_tags("sciencie-fiction komedia test5", LANG="en", saved_by=2)
        self.film4.save_tags("sciencie-fiction komedia", LANG="en", saved_by=2)

        self.film5 = Film()
        self.film5.title = "Battlefield Earth VI"
        self.film5.type = Object.TYPE_FILM
        self.film5.permalink = "battlefirld-earth-vi"
        self.film5.release_year = 2013
        self.film5.production_country_list = "UK"
        self.film5.save()
        self.film5.save_tags("sciencie-fiction comedy", LANG="en", saved_by=2)

    def tearDown( self ):
        Tag.all_objects.all().delete()
        Film.objects.all().delete()

    def test_remove_unused_tags( self ):
        self.assertEqual( Tag.all_objects.filter( LANG='pl' ).count(), 6 )
        self.assertEqual( Tag.all_objects.filter( LANG='en' ).count(), 4 )

        call_command( 'remove_unused_tags' )

        self.assertEqual( Tag.all_objects.filter( LANG='pl' ).count(), 6 )
        self.assertEqual( Tag.all_objects.filter( LANG='en' ).count(), 3 )

    def test_duplicate_localized_tags( self ):
        obj, created = FilmLocalized.objects.get_or_create( parent=self.film1, film=self.film1, LANG='pl' )
        ctype = ContentType.objects.get_for_model( obj )
        tag, created = Tag.all_objects.get_or_create( name='scifi', LANG='en' )
        
        TaggedItem._default_manager.get_or_create( tag=tag, content_type=ctype, object_id=obj.pk )
        
        self.assertEqual( Tag.all_objects.filter( LANG='pl' ).count(), 6 )
        self.assertEqual( Tag.all_objects.filter( LANG='en' ).count(), 5 )
        self.assertEqual( TaggedItem.all_objects.count(), 16 )

        call_command( 'duplicate_localized_tags' )
        
        self.assertEqual( Tag.all_objects.filter( LANG='pl' ).count(), 7 )
        self.assertEqual( Tag.all_objects.filter( LANG='en' ).count(), 3 )
        self.assertEqual( TaggedItem.all_objects.count(), 16 )

        tagged_item = TaggedItem._default_manager.get( content_type=ctype, object_id=obj.pk )
        self.assertEqual( tagged_item.tag.name, 'scifi' )
        self.assertEqual( tagged_item.tag.LANG, 'pl' )
开发者ID:thuvh,项目名称:filmmaster,代码行数:86,代码来源:test_commands.py

示例15: TagTranslationTestCase

# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import save [as 别名]
class TagTranslationTestCase( TestCase ):

    def setUp( self ):

        # set up films
        self.film1 = Film()
        self.film1.title = "Film 1"
        self.film1.type = Object.TYPE_FILM
        self.film1.permalink = "film-1"
        self.film1.release_year = 2010
        self.film1.production_country_list = "USA"
        self.film1.save()
        self.film1.save_tags( "dramat komedia ", LANG="pl", saved_by=2 )
        self.film1.save_tags( "drama comedy wizards ", LANG="en", saved_by=2 )


    def tearDown( self ):
        Tag.all_objects.all().delete()
        Film.objects.all().delete()

    def test_translation_1( self ):

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), 'dramat,komedia' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), 'comedy,drama,wizards' )

        TagTranslation.create_translation( 'drama', 'dramat', 'en', 'pl' )
        TagTranslation.create_translation( 'comedy', 'komedia', 'en', 'pl' )
        TagTranslation.create_translation( 'vampires', 'wampiry', 'en', 'pl' )

        self.film1.save_tags( "dramat komedia wampiry", LANG="pl", saved_by=2 )

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), 'dramat,komedia,wampiry' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), 'comedy,drama,vampires,wizards' )

    def test_translation_2( self ):

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), 'dramat,komedia' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), 'comedy,drama,wizards' )

        TagTranslation.create_translation( 'drama', 'dramat', 'en', 'pl' )
        TagTranslation.create_translation( 'comedy', 'komedia', 'en', 'pl' )

        self.film1.save_tags( "dramat komedia wampiry", LANG="pl", saved_by=2 )

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), 'dramat,komedia,wampiry' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), 'comedy,drama,wizards' )

    def test_translation_3( self ):

        TagTranslation.create_translation( 'drama', 'dramat', 'en', 'pl' )
        TagTranslation.create_translation( 'comedy', 'komedia', 'en', 'pl' )

        self.film1.save_tags( "test test1", LANG="en", saved_by=2 )
        self.film1.save_tags( "dramat komedia wampiry", LANG="pl", saved_by=2 )

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), 'dramat,komedia,wampiry' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), 'comedy,drama,test,test1' )

    def test_translation_4( self ):

        self.film1.save_tags( "test test1", LANG="en", saved_by=2 )
        self.film1.save_tags( "dramat komedia wampiry", LANG="pl", saved_by=2 )

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), 'dramat,komedia,wampiry' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), 'test,test1' )

    def test_command( self ):
        from django.db import connection, transaction
        from django.core.management import call_command
        from django.contrib.contenttypes.models import ContentType
        
        cursor = connection.cursor()    

        query = """
            INSERT INTO tagging_taggeditem ( tag_id, content_type_id, object_id ) VALUES( %d, %d, %d )
        """        

        self.film1.save_tags( "", LANG="pl", saved_by=2 )
        self.film1.save_tags( "", LANG="en", saved_by=2 )

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), '' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), '' )
        
        content_type_id = ContentType.objects.get_for_model( ObjectLocalized ).pk
        en_object = ObjectLocalized.objects.get( parent=self.film1.pk, LANG="en" )
        pl_object = ObjectLocalized.objects.get( parent=self.film1.pk, LANG="pl" )

        for name in "en1", "en2":
            tag, created = Tag.all_objects.get_or_create( LANG="en", name=name ) 
            cursor.execute( query % ( tag.id, content_type_id, en_object.pk ) )

        for name in "polski", "polski2", "polski3":
            tag, created = Tag.all_objects.get_or_create( LANG="pl", name=name ) 
            cursor.execute( query % ( tag.id, content_type_id, pl_object.pk ) )

        transaction.commit()

        self.assertEqual( get_tags_as_string( self.film1, 'pl' ), 'polski,polski2,polski3' )
        self.assertEqual( get_tags_as_string( self.film1, 'en' ), 'en1,en2' )

#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


注:本文中的film20.core.models.Film.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。