Exemplo n.º 1
0
def all_posts(page=1):
    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except ValueError:
            before = None

    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    offset = (page - 1) * settings.page_limit

    plist = posts.select_posts(private=False, author_private=False,
                               blacklist=True,
                               limit=settings.page_limit+1, offset=offset,
                               before=before)
    if len(plist) > settings.page_limit:
        plist = plist[:settings.page_limit]
        has_next = True
    else:
        has_next = False

    return {
        "posts": plist,
        "has_next": has_next
    }
Exemplo n.º 2
0
def all_posts_rss():
    plist = posts.select_posts(private=False, author_private=False,
                               deny_anonymous=False, blacklist=True,
                               limit=settings.page_limit*4)

    feed = PyRSS2Gen.RSS2(
            title="Point.im",
            link='http://%s/' % (settings.domain),
            description="Point.im")

    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')
Exemplo n.º 3
0
def all_posts(page=1):
    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except ValueError:
            before = None

    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    offset = (page - 1) * settings.page_limit

    plist = posts.select_posts(private=False,
                               author_private=False,
                               blacklist=True,
                               limit=settings.page_limit + 1,
                               offset=offset,
                               before=before)
    if len(plist) > settings.page_limit:
        plist = plist[:settings.page_limit]
        has_next = True
    else:
        has_next = False

    return {"posts": plist, "has_next": has_next}
Exemplo n.º 4
0
def all_posts_rss():
    plist = posts.select_posts(private=False,
                               author_private=False,
                               deny_anonymous=False,
                               blacklist=True,
                               limit=settings.page_limit * 4)

    feed = PyRSS2Gen.RSS2(title="Point.im",
                          link='http://%s/' % (settings.domain),
                          description="Point.im")

    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')
Exemplo n.º 5
0
def all_posts(page=1):
    sess = Session()
    if not sess['agree']:
        if env.request.args('agree'):
            sess['agree'] = True
            sess.save()
        else:
            return all_posts_warning()

    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    offset = (page - 1) * settings.page_limit

    plist = posts.select_posts(private=False,
                               author_private=False,
                               blacklist=True,
                               limit=settings.page_limit + 1,
                               offset=offset)

    return render('/all_posts.html', section='all', posts=plist, page=page)
Exemplo n.º 6
0
def all_posts(show=None, offset=None, limit=None):
    if offset:
        offset = int(offset)
    if limit:
        limit = int(limit)
    else:
        limit = 10

    plist = posts.select_posts(offset=offset, limit=limit, private=False)
    plist.reverse()

    return xmpp_template('posts', posts=plist)
Exemplo n.º 7
0
def all_posts(show=None, offset=None, limit=None):
    if offset:
        offset = int(offset)
    if limit:
        limit = int(limit)
    else:
        limit = 10

    plist = posts.select_posts(offset=offset, limit=limit, private=False, blacklist=True)
    plist.reverse()

    return xmpp_template('posts', posts=plist)
Exemplo n.º 8
0
def tag_posts(tag, page=1):
    if env.request.host != settings.domain and (not env.owner
                                                or not env.owner.id):
        raise UserNotFound

    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    offset = (page - 1) * settings.page_limit

    if env.owner and env.owner.id:
        author = env.owner
    else:
        author = None

    if env.owner and env.owner.id == env.user.id:
        private = None
    else:
        private = False

    # variable deny_anonymous is for corresponding value of 'deny_anonymous'
    # field in 'users.profile' table
    deny_anonymous = False if not env.user.is_authorized() else None

    if not isinstance(tag, (list, tuple)):
        tag = [tag]
    tag = [t.decode('utf-8', 'ignore').replace(u"\xa0", " ") for t in tag]

    plist = posts.select_posts(author=author,
                               private=private,
                               deny_anonymous=deny_anonymous,
                               tags=tag,
                               offset=offset,
                               limit=settings.page_limit + 1)

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

    section = 'blog' if env.owner and env.user.id == env.owner.id else ''

    return render('/tags.html',
                  section=section,
                  posts=plist,
                  page=page,
                  tags=tag)
Exemplo n.º 9
0
def tag_posts(tag, page=1):
    if env.request.host != settings.domain and (not env.owner or not env.owner.id):
        raise UserNotFound

    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    offset = (page - 1) * settings.page_limit

    if env.owner and env.owner.id:
        author = env.owner
    else:
        author = None

    if env.owner and env.owner.id == env.user.id:
        private = None
    else:
        private = False

    # variable deny_anonymous is for corresponding value of 'deny_anonymous'
    # field in 'users.profile' table
    deny_anonymous = False if not env.user.is_authorized() else None

    if not isinstance(tag, (list, tuple)):
        tag = [tag]
    tag = [t.decode('utf-8', 'ignore').replace(u"\xa0", " ") for t in tag]

    plist = posts.select_posts(author=author, private=private, 
                               deny_anonymous=deny_anonymous, tags=tag,
                               offset=offset, limit=settings.page_limit+1)

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

    section = 'blog' if env.owner and env.user.id == env.owner.id else ''

    return render('/tags.html', section=section, posts=plist, page=page,
                  tags=tag)
