本文整理汇总了Python中film20.core.models.Film类的典型用法代码示例。如果您正苦于以下问题:Python Film类的具体用法?Python Film怎么用?Python Film使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Film类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FilmBasketTestCase
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 )
示例2: refill_tag_basket
def refill_tag_basket(cls, user, tag):
TAG_BASKET_SIZE = getattr(settings, 'TAG_BASKET_SIZE')
MIN_TAG_BASKET_SIZE = getattr(settings, 'MIN_TAG_BASKET_SIZE')
try:
lang = user.get_profile().LANG
except AttributeError:
lang = 'en'
basket_key = cache.Key(cache.CACHE_TAG_BASKET, user, tag)
tag_basket = cache.get(basket_key) or dict()
if len(tag_basket) < MIN_TAG_BASKET_SIZE:
# get films with this tag
films_dict = Film.get_film_ids_by_tag(tag, lang)
# get films seen by user
seen_films = Film.get_user_seen_films(user)
# remove films seen by user
films_dict = dict([(k,v) for k,v in films_dict.items() if k not in seen_films])
# how many we want to refill
to_refill = TAG_BASKET_SIZE - len(tag_basket)
# reverse sort by popularity
sorted_films = sorted(films_dict, key=films_dict.get, reverse=True)[:to_refill]
refill_dict = dict([(fid, films_dict[fid]) for fid in sorted_films])
tag_basket.update(refill_dict)
cache.set(basket_key, tag_basket, cache.A_MONTH)
示例3: get_seen_films
def get_seen_films(user):
if settings.USE_REDIS:
seen_ids = redis_intf.get_seen_films(user)
else:
seen_ids = Film._recently_seen_film_ids(user)
seen_ids.difference_update(Film._long_ago_seen_film_ids(user))
return seen_ids
示例4: setUp
def setUp( self ):
self.u1 = User.objects.create_user( "user", "[email protected]", "user" )
self.u1.is_superuser = True
self.u1.save()
self.u2 = User.objects.create_user( "user2", "[email protected]", "user2" )
self.u3 = User.objects.create_user( "user3", "[email protected]", "user3" )
self.u4 = User.objects.create_user( "user4", "[email protected]", "user4" )
self.f1 = Film()
self.f1.title = "Battlefield Earth II"
self.f1.type = Object.TYPE_FILM
self.f1.permalink = "battlefirld-earth-ii"
self.f1.release_year = 2010
self.f1.production_country_list = "USA"
self.f1.save()
self.f1.save_tags( "sciencie-fiction komedia test1 test2", LANG="pl", saved_by=2)
self.f2 = Film()
self.f2.title = "Battlefield Earth II 2"
self.f2.type = Object.TYPE_FILM
self.f2.permalink = "battlefirld-earth-ii-2"
self.f2.release_year = 2010
self.f2.production_country_list = "USA"
self.f2.save()
self.f2.save_tags( "sciencie komedia test1", LANG="pl", saved_by=2)
rating_helper.rate(self.u1, 1, self.f1.id)
rating_helper.rate(self.u1, 2, self.f2.id)
rating_helper.rate(self.u2, 3, self.f1.id)
rating_helper.rate(self.u3, 3, self.f1.id)
rating_helper.rate(self.u4, 3, self.f2.id)
示例5: film_from_film_on_channel
def film_from_film_on_channel(f):
film = Film(
title=f.title,
permalink="unmatched-film-%d" % f.pk,
image=None,
production_country_list='',
)
film._directors = f.directors
return film
示例6: get_films
def get_films(self):
key = cache.Key("festival_films", self)
films = cache.get(key)
if films is None:
films = Film.objects.tagged(self.tag.lower())
films = list(films[:1000])
Film.update_ranking(films)
cache.set(key, films)
return films
示例7: initialize
def initialize(self):
self.clean_data()
# set up users
self.u1= User.objects.create_user('michuk', '[email protected]', '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()
示例8: testQueueCommand
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 )
示例9: SimilarFilmsTestCase
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 )
示例10: create_films
def create_films(self):
self.film1 = Film()
self.film1.title = "The Terminator"
self.film1.type = Object.TYPE_FILM
self.film1.permalink = "the-terminator"
self.film1.release_year = 1984
self.film1.save()
self.film2 = Film()
self.film2.title = "Rambo"
self.film2.type = Object.TYPE_FILM
self.film2.permalink = "rambo"
self.film2.release_year = 1982
self.film2.save()
示例11: test_filmindb
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)
示例12: setUp
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)
示例13: user_recommendations
def user_recommendations(user, films, with_rated=False, order_by=None):
film_ids = [f.id for f in films]
if user and user.is_authenticated():
profile = user.get_profile()
basket = BasketItem.user_basket(user)
rated_ids = Film._rated_film_ids(user)
if profile.recommendations_status in (profile.NORMAL_RECOMMENDATIONS, profile.FAST_RECOMMENDATIONS):
recommendations = _user_film_recommendations(user, film_ids)
else:
recommendations = {}
for f in films:
r = recommendations.get(f.id)
b = basket.get(f.id)
f._rated = f.id in rated_ids
f._guess_rating = r or 0
f._on_wishlist = b and b[0] and (b[0] != BasketItem.NOT_INTERESTED) or False
f._on_shitlist = b and (b[0] == BasketItem.NOT_INTERESTED) or False
else:
for f in films:
f._rated = False
f._guess_rating = 0
f._on_wishlist = False
f._on_shitlist = False
test_with_rated = lambda f: with_rated or not f._rated
films = list(f for f in films if not f._on_shitlist and test_with_rated(f))
comparator = create_film_comparator(order_by)
return sorted(films, cmp=comparator)
示例14: get_films_to_rate
def get_films_to_rate(self, number_of_films=1, tag=None):
key = cache.Key("vue_rater_user_films", self.user)
user_films = cache.get(key)
if user_films is None:
user_films = vue.get_ordered_known_film_ids()
if self.SHUFFLE_BLOCK_SIZE:
shuffled = []
while user_films:
block = user_films[:self.SHUFFLE_BLOCK_SIZE]
user_films = user_films[self.SHUFFLE_BLOCK_SIZE:]
random.shuffle(block)
shuffled.extend(block)
user_films = shuffled
cache.set(key, user_films)
excluded = self.get_excluded_films()
out = []
for film_id in user_films:
if film_id not in excluded:
out.append(film_id)
if len(out) >= number_of_films:
break
out = [Film.get(id=id) for id in out]
return out
示例15: setUp
def setUp( self ):
# test user with no permissions
self.u1 = User.objects.create_user( "user", "[email protected]", "user" )
# test user with moderation_permission
self.u2 = User.objects.create_user( "root", "[email protected]", "root" )
self.u2.user_permissions.add( Permission.objects.get( codename="can_add_link" ) )
self.u2.save()
# set up film
self.film = Film()
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()
# set up links
self.link1 = ExternalLink( user=self.u2, film=self.film, permalink='LINK', version=1,
type=ExternalLink.TYPE_LINK, status=ExternalLink.PUBLIC_STATUS,
url_kind = ExternalLink.TRAILER, url="http://yt.com" )
self.link2 = ExternalLink( user=self.u2, film=self.film, permalink='LINK', version=1,
type=ExternalLink.TYPE_LINK, status=ExternalLink.PUBLIC_STATUS,
url_kind = ExternalLink.TRAILER, url="http://yt.com/v=1" )
self.link1.save()
self.link2.save()