本文整理汇总了Python中videos.models.Video.widget_views_counter方法的典型用法代码示例。如果您正苦于以下问题:Python Video.widget_views_counter方法的具体用法?Python Video.widget_views_counter怎么用?Python Video.widget_views_counter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类videos.models.Video
的用法示例。
在下文中一共展示了Video.widget_views_counter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: forwards
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import widget_views_counter [as 别名]
def forwards(self, orm):
try:
from videos.models import Video
except ImportError:
return
try:
from statistic import video_view_counter, sub_fetch_total_counter, \
widget_views_total_counter
except ImportError:
if settings.DEBUG:
return
raise Exception('Some redis utilits is unavailable, maybe this migration was not updated after refactoring. You can ignore this migration with: python manage.py migrate statistic 0074 --fake, but all statistic data will be lost.')
try:
video_view_counter.r.ping()
except ConnectionError:
if settings.DEBUG:
return
raise Exception('Redis server is unavailable. You can ignore this migration with: python manage.py migrate statistic 00074 --fake, but all statistic data will be lost.')
video_view_counter.delete()
sub_fetch_total_counter.delete()
widget_views_total_counter.delete()
for obj in orm.Video.objects.all():
video_counter = Video.view_counter(obj.video_id)
video_counter.delete()
video_counter.set(obj.view_count)
video_view_counter.incr(obj.view_count)
sub_fetch_total_counter.incr(obj.subtitles_fetched_count)
widget_views_total_counter.incr(Video.widget_views_counter(obj.video_id).get())
示例2: handle
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import widget_views_counter [as 别名]
def handle(self, *args, **kwargs):
try:
sub_fetch_keys_set.r.ping()
except:
if settings.DEBUG:
raise
self.handle_error('Statistic update error', '', sys.exc_info())
return
count = sub_fetch_keys_set.scard()
while count:
count -= 1
key = sub_fetch_keys_set.spop()
if not key:
break
print 'Handle key: %s' % key
parts = key.split(':')
d = date(int(parts[-1]), int(parts[-2]), int(parts[-3]))
if len(parts) == 6:
lang = parts[2]
else:
lang = ''
try:
video = Video.objects.get(video_id=parts[1])
except Video.DoesNotExist:
print 'Video does not exist'
default_connection.delete(key)
continue
counter_obj, created = SubtitleFetchCounters.objects.get_or_create(date=d, video=video, language=lang)
counter_obj.count += int(default_connection.getset(key, 0))
counter_obj.save()
count = changed_video_set.scard()
while count:
count -= 1
video_id = changed_video_set.spop()
if not video_id:
break
print 'Update statistic for video: %s' % video_id
subtitles_fetched_counter = Video.subtitles_fetched_counter(video_id, True)
widget_views_counter = Video.widget_views_counter(video_id, True)
view_counter = Video.view_counter(video_id, True)
Video.objects.filter(video_id=video_id).update(view_count=F('view_count')+view_counter.getset(0))
Video.objects.update(widget_views_count=F('widget_views_count')+widget_views_counter.getset(0))
Video.objects.update(subtitles_fetched_count=F('subtitles_fetched_count')+subtitles_fetched_counter.getset(0))
示例3: forwards
# 需要导入模块: from videos.models import Video [as 别名]
# 或者: from videos.models.Video import widget_views_counter [as 别名]
def forwards(self, orm):
if db.dry_run:
return
try:
from videos.models import Video, SubtitleLanguage
except ImportError:
return
try:
Video.widget_views_counter.r.ping()
except ConnectionError:
if settings.DEBUG:
return
raise Exception('Redis server is unavailable. You can ignore this migration with: python manage.py migrate videos 0068 --fake, but all statistic data will be lost.')
for obj in orm.Video.objects.all():
Video.subtitles_fetched_counter(obj.video_id).val = obj.subtitles_fetched_count
Video.widget_views_counter(obj.video_id).val = obj.widget_views_count
for obj in orm.SubtitleLanguage.objects.all():
SubtitleLanguage.subtitles_fetched_counter(obj.pk).val = obj.subtitles_fetched_count