Ejemplo n.º 1
0
def get_revisions(handler, article_id):
    if not isinstance(article_id, (int, long)):
        raise TypeError('Article id must be an integer')

    rpc = model.get_rpc()
    query = model.ArticleRevision.all_for_article(article_id)
    revisions = query.order('-created').fetch(10, rpc=rpc)
    return [get_revision_dict(revision) for revision in revisions]
Ejemplo n.º 2
0
def get_comments(handler, article_id):
    if not isinstance(article_id, (int, long)):
        raise TypeError('Article id must be an integer')

    rpc = model.get_rpc()
    query = model.ArticleComment.all_for_article(article_id)
    comments = query.order('created').fetch(50, rpc=rpc)
    return [get_comment_dict(comment) for comment in comments]
Ejemplo n.º 3
0
def get_articles(handler, order, limit=50, include_content=False,
        include_unpublished=False):
    query = model.Article.all().order(order)
    if not include_unpublished:
        query = query.filter('published', True)

    rpc = model.get_rpc()
    articles = query.fetch(limit, rpc=rpc)
    return [get_article_dict(article, include_content) for article in articles]
Ejemplo n.º 4
0
def get_files(handler, article_id):
    if not isinstance(article_id, (int, long)):
        raise TypeError('Article id must be an integer')

    rpc = model.get_rpc()
    query = model.Blob.all() \
        .filter('owner', model.get_key(article_id, model.Article)) \
        .order('-created')
    files = query.fetch(10, rpc=rpc)
    return [get_blob_dict(file) for file in files]
Ejemplo n.º 5
0
def get_articles_by_user(handler, user_id):
    if not isinstance(user_id, (int, long)):
        raise TypeError('User id must be an integer')

    user_key = model.get_key(user_id, model.User)

    rpc = model.get_rpc()
    articles = model.Article.all() \
        .filter('user', user_key) \
        .order('-last_modified') \
        .fetch(50, rpc=rpc)

    return [get_article_dict(article) for article in articles]
Ejemplo n.º 6
0
def get_user_info(handler, id=None):
    """Returns information about a user. The current user is returned if no id
    is specified.

    """
    if id:
        rpc = model.get_rpc()
        user = model.User.get_by_id(id, rpc=rpc)
        if not user:
            raise simpleeditions.UserNotFoundError(
                'Could not find user with id %r.' % id)
        return get_user_dict(user)
    else:
        # This behavior is slightly backwards, with the controller getting data
        # from a view-provided value, but it's necessary to avoid getting the
        # user more than once.
        return handler.user
Ejemplo n.º 7
0
def get_user_info(handler, id=None):
    """Returns information about a user. The current user is returned if no id
    is specified. The id can also be the canonical display name of the user.

    """
    if id:
        rpc = model.get_rpc()
        if isinstance(id, (int, long)):
            user = model.User.get_by_id(id, rpc=rpc)
        else:
            user = model.User.all().filter('canonical_name', id).get(rpc=rpc)

        if not user:
            raise simpleeditions.UserNotFoundError(
                'Could not find user with id %r.' % id)
        return get_user_dict(user)
    else:
        # This behavior is slightly backwards, with the controller getting data
        # from a view-provided value, but it's necessary to avoid getting the
        # user more than once.
        return handler.user
Ejemplo n.º 8
0
def get_revisions(handler, article_id):
    rpc = model.get_rpc()
    query = model.ArticleRevision.all_for_article(int(article_id))
    revisions = query.order('-created').fetch(10, rpc=rpc)
    return [get_revision_dict(revision) for revision in revisions]
Ejemplo n.º 9
0
def get_articles(handler, order, limit, include_content=False):
    rpc = model.get_rpc()
    articles = model.Article.all().order(order).fetch(limit, rpc=rpc)
    return [get_article_dict(article, include_content) for article in articles]