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


Python User.get方法代码示例

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


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

示例1: parse_signed_cookie

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def parse_signed_cookie(cookie_str):
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        id, expires, md5 = L
        if int(expires) < time.time():
            return None
        user = User.get(id)
        if user is None:
            return None
        if md5 != hashlib.md5('%s-%s-%s-%s' % (id, user.password, expires, _COOKIE_KEY)).hexdigest():
            return None
        return user
    except:
        return None 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:18,代码来源:urls.py

示例2: api_update_blog

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def api_update_blog(blog_id):
    check_admin()
    i = ctx.request.input(name='', summary='', content='')
    name = i.name.strip()
    summary = i.summary.strip()
    content = i.content.strip()
    if not name:
        raise APIValueError('name', 'name cannot be empty.')
    if not summary:
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    blog = Blog.get(blog_id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    blog.name = name
    blog.summary = summary
    blog.content = content
    blog.update()
    return blog 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:22,代码来源:urls.py

示例3: set_notifications

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def set_notifications(bot, update, value: bool):
    cid = update.effective_chat.id
    try:
        notifications = Notifications.get(Notifications.chat_id == cid)
    except Notifications.DoesNotExist:
        notifications = Notifications(chat_id=cid)
    notifications.enabled = value
    notifications.save()

    Statistic.of(update, ('enabled' if value else 'disabled') + ' notifications for their group {}'.format(
        cid))

    msg = util.success("Nice! Notifications enabled.") if value else "Ok, notifications disabled."
    msg += '\nYou can always adjust this setting with the /subscribe command.'
    bot.formatter.send_or_edit(cid, msg, to_edit=util.mid_from_update(update))
    return ConversationHandler.END 
开发者ID:JosXa,项目名称:BotListBot,代码行数:18,代码来源:misc.py

示例4: parse_signed_cookie

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def parse_signed_cookie(cookie_str):
    try:
        L = cookie_str.split('-')
        if len(L) != 3:
            return None
        id, expires, md5 = L
        if int(expires) < time.time():
            return None
        user = User.get(id)
        if user is None:
            return None
        if md5 != hashlib.md5(('%s-%s-%s-%s' % (id, user.password, expires, _COOKIE_KEY)).encode('utf-8')).hexdigest():
            return None
        return user
    except:
        return None 
开发者ID:caolinjian,项目名称:awesome-python3-webapp,代码行数:18,代码来源:urls.py

示例5: test_atomic_with_delete

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def test_atomic_with_delete(flushdb):
    for i in range(3):
        await User.create(username=f'u{i}')

    async with db.atomic():
        user = await User.get(User.username == 'u1')
        await user.delete_instance()

    usernames = [u.username async for u in User.select()]
    assert sorted(usernames) == ['u0', 'u2']

    async with db.atomic():
        async with db.atomic():
            user = await User.get(User.username == 'u2')
            await user.delete_instance()

    usernames = [u.username async for u in User.select()]
    assert usernames == ['u0'] 
开发者ID:kszucs,项目名称:aiopeewee,代码行数:20,代码来源:test_transactions.py

示例6: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def post(self):
        url = self.get_argument('url', None)
        if not url:
            self.render("tools/save-video.html", url = url, title = None, description=None)
        url = Sourcefile.make_oembed_url(url.strip())
        if url:
            current_user = self.get_current_user_object();
            shake_id = self.get_argument('shake_id', None)
            if not shake_id:
                self.destination_shake = Shake.get('user_id=%s and type=%s', current_user.id, 'user')
            else:
                self.destination_shake = Shake.get('id=%s', shake_id)
                if not self.destination_shake:
                    return self.render("tools/save-video-error.html", message="We couldn't save the video to specified shake. Please contact support.")
                if not self.destination_shake.can_update(current_user.id):
                    return self.render("tools/save-video-error.html", message="We couldn't save the video to specified shake. Please contact support.")
                if current_user.email_confirmed != 1:
                    return self.render("tools/save-video-error.html", message="You must confirm your email address before you can post.")
            self.handle_oembed_url(url)
        else:
            self.render("tools/save-video-error.html", message="We could not load the embed code. The video server may be down. Please contact support.") 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:23,代码来源:tools.py

示例7: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def get(self, share_key):
        sharedfile = Sharedfile.get_by_share_key(share_key)
        if not sharedfile:
            raise tornado.web.HTTPError(404)

        expanded = self.get_argument("expanded", False)
        if expanded:
            expanded = True

        # Prevent IE from caching AJAX requests
        self.set_header("Cache-Control","no-store, no-cache, must-revalidate");
        self.set_header("Pragma","no-cache");
        self.set_header("Expires", 0);

        user = self.get_current_user_object()
        can_comment = user and user.email_confirmed == 1 and not options.readonly

        comments = sharedfile.comments()
        html_response = self.render_string("image/quick-comments.html", sharedfile=sharedfile,
            comments=comments, current_user=user,
            can_comment=can_comment,
            expanded=expanded)
        return self.write({'result' : 'ok', 'count' : len(comments), 'html' : html_response }) 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:25,代码来源:image.py

示例8: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def post(self, share_key, shake_id):
        current_user = self.get_current_user_object()
        sharedfile = Sharedfile.get_by_share_key(share_key)
        shake = Shake.get("id = %s", shake_id)
        if not sharedfile:
            raise tornado.web.HTTPError(404)
        if not shake:
            raise tornado.web.HTTPError(404)
        if not sharedfile.can_user_delete_from_shake(current_user, shake):
            raise tornado.web.HTTPError(403)
        sharedfile.delete_from_shake(shake)
        redirect_to = self.get_argument("redirect_to", None)
        if redirect_to:
            return self.redirect(redirect_to)
        else:
            return self.redirect("/p/%s" % sharedfile.share_key) 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:18,代码来源:image.py

示例9: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def get(self, shake_name):
        shake = Shake.get("name=%s and deleted=0", shake_name)
        if not shake:
            raise tornado.web.HTTPError(404)

        value = {
            'title' : escape.xhtml_escape(shake.title) if shake.title else '',
            'title_raw' : shake.title if shake.title else '',
            'description' : escape.xhtml_escape(shake.description) if shake.description else '',
            'description_raw' : shake.description if shake.description else ''
        }
        # prevents IE from caching ajax requests.
        self.set_header("Cache-Control","no-store, no-cache, must-revalidate");
        self.set_header("Pragma","no-cache");
        self.set_header("Expires", 0);
        return self.write(escape.json_encode(value)) 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:18,代码来源:shake.py

示例10: post

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def post(self, shake_name):
        current_user = self.get_current_user_object()
        shake_to_update = Shake.get('name=%s and user_id=%s and type=%s and deleted=0', shake_name, current_user.id, 'group')
        new_title = self.get_argument('title', None)
        new_description = self.get_argument('description', None)

        if not shake_to_update:
            return self.write({'error':'No permission to update shake.'})

        if new_title:
            shake_to_update.title = new_title
        if new_description:
            shake_to_update.description = new_description
        shake_to_update.save()

        return self.redirect('/shake/' + shake_to_update.name + '/quick-details') 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:18,代码来源:shake.py

示例11: get

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def get(self):
        where = "deleted=0 ORDER BY id DESC LIMIT 21"
        before_id = self.get_argument('before', None)
        if before_id is not None:
            where = "id < %d AND %s" % (int(before_id), where)
        users = User.where(where)

        prev_link = None
        next_link = None
        if len(users) == 21:
            next_link = "?before=%d" % users[-1].id

        for user in users[:20]:
            files = user.sharedfiles(per_page=1)
            user.last_sharedfile = len(files) == 1 and files[0] or None

        return self.render("admin/new-users.html", users=users[:20],
            previous_link=prev_link, next_link=next_link) 
开发者ID:MLTSHP,项目名称:mltshp,代码行数:20,代码来源:admin.py

示例12: _get_page_index

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def _get_page_index():
    page_index = 1
    try:
        page_index = int(ctx.request.get('page', '1'))
    except ValueError:
        pass
    return page_index 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:9,代码来源:urls.py

示例13: user_interceptor

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def user_interceptor(next):
    logging.info('try to bind user from session cookie...')
    user = None
    cookie = ctx.request.cookies.get(_COOKIE_NAME)
    if cookie:
        logging.info('parse session cookie...')
        user = parse_signed_cookie(cookie)
        if user:
            logging.info('bind user <%s> to session...' % user.email)
    ctx.request.user = user
    return next() 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:13,代码来源:urls.py

示例14: blog

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def blog(blog_id):
    blog = Blog.get(blog_id)
    if blog is None:
        raise notfound()
    blog.html_content = markdown2.markdown(blog.content)
    comments = Comment.find_by(
        'where blog_id=? order by created_at desc limit 1000', blog_id)
    return dict(blog=blog, comments=comments, user=ctx.request.user) 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:10,代码来源:urls.py

示例15: manage_blogs_edit

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get [as 别名]
def manage_blogs_edit(blog_id):
    blog = Blog.get(blog_id)
    print blog
    if blog is None:
        raise notfound()
    return dict(id=blog.id, name=blog.name, summary=blog.summary, content=blog.content, action='/api/blogs/%s' % blog_id, redirect='/manage/blogs', user=ctx.request.user) 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:8,代码来源:urls.py


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