• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python settings.lazy_gettext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中settings.lazy_gettext函数的典型用法代码示例。如果您正苦于以下问题:Python lazy_gettext函数的具体用法?Python lazy_gettext怎么用?Python lazy_gettext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: get_post

def get_post(id):
    """get a post.
    Args:
        id: post id
    Returns:
        post: a dict of post"""

    key = POST_CACHE_KEY % id

    post = memcache.get(key)
    if post is None:
        post = apis.Post.get_by_id(id)
        if post:
            post = post.to_dict()
            memcache.set(key, post)

    if not post:
        raise Exception(lazy_gettext(MSG_NO_POST, id=id))

    if not post["public"]:
        cur_user = apis.User.get_current_user()
        if not cur_user.is_admin():
            raise Exception(lazy_gettext(MSG_UNAUTHORIZED))

    return {
        "post": post
    }
开发者ID:errorcode7,项目名称:me,代码行数:27,代码来源:ajax.py


示例2: update_user_profile

def update_user_profile(id, **profile):
    """update user profile.
    Args:
        id: string of user id
        profile: a dict of user profile
    Returns:
        user: a dict of user profile"""

    user = apis.User.get_by_id(id)
    if not user:
        raise Exception(lazy_gettext(MSG_NO_USER, id=id))

    cur_user = apis.User.get_current_user()

    if cur_user.is_owner():
        pass
    elif user == cur_user:
        if "role" in profile:
            raise Exception(lazy_gettext(MSG_UNAUTHORIZED))
    else:
        raise Exception(lazy_gettext(MSG_UNAUTHORIZED))

    user.update(**profile)

    result = {
        "user": user
    }
    return result
开发者ID:errorcode7,项目名称:me,代码行数:28,代码来源:ajax.py


示例3: get_posts_by_category

def get_posts_by_category(category="", page=1, per_page=10, group_by="", start_cursor=""):
    """get all posts of a category.
    Args:
        category: category id or url, if "", return all posts
        page: page number starts from 1
        per_page: item count per page
        start_cursor: GAE data store cursor
    Returns:
        pager: a pager
        posts: list of post"""

    try:
        if isinstance(category, int):
            category = get_category(id=category)["category"]
        else:
            category = get_category(url=category)["category"]
    except:
        raise Exception(lazy_gettext(MSG_ERROR_CATEGORY, id=category))

    if not category:
        raise Exception(lazy_gettext(MSG_NO_CATEGORY, id=category))

    cur_user = apis.User.get_current_user()
    get_no_published = cur_user.is_admin()

    result = {
        "pager": {
            "cur_page": page,
            "per_page": per_page,
            "group_by": group_by,
            "start_cursor": start_cursor,
        },
        "category": category,
    }

    if page <= CATEGORY_CACHE_PAGES:  # cache only CATEGORY_CACHE_PAGES pages
        key = CATEGORY_CACHE_KEY % (category.id, page, per_page, get_no_published)
        res = memcache.get(key)

        if res is None:
            posts, end_cursor = category.get_posts(page, per_page, get_no_published, start_cursor)
            posts = [post.to_dict() for post in posts]
            memcache.set(key, (posts, end_cursor))
        else:
            posts, end_cursor = res
    else:
        posts, end_cursor = category.get_posts(page, per_page, get_no_published, start_cursor)

    result["posts"] = posts
    result["pager"]["start_cursor"] = end_cursor
    result["pager"]["is_last_page"] = len(posts) < per_page
    if group_by:
        result["group_posts"] = apis.group_by(posts, group_by)

    return result
开发者ID:errorcode7,项目名称:me,代码行数:55,代码来源:ajax.py


示例4: get_posts_by_tag

def get_posts_by_tag(name, page=1, per_page=10):
    """get posts by tag.
    Args:
        name: tag name
        page: page number, starts with 1
        per_page: post count per page
    Returns:
        tag: a tag
        pager: a pager
        posts: a list of posts"""

    tag = apis.Tag.get_tag_by_name(name)
    if not tag:
        raise Exception(lazy_gettext(MSG_NO_TAG, name=name))

    key = TAG_POSTS_CACHE_KEY % (tag.name, page, per_page)

    posts = memcache.get(key)
    if posts is None:
        posts = [post.to_dict() for post in tag.get_posts(page, per_page)]
        memcache.set(key, posts, 3600)  # cache 1 hour

    result = {
        "tag": tag.to_dict(),
        "pager": {
            "cur_page": page,
            "per_page": per_page,
            "is_last_page": len(posts) < per_page
        },
        "posts": posts
    }

    return result
