本文整理汇总了Python中karma.manager.KarmaManager.user_data方法的典型用法代码示例。如果您正苦于以下问题:Python KarmaManager.user_data方法的具体用法?Python KarmaManager.user_data怎么用?Python KarmaManager.user_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类karma.manager.KarmaManager
的用法示例。
在下文中一共展示了KarmaManager.user_data方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: karma
# 需要导入模块: from karma.manager import KarmaManager [as 别名]
# 或者: from karma.manager.KarmaManager import user_data [as 别名]
def karma(request):
"""Admin view that displays karma related data."""
if not request.user.has_perm('users.view_karma_points'):
raise PermissionDenied
if request.POST.get('init'):
init_karma.delay()
messages.add_message(request, messages.SUCCESS,
'init_karma task queued!')
return HttpResponseRedirect(request.path)
if request.POST.get('recalculate'):
recalculate_karma_points.delay()
messages.add_message(request, messages.SUCCESS,
'recalculate_karma_points task queued!')
return HttpResponseRedirect(request.path)
if request.POST.get('update-top'):
update_top_contributors.delay()
messages.add_message(request, messages.SUCCESS,
'update_top_contributors task queued!')
return HttpResponseRedirect(request.path)
kmgr = KarmaManager()
top_alltime = [_user_karma_alltime(u, kmgr) for
u in kmgr.top_users('all') or []]
top_week = [_user_karma_week(u, kmgr) for
u in kmgr.top_users(daterange='1w') or []]
username = request.GET.get('username')
user_karma = None
if username:
try:
user = User.objects.get(username=username)
d = kmgr.user_data(user)
user_karma = [{'key': k, 'value': d[k]} for k in sorted(d.keys())]
except User.DoesNotExist:
pass
return render(
request,
'admin/karma.html',
{'title': 'Karma',
'top_alltime': top_alltime,
'top_week': top_week,
'username': username,
'user_karma': user_karma})