Exemplo n.º 10
0
def tag_posts(login=None):
    """Выборка постов по тегам пользователя. Пользователь может быть 
    идентифицирован по его user id или логину. 
    Параметр login, переданный в URL может быть числом, и тогда 
    интерпретируется как id пользователя, или строкой -- в этом случае он 
    интерпретируется как login пользователя
    """
    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except ValueError:
            before = None

    if login:
        if login and login.isdigit():
            author = User(int(login))
        else:            
            author = User("login", login)
    else:
        author = None

    if author and author == env.user:
        private = None
    else:
        private = False

    tags = env.request.args("tag")
    if not isinstance(tags, (list, tuple)):
        tags = [tags]
    tags = [t.decode('utf-8').replace(u"\xa0", " ") for t in tags]

    plist = posts.select_posts(author=author, private=private, tags=tags,
                               limit=settings.page_limit+1, before=before)
    if len(plist) > settings.page_limit:
        plist = plist[:settings.page_limit]
        has_next = True
    else:
        has_next = False

    return {
        "posts": plist,
        "has_next": has_next
    }
Exemplo n.º 11
0
def tag_posts(login=None):
    """Выборка постов по тегам пользователя. Пользователь может быть 
    идентифицирован по его user id или логину. 
    Параметр login, переданный в URL может быть числом, и тогда 
    интерпретируется как id пользователя, или строкой -- в этом случае он 
    интерпретируется как login пользователя
    """
    before = env.request.args("before")
    if before:
        try:
            before = long(before)
        except ValueError:
            before = None

    if login:
        if login and login.isdigit():
            author = User(int(login))
        else:
            author = User("login", login)
    else:
        author = None

    if author and author == env.user:
        private = None
    else:
        private = False

    tags = env.request.args("tag")
    if not isinstance(tags, (list, tuple)):
        tags = [tags]
    tags = [t.decode('utf-8').replace(u"\xa0", " ") for t in tags]

    plist = posts.select_posts(author=author,
                               private=private,
                               tags=tags,
                               limit=settings.page_limit + 1,
                               before=before)
    if len(plist) > settings.page_limit:
        plist = plist[:settings.page_limit]
        has_next = True
    else:
        has_next = False

    return {"posts": plist, "has_next": has_next}
Exemplo n.º 12
0
def all_posts(page=1):
    sess = Session()
    if not sess['agree']:
        if env.request.args('agree'):
            sess['agree'] = True
            sess.save()
        else:
            return all_posts_warning()

    try:
        page = int(page)
    except (TypeError, ValueError):
        page = 1
    if not page:
        page = 1

    offset = (page - 1) * settings.page_limit

    plist = posts.select_posts(private=False, author_private=False,
                               blacklist=True,
                               limit=settings.page_limit+1, offset=offset)

    return render('/all_posts.html', section='all', posts=plist, page=page)
Exemplo n.º 13
0
    else:
        limit = 10

    try:
        author = User('login', login) if login else None
    except UserNotFound, e:
        return xmpp_template('user_not_found', login=e.message)

    if env.user and author and env.user.id == author.id:
        private = None
    else:
        private = False

    plist = posts.select_posts(author=author,
                               private=private,
                               tags=parse_tags(tag),
                               offset=offset,
                               limit=limit)

    plist.reverse()

    return xmpp_template('posts', posts=plist)


def all_posts(show=None, offset=None, limit=None):
    if offset:
        offset = int(offset)
    if limit:
        limit = int(limit)
    else:
        limit = 10
Exemplo n.º 14
0
        limit = int(limit)
    else:
        limit = 10

    try:
        author = User('login', login) if login else None
    except UserNotFound, e:
        return xmpp_template('user_not_found', login=e.message)

    if env.user and author and env.user.id == author.id:
        private = None
    else:
        private = False

    plist = posts.select_posts(author=author, private=private,
                               tags=parse_tags(tag),
                               offset=offset, limit=limit)

    plist.reverse()

    return xmpp_template('posts', posts=plist)

def all_posts(show=None, offset=None, limit=None):
    if offset:
        offset = int(offset)
    if limit:
        limit = int(limit)
    else:
        limit = 10

    plist = posts.select_posts(offset=offset, limit=limit, private=False, blacklist=True)