开发者ID:errorcode7,项目名称:me,代码行数:33,代码来源:ajax.py


示例5: create_user

def create_user(**settings):
    """create a new user.
    Args:
        settings: a dict of user settings
    Returns:
        user: a dict of user"""

    if "email" not in settings:
        raise Exception(lazy_gettext("email is required"))

    if "password" not in settings:
        raise Exception(lazy_gettext("password is required"))

    user = apis.User.create_user(**settings)

    result = {
        "user": user
    }
    return result
开发者ID:errorcode7,项目名称:me,代码行数:19,代码来源:ajax.py


示例6: delete_user

def delete_user(id):
    """delete a user.
    Args:
        id: string of user id
    Returns:
        user: a dict of deleted user"""

    user = apis.User.get_by_id(id)
    if not user:
        raise Exception(lazy_gettext(MSG_NO_USER, id=id))

    if user.is_owner():
        raise Exception(lazy_gettext("can not delete owner"))

    result = {
        "user": user.to_dict(),
    }
    user.delete()

    return result
开发者ID:errorcode7,项目名称:me,代码行数:20,代码来源:ajax.py


示例7: get_category

def get_category(id=None, url=None):
    """get category by id or url
    Args:
        id: category id
        url: category url
    Returns:
        category: a dict of category
    """
    if id is not None:
        category = apis.Category.get_by_id(id)
    elif url is not None:
         category = apis.Category.get_by_url(url)
    else:
        raise Exception(lazy_gettext("pls input id or url"))

    if not category:
        raise Exception(lazy_gettext(MSG_NO_CATEGORY, id=id))

    return {
        "category": category
    }
开发者ID:errorcode7,项目名称:me,代码行数:21,代码来源:ajax.py


示例8: get_comment

def get_comment(id):
    """get comment by id.
    Args:
        id: comment id
    Returns:
        comment: comment"""
    comment = apis.Comment.get_by_id(id)
    if not comment:
        raise Exception(lazy_gettext(MSG_NO_COMMENT, id=id))

    return {
        "comment": comment
    }
开发者ID:errorcode7,项目名称:me,代码行数:13,代码来源:ajax.py


示例9: delete_category

def delete_category(id):
    """delete a category.
    Args:
        id: string of category id
    Returns:
        category: category id"""

    category = apis.Category.get_by_id(id)
    if not category:
        raise Exception(lazy_gettext(MSG_NO_CATEGORY, id=id))

    if category.url == "":
        raise Exception(lazy_gettext("can not delete Home category"))

    _delete_category_posts_cache(category)

    result = {
        "category": category.to_dict(),
    }
    category.delete()

    return result
开发者ID:errorcode7,项目名称:me,代码行数:22,代码来源:ajax.py


示例10: get_photo

def get_photo(id):
    """get photo by id.
    Args:
        id: photo id
    Returns:
        photo: photo"""
    photo = apis.Photo.get_by_id(id)
    if not photo:
        raise Exception(lazy_gettext(MSG_NO_PHOTO, id=id))

    return {
        "photo": photo
    }
开发者ID:errorcode7,项目名称:me,代码行数:13,代码来源:ajax.py


示例11: delete_photo

def delete_photo(id):
    """date a photo.
    Args:
        id: photo id
    Returns:
        photo: a dict of photo"""

    photo = apis.Photo.get_by_id(id)
    if not photo:
        raise Exception(lazy_gettext(MSG_NO_PHOTO, id=id))

    result = {
        "photo": photo.to_dict(),
    }

    photo.delete()

    return result
开发者ID:errorcode7,项目名称:me,代码行数:18,代码来源:ajax.py


示例12: update_photo

def update_photo(id, **settings):
    """update a photo.
    Args:
        id: photo id
        settings: settings of photo
    Returns:
        photo: a dict of photo"""

    photo = apis.Photo.get_by_id(id)
    if not photo:
        raise Exception(lazy_gettext(MSG_NO_PHOTO, id=id))

    photo.update(**settings)

    result = {
        "photo": photo,
    }
    return result
开发者ID:errorcode7,项目名称:me,代码行数:18,代码来源:ajax.py


示例13: delete_comment

def delete_comment(id):
    """date a comment.
    Args:
        id: comment id
    Returns:
        comment: a dict of comment"""
    comment = apis.Comment.get_by_id(id)
    if not comment:
        raise Exception(lazy_gettext(MSG_NO_COMMENT, id=id))

    _delete_comments_cache(comment.post_id)

    comment.delete()

    result = {
        "comment": comment,
    }

    return result
