Esempio n. 1
0
def blog_rss():
    if not env.owner or not env.owner.id:
        raise UserNotFound

    if env.owner.type == 'feed':
        raise Forbidden

    plist = posts.recent_blog_posts(env.owner, settings.page_limit, 0)

    feed = PyRSS2Gen.RSS2(
            title="%s@point" % env.owner.login,
            link='http://%s.%s/' % (env.owner.login, settings.domain),
            description="Point.im user's blog")

    for p in plist:
        if 'comment_id' in p and p['comment_id']:
            title='#%s/%s' % (p['post'].id, p['comment_id'])
            link = 'http://%s/%s#%s' % \
                    (settings.domain, p['post'].id, p['comment_id'])
        else:
            title='#%s' % p['post'].id
            link = 'http://%s/%s' % (settings.domain, p['post'].id)

        feed.items.append(PyRSS2Gen.RSSItem(
            author=env.owner.login,
            title=title,
            link=link,
            guid=link,
            pubDate=p['post'].created,
            categories=p['post'].tags,
            description=render_string('/rss-text.html', p=p)
        ))

    return Response(feed.to_xml(), mimetype='application/rss+xml')
Esempio n. 2
0
def blog_by_id(uid=None):
    """Obtain user blog contents by given user id
    parameters:
    uid - user id
    """
    if uid:
        env.owner = User(int(uid))
    elif env.user.is_authorized():
        env.owner = env.user

    if not env.owner:
        raise UserNotFound

    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except ValueError:
            before = None

    try:
        plist = posts.recent_blog_posts(env.owner, settings.page_limit+1,
                                        before=before)
        if len(plist) > settings.page_limit:
            plist = plist[:settings.page_limit]
            has_next = True
        else:
            has_next = False
    except PostAuthorError:
        raise Forbidden

    return {
        "posts": plist,
        "has_next": has_next
    }
Esempio n. 3
0
def blog_by_id(uid=None):
    """Obtain user blog contents by given user id
    parameters:
    uid - user id
    """
    if uid:
        env.owner = User(int(uid))
    elif env.user.is_authorized():
        env.owner = env.user

    if not env.owner:
        raise UserNotFound

    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except ValueError:
            before = None

    try:
        plist = posts.recent_blog_posts(env.owner,
                                        settings.page_limit + 1,
                                        before=before)
        if len(plist) > settings.page_limit:
            plist = plist[:settings.page_limit]
            has_next = True
        else:
            has_next = False
    except PostAuthorError:
        raise Forbidden

    return {"posts": plist, "has_next": has_next}
Esempio n. 4
0
def blog(login=None):
    if login:
        env.owner = User("login", login)
    elif env.user.is_authorized():
        env.owner = env.user

    if not env.owner:
        raise UserNotFound

    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except ValueError:
            before = None

    try:
        plist = posts.recent_blog_posts(env.owner, settings.page_limit+1,
                                        before=before)
        if len(plist) > settings.page_limit:
            plist = plist[:settings.page_limit]
            has_next = True
        else:
            has_next = False
    except PostAuthorError:
        raise Forbidden

    return {
        "posts": plist,
        "has_next": has_next
    }
Esempio n. 5
0
def blog(login=None):
    if login:
        env.owner = User("login", login)
    elif env.user.is_authorized():
        env.owner = env.user

    if not env.owner:
        raise UserNotFound

    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except (TypeError, ValueError):
            before = None

    try:
        plist = posts.recent_blog_posts(env.owner,
                                        settings.page_limit + 1,
                                        before=before)
        if len(plist) > settings.page_limit:
            plist = plist[:settings.page_limit]
            has_next = True
        else:
            has_next = False
    except PostAuthorError:
        raise Forbidden

    return {"posts": plist, "has_next": has_next}
