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


Python settings.lazy_gettext函数代码示例

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


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


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