本文整理匯總了Python中questions.models.Answer.last_activity_for方法的典型用法代碼示例。如果您正苦於以下問題:Python Answer.last_activity_for方法的具體用法?Python Answer.last_activity_for怎麽用?Python Answer.last_activity_for使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類questions.models.Answer
的用法示例。
在下文中一共展示了Answer.last_activity_for方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: users
# 需要導入模塊: from questions.models import Answer [as 別名]
# 或者: from questions.models.Answer import last_activity_for [as 別名]
def users(request):
"""Returns list of user karma information.
GET paramaters:
* daterange - 7d, 1m, 3m, 6m or 1y (default: 1y)
* sort - field to sort on (default: points). Order is always descending.
* page - starts at 1 (default: 1)
* pagesize - (default: 100)
Returns list of objects with the following fields:
userid, username, points, <action_types>
"""
form = UserAPIForm(request.GET)
if not form.is_valid():
return {'success': False, 'errors': form.errors}
daterange = form.cleaned_data.get('daterange') or '1y'
sort = form.cleaned_data.get('sort') or 'points'
page = form.cleaned_data.get('page') or 1
pagesize = form.cleaned_data.get('pagesize') or 100
mgr = KarmaManager()
users = mgr.top_users(daterange=daterange, type=sort, count=pagesize,
offset=(page - 1) * pagesize) or []
now = datetime.now()
action_types = KarmaManager.action_types.keys()
schema = ['id', 'username', 'lastactivity', 'points'] + action_types
user_list = []
for u in users:
user = [u.id, u.username]
last_activity = Answer.last_activity_for(u)
user.append((now - last_activity).days if last_activity else None)
user.append(mgr.count(u, daterange=daterange, type='points'))
for t in action_types:
user.append(mgr.count(u, daterange=daterange, type=t))
user_list.append(user)
return {
'success': True,
'results': user_list,
'schema': schema}
示例2: users
# 需要導入模塊: from questions.models import Answer [as 別名]
# 或者: from questions.models.Answer import last_activity_for [as 別名]
def users(request):
"""Returns list of user karma information.
GET paramaters:
* daterange - 7d, 1m, 3m, 6m or 1y (default: 1y)
* sort - field to sort on (default: points). Order is always descending.
* page - starts at 1 (default: 1)
* pagesize - (default: 100)
Returns list of objects with the following fields:
userid, username, points, <action_types>
"""
form = UserAPIForm(request.GET)
if not form.is_valid():
return {"success": False, "errors": form.errors}
daterange = form.cleaned_data.get("daterange") or "1y"
sort = form.cleaned_data.get("sort") or "points"
page = form.cleaned_data.get("page") or 1
pagesize = form.cleaned_data.get("pagesize") or 100
mgr = KarmaManager()
users = mgr.top_users(daterange, type=sort, count=pagesize, offset=(page - 1) * pagesize) or []
now = datetime.now()
action_types = KarmaManager.action_types.keys()
schema = ["id", "username", "lastactivity", "points"] + action_types
user_list = []
for u in users:
user = [u.id, u.username]
last_activity = Answer.last_activity_for(u)
user.append((now - last_activity).days if last_activity else None)
user.append(mgr.count(daterange, u, type="points"))
for t in action_types:
user.append(mgr.count(daterange, u, type=t))
user_list.append(user)
return {"success": True, "results": user_list, "schema": schema}