Esempio n. 6
0
def blog_rss():
    if not env.owner or not env.owner.id:
        raise UserNotFound

    if env.owner.type == 'feed':
        raise Forbidden

    plist = posts.recent_blog_posts(env.owner, settings.page_limit, 0)

    feed = PyRSS2Gen.RSS2(title="%s@point" % env.owner.login,
                          link='http://%s.%s/' %
                          (env.owner.login, settings.domain),
                          description="Point.im user's blog")

    for p in plist:
        if 'comment_id' in p and p['comment_id']:
            title = '#%s/%s' % (p['post'].id, p['comment_id'])
            link = 'http://%s/%s#%s' % \
                    (settings.domain, p['post'].id, p['comment_id'])
        else:
            title = '#%s' % p['post'].id
            link = 'http://%s/%s' % (settings.domain, p['post'].id)

        feed.items.append(
            PyRSS2Gen.RSSItem(author=env.owner.login,
                              title=title,
                              link=link,
                              guid=link,
                              pubDate=p['post'].created,
                              categories=p['post'].tags,
                              description=render_string('/rss-text.html',
                                                        p=p)))

    return Response(feed.to_xml(), mimetype='application/rss+xml')
Esempio n. 7
0
def blog(page=1):
    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    if not env.owner or not env.owner.id:
        raise UserNotFound

    offset = (page - 1) * settings.page_limit

    plist = posts.recent_blog_posts(env.owner, settings.page_limit+1, offset)

    if env.request.is_xhr:
        for p in plist:
            p['created'] = timestamp(p['created'])
            p['text'] = markdown_filter(None, p['text'])
        return Response(json.dumps(plist), mimetype='application/json')

    return render('/blog.html', section='blog', posts=plist, page=page)
Esempio n. 8
0
def blog(page=1):
    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    if not env.owner or not env.owner.id:
        raise UserNotFound

    offset = (page - 1) * settings.page_limit

    plist = posts.recent_blog_posts(env.owner, settings.page_limit + 1, offset)

    if env.request.is_xhr:
        for p in plist:
            p['created'] = timestamp(p['created'])
            p['text'] = markdown_filter(None, p['text'])
        return Response(json.dumps(plist), mimetype='application/json')

    return render('/blog.html', section='blog', posts=plist, page=page)
Esempio n. 9
0
def info(login, show=False, offset=None, limit=None):
    """Get user info
    """
    try:
        user = User('login', login)
        data = users.info(user)
    except UserNotFound:
        return xmpp_template('user_not_found', login=login)
    except SubscribeError:
        return xmpp_template('user_denied', login=login)

    data['realname'] = data['name']
    del data['name']

    #_posts = None
    if show:
        if offset:
            offset = int(offset)
        if limit:
            limit = int(limit)
        else:
            limit = 10
        if env.user and env.user.id and env.user.id == user.id:
            private = None
        else:
            private = False
        #plist = posts.select_posts(author=user, private=private,
        #                           offset=offset, limit=limit)
        plist = posts.recent_blog_posts(author=user,
                                        offset=offset,
                                        limit=limit)
        plist.reverse()
        data['posts'] = plist

    else:
        data['posts_count'] = user.posts_count()

    return xmpp_template('user_info', login=login, **data)
Esempio n. 10
0
def info(login, show=False, offset=None, limit=None):
    """Get user info
    """
    try:
        user = User('login', login)
        data = users.info(user)
    except UserNotFound:
        return xmpp_template('user_not_found', login=login)
    except SubscribeError:
        return xmpp_template('user_denied', login=login)

    data['realname'] = data['name']
    del data['name']

    #_posts = None
    if show:
        if offset:
            offset = int(offset)
        if limit:
            limit = int(limit)
        else:
            limit = 10
        if env.user and env.user.id and env.user.id == user.id:
            private = None
        else:
            private = False
        #plist = posts.select_posts(author=user, private=private,
        #                           offset=offset, limit=limit)
        plist = posts.recent_blog_posts(author=user, offset=offset, limit=limit)
        plist.reverse()
        data['posts'] = plist

    else:
        data['posts_count'] = user.posts_count()

    return xmpp_template('user_info', login=login, **data)