本文整理汇总了Python中models.Profile.profile方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.profile方法的具体用法?Python Profile.profile怎么用?Python Profile.profile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Profile
的用法示例。
在下文中一共展示了Profile.profile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_request
# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import profile [as 别名]
def process_request(self, request):
ua = request.META.get('HTTP_USER_AGENT', '')
# Load from cache/DB based on user agent string
key = 'profile::%s' % (md5(ua).hexdigest()) # Sanitise to avoid memcache warnings.
server = cache.get(key)
if server is None:
try:
server = Profile.objects.get(user_agent=ua)
except Profile.DoesNotExist:
server = Profile(user_agent=ua)
cache.set(key, server)
# Load data from the cookie
cookie = request.COOKIES.get('profile', '{"profile": false}')
cookie = urllib.unquote(cookie).decode('utf8')
# Merge the cookie and server profile.
client = simplejson.loads(cookie)
merged = combine(server.profile, client)
# If it's changed, sore to DB and cache.
if merged != server.profile or not server.pk:
server.profile = merged
server.save()
cache.set(key, server)
# Make available on the request object.
request.profile = server.profile