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


Python Place.get_by_id方法代码示例

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


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

示例1: place_page

# 需要导入模块: from models import Place [as 别名]
# 或者: from models.Place import get_by_id [as 别名]
def place_page(place_id=None):
    if request.method == 'POST':
        p = Place.get_by_id(place_id)

        # for add subscriber form
        if 'email' in request.form:
            email = request.form.get('email', '')
            if email not in [u.email for u in User.all()]:
                u = User(
                    email=email,
                    suscribed_at=datetime.datetime.now())
                u.put()
            else:
                u = User.gql("WHERE email = '{0}'".format(email)).get()

            up = UserPlace.all().filter('user =', u).filter('place =', p).get()
            
            if up:
                return "This user already exists in subscribers!"
            else:
                if u.places_subscribed.count() >= 4:
                    return "This user has maximum subscribing"
                up = UserPlace(
                    user=u,
                    place=p
                )
                up.put()

        # for add update form
        elif 'update_link' in request.form and 'update_info' in request.form:
            update_link = request.form.get('update_link', '')
            update_info = request.form.get('update_info', '')
            u = Update(
                place=p,
                link=update_link,
                info=update_info
            )
            u.put()

        # for add link form
        elif 'link_link' in request.form and 'link_description' in request.form:
            link_link = request.form.get('link_link', '')
            link_description = request.form.get('link_description', '')
            l = PlaceLink(
                place=p,
                link=link_link,
                description=link_description
            )
            l.put()

    p = Place.get_by_id(place_id)
    updates = [update for update in p.place_updates.order('-added_at')]
    links = [link for link in p.placelink_set.order('-added_at')]

    return render_template('place.html', place=p, updates=updates, links=links)
开发者ID:gromadco,项目名称:locograph,代码行数:57,代码来源:main.py


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