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


Python UserInfo.get_or_insert方法代码示例

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


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

示例1: submit_bm

# 需要导入模块: from models import UserInfo [as 别名]
# 或者: from models.UserInfo import get_or_insert [as 别名]
def submit_bm(feed, user, title, url, comment):
    bm = Bookmarks()

    result = urlfetch.fetch(url=url, follow_redirects=True, allow_truncated=True, deadline=60)
    if result.status_code == 200 and result.final_url:
        a = result.final_url
    elif result.status_code == 500:
        pass
    else:
        a = url

    url_candidate = a.lstrip().rstrip().split('?utm_source')[0].split('&feature')[0]

    url_parsed = urlparse(url_candidate)
    query = parse_qs(url_parsed.query)
    name = url_parsed.path.split('/')[-1]
    ext = name.split('.')[-1].lower()

    bm.title = url_candidate if title == '' or None else title

    if url_parsed.netloc == 'www.youtube.com':
        bm.url = 'http://www.youtube.com/watch?v=%s' % query["v"][0]
        bm.comment = """<embed
        width="640" height="360"
        src="http://www.youtube.com/v/%s"
        type="application/x-shockwave-flash">
        </embed>""" % query["v"][0]

    elif url_parsed.netloc == 'vimeo.com':
        bm.url = 'http://vimeo.com/%s' % name
        bm.comment = '''<iframe src="http://player.vimeo.com/video/%s?color=ffffff"
        width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen
        allowFullScreen></iframe>''' % name

    elif ext in ['jpg', 'png', 'jpeg', 'gif']:
        bm.url = url_candidate
        blob_key = upload_to_blobstore(url_candidate, ext)
        bm.comment = '<img src="%s" />' % images.get_serving_url(blob_key, size=1600)
    else:
        bm.comment = comment
        bm.url = url_candidate

    bm.domain = url_parsed.netloc
    bm.user = user
    bm.feed = feed
    bm.put()
    Bookmarks.index_bm(bm.key)

    copie = Bookmarks.query(Bookmarks.url == bm.url,
                            Bookmarks.user == user)

    if copie.get():
        ndb.delete_multi([cp.key for cp in copie])

    ui = UserInfo.get_or_insert(str(user.user_id()), user=user)
    if feed is None and ui.mys is True:
        deferred.defer(util.send_bm, bm.key, _queue="email")
    elif feed is not None and feed.get().notify == 'email':
        deferred.defer(util.send_bm, bm.key, _queue="email")
开发者ID:presveva,项目名称:gaeicious,代码行数:61,代码来源:submit.py


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