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


Python Customer.get方法代码示例

本文整理汇总了Python中models.Customer.get方法的典型用法代码示例。如果您正苦于以下问题:Python Customer.get方法的具体用法?Python Customer.get怎么用?Python Customer.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Customer的用法示例。


在下文中一共展示了Customer.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get

# 需要导入模块: from models import Customer [as 别名]
# 或者: from models.Customer import get [as 别名]
    def test_get(self):
        c = Customer(name='foobar', sites=["foo.com", "bar.co.uk"])
        self.session.add(c)
        self.session.commit()

        b = Customer.get(c.id)
        self.assertEqual(c.id,    b.id)
        self.assertEqual(c.name,  b.name)
        self.assertEqual(c.sites, b.sites)
开发者ID:venkateshRS,项目名称:ape,代码行数:11,代码来源:tests.py

示例2: beacon

# 需要导入模块: from models import Customer [as 别名]
# 或者: from models.Customer import get [as 别名]
def beacon():

    global JSONP_CALLBACK
    JSONP_CALLBACK = request.args.get('jsonp', "_ape.callback")

    # Get args data or defaults
    args = dict()
    args['jsonp']          = JSONP_CALLBACK                 # JSONP callback function
    args['visitor_id']     = request.args.get('cc', "")     # The APE cookie visitor_id
    args['debug']          = request.args.get('db', "")     # Debug switch
    args['page_url']       = request.args.get('dl', "")     # Page URL
    args['referrer_url']   = request.args.get('dr', "")     # Referrer URL if set
    args['page_title']     = request.args.get('dt', "")     # Page title
    args['event']          = request.args.get('ev', "")     # Event
    args['customer_id']    = request.args.get('id', "")     # The customer account ID
    args['timestamp']      = request.args.get('ld', "")     # Event timestamp
    args['language']       = request.args.get('lg', "")     # Browser language
    args['placeholders']   = request.args.get('pc', "")     # The set of Placeholder ids on this page
    args['prefix']         = request.args.get('px', "ape")  # Placeholder class prefix
    args['screen_colour']  = request.args.get('sc', 0)      # Screen colour depth
    args['screen_height']  = request.args.get('sh', 0)      # Screen height
    args['screen_width']   = request.args.get('sw', 0)      # Screen width
    args['user_agent']     = request.args.get('ua', "")     # User Agent
    args['script_version'] = request.args.get('vr', "0.0")  # Version number of this script

    # Ensure page url and customer id are provided
    if not args['page_url']:    raise BadRequest("Bad Request: Value required for page url (dl)")
    if not args['customer_id']: raise BadRequest("Bad Request: Value required for customer id (id)")

    # Extract placeholder identifiers
    placeholders = args['placeholders'].split(' ')
    prefix = "%s-" % args['prefix']
    args['placeholder_ids'] = [c.lstrip(prefix) for c in placeholders if c.startswith(prefix)]

    # Deserialise timestamp
    try:
        args['timestamp'] = DT.datetime.utcfromtimestamp(int(args['timestamp']) / 1000)
    except ValueError:
        args['timestamp'] = DT.datetime.now()

    # Convert values to base data types
    args['screen_width']  = int(args['screen_width'])
    args['screen_height'] = int(args['screen_height'])
    args['screen_colour'] = int(args['screen_colour'])
    args['debug']         = (args['debug'] == "true")

    # The response payload
    payload = dict()

    # Respect Do Not Track
    if request.headers.get('DNT', False):
        raise Conflict("Do Not Track enabled on client")
    
    # Return args in payload in debug mode
    if args['debug']:
        payload['args'] = args

    # Get customer record
    customer = Customer.get(id=args['customer_id'])
    if customer:
        
        # Ensure customer account_id is valid for this page url
        if customer.is_site_owner(url=args['page_url']):
        
            # Get/create visitor record for this customer
            visitor = customer.get_visitor(id=args['visitor_id'])
            payload['visitor_id'] = visitor.id
        
            # Update visitor data from payload args
            visitor.update_with_data(data=args)

            # Ensure we have placeholder ids (hence there are ads on the page)
            if args['placeholder_ids']:

                # Get personalised components for this visitor for these placeholders
                components = visitor.components(ad_ids=args['placeholder_ids'])
                
                # Format components for json response
                payload['components'] = dict()
                for component in components:
                    key = "%s-%s" % (args['prefix'], component.id)
                    payload['components'][key] = dict()
                    payload['components'][key]['id']      = component.id
                    payload['components'][key]['styles']  = component.styles
                    payload['components'][key]['content'] = component.content
    
    return make_jsonp_response(payload)
开发者ID:venkateshRS,项目名称:ape,代码行数:89,代码来源:app.py


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