本文整理匯總了Python中models.Request.user_pk方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.user_pk方法的具體用法?Python Request.user_pk怎麽用?Python Request.user_pk使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Request
的用法示例。
在下文中一共展示了Request.user_pk方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_or_create_request
# 需要導入模塊: from models import Request [as 別名]
# 或者: from models.Request import user_pk [as 別名]
def get_or_create_request():
'''
Returns a request instance that is global for this request
If this function is called outside of a web request then the user_name is marked as system
'''
thread_ident = thread.get_ident()
request, rq = STATE.get(thread_ident, (None, None))
if not rq:
rq = Request()
if request:
rq.request_path = request.path
if request.user.is_anonymous():
rq.user_name = u'(Anonymous)'
else:
rq.user_pk = request.user.pk
rq.user_name = unicode(request.user)[:255]
else:
rq.user_name = u'(System)'
rq.save()
STATE[thread_ident] = (request, rq)
return rq