本文整理汇总了Python中models.Platform.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Platform.get_by_id方法的具体用法?Python Platform.get_by_id怎么用?Python Platform.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Platform
的用法示例。
在下文中一共展示了Platform.get_by_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Platform [as 别名]
# 或者: from models.Platform import get_by_id [as 别名]
def get(self, campaign_id, platform_name):
"""
Handles incoming clicks for given campaign_id and platform_name.
If click is valid then user is redirected to url defined in the campaign
and statistic about this click is saved. All invalid clicks (e.g. for non
existing campaigns, platforms) users are redirected to http://outfit7.com.
"""
# cast campaign_id, type checking is done through route definition
try:
campaign_id = int(campaign_id)
except ValueError:
return webapp2.redirect("http://outfit7.com", permanent=True)
platform_id = "%d-%s" % (campaign_id, platform_name)
platform = Platform.get_by_id(platform_id)
if platform:
memcache.incr(platform_id, 1, namespace="counters", initial_value=0)
try:
deferred.defer(Platform.increment, platform_id, _countdown=TRACKER_COUNTER_UPDATE_INTERVAL_LENGTH,
_name="%s-%d" % (platform_id, get_interval_index()))
except (taskqueue.TaskAlreadyExistsError, taskqueue.TombstonedTaskError), e:
pass
# TODO: optimize with async operations
campaign = Campaign.get_by_id(campaign_id)
return webapp2.redirect(campaign.link.encode("utf8"))