本文整理汇总了Python中film20.core.models.Film.get方法的典型用法代码示例。如果您正苦于以下问题:Python Film.get方法的具体用法?Python Film.get怎么用?Python Film.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类film20.core.models.Film
的用法示例。
在下文中一共展示了Film.get方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_films_to_rate
# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get [as 别名]
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
示例2: show_event
# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get [as 别名]
def show_event(request, permalink, ajax=None):
event = get_object_or_404(Event,permalink = permalink)
nominated = Nominated.objects.with_rates(event)
for n in nominated:
if n.film_id:
n.film = Film.get(id=n.film_id)
if n.person_id:
n.person = Person.get(id=n.person_id)
categories = []
for type, items in groupby(nominated, lambda n: n.oscar_type):
items = list(items)
if event.event_status == Event.STATUS_OPEN:
shuffle(list(items))
if items:
categories.append({
'name': items[0].get_category_name(),
'nominated': items,
})
ctx = {
'event': event,
'categories': categories,
}
return render_to_response('event/event.html', ctx, context_instance=RequestContext(request))
示例3: force_similar
# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get [as 别名]
def force_similar(self, recommendations, ratings):
if self.limit is not None and self.limit < TOP_RECOMMENDATIONS_NR:
similar_cnt = self.limit - (self.limit / 2)
else:
similar_cnt = 3
similar_films = get_similar_films()
similar_scores = {}
for film_id, r in ratings.items():
weight = r - 5
similar = similar_films.get(film_id, set())
for s_id in similar:
similar_scores[s_id] = similar_scores.get(s_id, 0) + weight
recommended_ids = set(k for k, v in recommendations)
similar_scores = [(id, score*10 + self.recommendations_dict.get(id, 0)) for (id, score) in similar_scores.items()]
top_similar = sorted(similar_scores, key=lambda i:i[1], reverse=True)
if settings.VUE_DEBUG:
self.similar_debug = [(Film.get(id=id), score) for (id, score) in top_similar if id in recommended_ids]
logger.info(self.similar_debug)
else:
self.similar_debug = []
top_similar = [(id, self.recommendations_dict.get(id, 0)) for (id, score) in top_similar if score>=0 and id in recommended_ids]
top_similar = top_similar[:similar_cnt]
self.similar = set(i[0] for i in top_similar)
recommendations = [r for r in recommendations if r[0] not in self.similar]
if len(top_similar) < (self.limit or TOP_RECOMMENDATIONS_NR):
# sort visible recommendations
left = (self.limit or TOP_RECOMMENDATIONS_NR) - len(top_similar)
top_similar.extend(recommendations[:left])
del recommendations[:left]
top_similar.sort(key=lambda r:r[1], reverse=True)
top_similar.extend(recommendations)
recommendations = top_similar
return recommendations
示例4: wrap
# 需要导入模块: from film20.core.models import Film [as 别名]
# 或者: from film20.core.models.Film import get [as 别名]
def wrap(self, items):
for id, rating in items:
film = Film.get(id=id)
film.guess_rating = rating
film.similar = self.similar and (film.id in self.similar)
yield film