开发者ID:errorcode7,项目名称:me,代码行数:19,代码来源:ajax.py


示例14: update_category

def update_category(id, **settings):
    """update category settings.
    Args:
        id: string of category id
        settings: a dict of category settings
    Returns:
        category: a dict of category"""

    category = apis.Category.get_by_id(id)
    if not category:
        raise Exception(lazy_gettext(MSG_NO_CATEGORY, id=id))

    _delete_category_posts_cache(category)
    category.update(**settings)

    result = {
        "category": category
    }
    return result
开发者ID:errorcode7,项目名称:me,代码行数:19,代码来源:ajax.py


示例15: get_comments_by_post

def get_comments_by_post(id):
    """get comments by post.
    Args:
        id: post id
    Returns:
        comments: a list of comments"""
    post = apis.Post.get_by_id(id)
    if not post:
        raise Exception(lazy_gettext(MSG_NO_POST, id=id))

    key = COMMENT_CACHE_KEY % id

    comments = memcache.get(key)
    if comments is None:
        comments = [comment.to_dict() for comment in post.Comments]
        memcache.set(key, comments)

    result = {
        "comments": comments
    }
    return result
开发者ID:errorcode7,项目名称:me,代码行数:21,代码来源:ajax.py


示例16: delete_post

def delete_post(id):
    """delete a post.
    Args:
        id: post id
    Returns:
        post: a dict of post"""

    post = apis.Post.get_by_id(id)
    if not post:
        raise Exception(lazy_gettext(MSG_NO_POST, id=id))

    _delete_post_cache(post)
    _delete_category_posts_cache(post.category)

    result = {
        "post": post.to_dict(),
    }

    post.delete()

    return result
开发者ID:errorcode7,项目名称:me,代码行数:21,代码来源:ajax.py


示例17: create_comment

def create_comment(post_id, author, content, parent_id=-1):
    """create a new comment in a post.
    Args:
        post_id: id of post
        author: author name
        content: content
    Returns:
        comment: comment"""

    post = apis.Post.get_by_id(post_id)
    if not post:
        raise Exception(lazy_gettext(MSG_NO_POST, id=post_id))

    comment = apis.Comment.add_comment(author, content, post_id, parent_id)

    _delete_comments_cache(post_id)

    result = {
        "comment": comment
    }
    return result
开发者ID:errorcode7,项目名称:me,代码行数:21,代码来源:ajax.py


示例18: update_post

def update_post(id, **settings):
    """update a post.
    Args:
        id: post id
        settings: a dict of post settings
    Returns:
        post: a dict of post"""

    post = apis.Post.get_by_id(id)
    if not post:
        raise Exception(lazy_gettext(MSG_NO_POST, id=id))

    _delete_post_cache(post)
    _delete_category_posts_cache(post.category)

    post.update(**settings)

    _delete_category_posts_cache(post.category)

    result = {
        "post": post
    }
    return result
开发者ID:errorcode7,项目名称:me,代码行数:23,代码来源:ajax.py


示例19: get_site_settings

    context.update({
        "user": User.get_current_user(),
        "settings": get_site_settings(),
    })
    return flask_render_template(template_name_or_list, **context)

############################################
## Users
############################################
from settings import login_manager, lazy_gettext
from flask.ext.login import login_required,logout_user
from flask.ext.login import login_user as _login_user

login_manager.anonymous_user = Anonymous
login_manager.login_view = "login"
login_manager.login_message = lazy_gettext("Please login to access this page")


@login_manager.user_loader
def load_user(user_id):
    """flask.login user_loader callback"""
    return User.load_user(user_id)


def login_user(email, password, remember=False):
    """check and login user"""
    user = User.check_user(email, password)
    if user and user.is_active():
        _login_user(user, remember)
        return user
    return False
开发者ID:MwzkQmuUZkFLbXm,项目名称:me,代码行数:31,代码来源:utils.py


示例20: _get_method_doc

def _get_method_doc(method_name):
    method = AJAX_METHODS.get(method_name)
    if method:
        return method.func_doc
    else:
        return lazy_gettext("unsupported method [ %(name)s]", name=method_name)
开发者ID:errorcode7,项目名称:me,代码行数:6,代码来源:ajax.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python settings.load函数代码示例发布时间:2022-05-27
下一篇:
Python settings.init函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap