本文整理汇总了Python中models.UserData.add方法的典型用法代码示例。如果您正苦于以下问题:Python UserData.add方法的具体用法?Python UserData.add怎么用?Python UserData.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.UserData
的用法示例。
在下文中一共展示了UserData.add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import add [as 别名]
def post(self):
params = self.request.params
if not 'domain' in params:
self.abort(404)
domain = get_domain_or_404(params['domain'])
if 'from' in params and 'firstvisit' in params:
if params['from'] == 'inside' and params['firstvisit'] == 'true':
# maybe use a transaction for these two independent database
# operations? maybe not: it doesn't really matter if an entity of
# UserData could be put while Domain failed or vice versa.
domain.increment_counter()
UserData.add(self.request, params['domain'])
# explicit request to have content-type application/json
self.response.headers['Content-Type'] = 'application/json'
self.response.write(domain.get_json())
示例2: test_userdata_add
# 需要导入模块: from models import UserData [as 别名]
# 或者: from models.UserData import add [as 别名]
def test_userdata_add(self):
remote_addr = '127.0.0.1'
http_user_agent = 'foo agent'
domain = 'foobar'
referer = None
class Request(object): pass
request = Request()
request.headers = {'HTTP_USER_AGENT': http_user_agent}
request.referer = referer
os.environ['REMOTE_ADDR'] = remote_addr
UserData.add(request, domain)
user_data = UserData.query(UserData.domain==domain).get()
self.assertEqual(user_data.remote_addr, remote_addr)
self.assertEqual(user_data.http_user_agent, http_user_agent)
self.assertEqual(user_data.referer, referer)