当前位置: 首页>>代码示例>>Python>>正文


Python UserData.add方法代码示例

本文整理汇总了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())
开发者ID:sebtesobe,项目名称:clickcounter-backend,代码行数:19,代码来源:handlers.py

示例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)
开发者ID:sebtesobe,项目名称:clickcounter-backend,代码行数:19,代码来源:tests.py


注:本文中的models.UserData.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。