示例#1
0
文件: blog.py 项目: skobkin/point
def show_post(id):
    post = posts.show_post(id)
    post_dict = posts.show_post(id).todict()
    post_dict['unread'] = posts.post_unread(id, env.user.id) if env.user.id \
        else None
    return {
        "post": post_dict,
        "comments": post.comments(cuser=env.user),
    }
示例#2
0
def show_post(post_id,
              last=False,
              all=False,
              show=False,
              offset=None,
              limit=None):
    try:
        post = posts.show_post(post_id)
    except PostNotFound:
        return xmpp_template('post_not_found', post_id=post_id)
    except (SubscribeError, PostAuthorError):
        return xmpp_template('post_denied', post_id=post_id)

    subscribed = post.check_subscriber(env.user) if env.user.id else False

    updates = []
    for i, upd in enumerate(post.updates()):
        updates.append({'no': i + 1, 'text': upd['text']})

    comments = []

    posts.clear_unread_posts(post_id)
    if last or all or show:
        if offset:
            offset = int(offset)
        if limit:
            limit = int(limit)
        else:
            limit = 10
        res = post.comments(last=last, all=all, offset=offset, limit=limit)
        for c in res:
            comments.append({
                'comment_id': c.id,
                'to_comment_id': c.to_comment_id,
                'comment_author': c.author.login,
                'comment_text': c.text,
                'is_rec': c.is_rec,
                'files': c.files
            })
        cnt = None
        posts.clear_unread_comments(post_id, map(lambda c: c.id, res))
    else:
        cnt = post.comments_count()

    return xmpp_template('post',
                         post_id=post_id,
                         author=post.author.login,
                         type=post.type,
                         private=post.private,
                         title=post.title,
                         link=post.link,
                         tags=post.tags,
                         text=post.text,
                         files=post.files,
                         subscribed=subscribed,
                         updates=updates,
                         comments=comments,
                         comments_count=cnt,
                         archive=post.archive,
                         rec_users=post.recommended_users())
示例#3
0
def show_post(id):
    post = posts.show_post(id)

    return {
        "post": post.todict(),
        "comments": post.comments(cuser=env.user),
    }
示例#4
0
def show_post(id):
    post = posts.show_post(id)

    return {
        "post": post.todict(),
        "comments": post.comments(cuser=env.user),
    }
示例#5
0
def show_post(id):
    post = posts.show_post(id)

    if env.request.method == 'POST':
        return add_comment(post.id)

    if not env.owner or env.owner.id != post.author.id:
        return Response(redirect='%s://%s.%s/%s' % \
                        (env.request.protocol,
                         post.author.login.lower(), settings.domain, id))

    comments = post.comments(cuser=env.user)

    if env.user.is_authorized():
        posts.clear_unread_posts(id)
        if comments:
            posts.clear_unread_comments(id)

    errors = []
    if env.request.args('expired'):
        errors.append('expired')
    if env.request.args('commented'):
        errors.append('commented')

    sess = Session()

    tree = env.request.args('tree')
    if tree:
        if tree.lower() in ('0', 'false', 'f'):
            tree = False
        else:
            tree = True
        sess['ctree'] = tree
        sess.save()
    elif sess['ctree'] is not None:
        tree = sess['ctree']
    else:
        env.user.get_profile('tree')

    comments_count = len(comments)
    if tree:
        cout = {}
        for c in comments:
            cout[c.id] = c
            if c.to_comment_id and c.to_comment_id in cout:
                cout[c.to_comment_id].comments.append(c)
            else:
                c.to_comment_id = None
        comments = filter(lambda c: not c.to_comment_id, cout.itervalues())

    section = 'messages' if post.private else ''

    return render('/post.html',
                  post=post,
                  comments=comments,
                  comments_count=comments_count,
                  tree=tree,
                  errors=errors,
                  section=section)
示例#6
0
def post_pin(id):
    post = posts.show_post(id)
    try:
        if post.pinned:
            raise PostAlreadyPinnedError
    except PostAlreadyPinnedError:
        return {"code": "405", "message": "Post already pinned."}
    else:
        post.set_pinned()
示例#7
0
文件: blog.py 项目: skobkin/point
def post_unpin(id):
    post = posts.show_post(id)
    try:
        if not post.pinned:
            raise PostNotPinnedError
    except PostNotPinnedError:
        return {"code": "405", "message": "Post not pinned."}
    else:
        post.set_pinned(False)
示例#8
0
文件: blog.py 项目: skobkin/point
def post_pin(id):
    post = posts.show_post(id)
    try:
        if post.pinned:
            raise PostAlreadyPinnedError
    except PostAlreadyPinnedError:
        return {"code": "405", "message": "Post already pinned."}
    else:
        post.set_pinned()
示例#9
0
def post_unpin(id):
    post = posts.show_post(id)
    try:
        if not post.pinned:
            raise PostNotPinnedError
    except PostNotPinnedError:
        return {"code": "405", "message": "Post not pinned."}
    else:
        post.set_pinned(False)
示例#10
0
文件: blog.py 项目: radjah/point-www
def show_post(id):
    post = posts.show_post(id)

    if env.request.method == 'POST':
        return add_comment(post.id)

    if not env.owner or env.owner.id != post.author.id:
        return Response(redirect='%s://%s.%s/%s' % \
                        (env.request.protocol,
                         post.author.login.lower(), settings.domain, id))

    comments = post.comments(cuser=env.user)

    if env.user.is_authorized():
        posts.clear_unread_posts(id)
        if comments:
            posts.clear_unread_comments(id)

    errors = []
    if env.request.args('expired'):
        errors.append('expired')
    if env.request.args('commented'):
        errors.append('commented')

    sess = Session()

    tree = env.request.args('tree')
    if tree:
        if tree.lower() in ('0', 'false', 'f'):
            tree = False
        else:
            tree = True
        sess['ctree'] = tree
        sess.save()
    elif sess['ctree'] is not None:
        tree = sess['ctree']
    else:
        env.user.get_profile('tree')

    comments_count = len(comments)
    if tree:
        cout = {}
        for c in comments:
            cout[c.id] = c
            if c.to_comment_id and c.to_comment_id in cout:
                cout[c.to_comment_id].comments.append(c)
            else:
                c.to_comment_id = None
        comments = filter(lambda c: not c.to_comment_id, cout.itervalues())

    section = 'messages' if post.private else ''

    return render('/post.html', post=post, comments=comments,
                  comments_count=comments_count, tree=tree,
                  errors=errors, section=section)
示例#11
0
def show_post(post_id, last=False, all=False, show=False,
              offset=None, limit=None):
    try:
        post = posts.show_post(post_id)
    except PostNotFound:
        return xmpp_template('post_not_found', post_id=post_id)
    except (SubscribeError, PostAuthorError):
        return xmpp_template('post_denied', post_id=post_id)

    subscribed = post.check_subscriber(env.user) if env.user.id else False

    updates = []
    for i, upd in enumerate(post.updates()):
        updates.append({'no': i+1, 'text': upd['text']})

    comments = []

    posts.clear_unread_posts(post_id)
    if last or all or show:
        if offset:
            offset = int(offset)
        if limit:
            limit = int(limit)
        else:
            limit = 10
        res = post.comments(last=last, all=all, offset=offset, limit=limit)
        for c in res:
            comments.append({
                'comment_id': c.id,
                'to_comment_id': c.to_comment_id,
                'comment_author': c.author.login,
                'comment_text': c.text,
                'is_rec': c.is_rec,
                'files': c.files
            })
        cnt = None
        posts.clear_unread_comments(post_id, map(lambda c: c.id, res))
    else:
        cnt = post.comments_count()

    return xmpp_template('post', post_id=post_id, author=post.author.login,
                                 type=post.type, private=post.private,
                                 title=post.title, link=post.link,
                                 tags=post.tags, text=post.text,
                                 tune=post.tune, files=post.files,
                                 subscribed=subscribed,
                                 updates=updates, comments=comments,
                                 comments_count=cnt,
                                 archive=post.archive,
                                 rec_users=post.recommended_users())
示例#12
0
def edit_post(id):
    try:
        post = posts.show_post(id)
    except PostAuthorError:
        raise SubscribeError

    if env.request.method == 'GET':
        return render('/post-edit.html', post=post)

    files = _files(post.files)

    @csrf
    def save(post):
        text = env.request.args('text', '').strip()

        tags = env.request.args('tags', '').strip(' \t*,;')
        if isinstance(tags, str):
            tags = tags.decode('utf-8')
        tags = [
            t.replace(u"\xa0", " ") for t in re.split(r'\s*[,;*]\s*', tags)
        ]

        private = bool(env.request.args('private'))

        posts.edit_post(post,
                        text=text,
                        tags=tags,
                        private=private,
                        files=files)

        return Response(redirect='%s://%s.%s/%s' % \
                                 (env.request.protocol,
                                  env.user.login, settings.domain, post.id))

    try:
        return save(post)
    except PostUpdateError:
        return Response(redirect='%s://%s.%s/%s?expired=1' % \
                                 (env.request.protocol,
                                  env.user.login, settings.domain, post.id))
    except PostCommentedError:
        return Response(redirect='%s://%s.%s/%s?commented=1' % \
                                 (env.request.protocol,
                                  env.user.login, settings.domain, post.id))
    except PostDiffError:
        return render('/post-edit.html', post=post, errors=['diff'])
示例#13
0
文件: blog.py 项目: skobkin/point
def edit_post(id):
    post = posts.show_post(id)

    text = env.request.args('text', '').strip()
    #private = bool(env.request.args('private'))
    tags = env.request.args('tag', '') or env.request.args('tag[]', '')
    if not tags:
        tags = []
    elif not isinstance(tags, (list, tuple)):
        tags = [tags]

    def _t(tag):
        if isinstance(tag, str):
            tag = tag.decode('utf-8')
        return tag.replace(u"\xa0", " ")

    tags = map(_t, tags)

    posts.edit_post(post, text=text, tags=tags)
示例#14
0
def edit_post(id):
    post = posts.show_post(id)

    text = env.request.args('text', '').strip()
    #private = bool(env.request.args('private'))
    tags = env.request.args('tag', '') or env.request.args('tag[]', '')
    if not tags:
        tags = []
    elif not isinstance(tags, (list, tuple)):
        tags = [tags]

    def _t(tag):
        if isinstance(tag, str):
            tag = tag.decode('utf-8')
        return tag.replace(u"\xa0", " ")

    tags = map(_t, tags)

    posts.edit_post(post, text=text, tags=tags)
示例#15
0
文件: post.py 项目: Raegdan/www-new
def show_post(id):
    post = posts.show_post(id)

    comments = post.comments(cuser=env.user)

    if env.user.is_authorized():
        posts.clear_unread_posts(id)
        if comments:
            posts.clear_unread_comments(id)

    menu = 'messages' if post.private else ''

    return Response(template='/pages/post.html', menu=menu, owner=post.author,
                    p={
                        'post': post,
                        'comments_count': post.comments_count(),
                        'subscribed': post.check_subscriber(env.user),
                        'bookmarked': post.check_bookmarked(env.user),
                        'recommended': post.check_recommended(env.user),
                        'rec_users': post.recommended_users()
                    }, comments=comments)
示例#16
0
文件: blog.py 项目: radjah/point-www
def edit_post(id):
    try:
        post = posts.show_post(id)
    except PostAuthorError:
        raise SubscribeError

    if env.request.method == 'GET':
        return render('/post-edit.html', post=post)

    files = _files(post.files)

    @csrf
    def save(post):
        text = env.request.args('text', '').strip()

        tags = env.request.args('tags', '').strip(' \t*,;')
        if isinstance(tags, str):
            tags = tags.decode('utf-8')
        tags = [t.replace(u"\xa0", " ") for t in re.split(r'\s*[,;*]\s*', tags)]

        private = bool(env.request.args('private'))

        posts.edit_post(post, text=text, tags=tags, private=private, files=files)

        return Response(redirect='%s://%s.%s/%s' % \
                                 (env.request.protocol,
                                  env.user.login, settings.domain, post.id))
    try:
        return save(post)
    except PostUpdateError:
        return Response(redirect='%s://%s.%s/%s?expired=1' % \
                                 (env.request.protocol,
                                  env.user.login, settings.domain, post.id))
    except PostCommentedError:
        return Response(redirect='%s://%s.%s/%s?commented=1' % \
                                 (env.request.protocol,
                                  env.user.login, settings.domain, post.id))
    except PostDiffError:
        return render('/post-edit.html', post=post, errors=['diff'])
示例#17
0
def show_post(id):
    post = posts.show_post(id)

    comments = post.comments(cuser=env.user)

    if env.user.is_authorized():
        posts.clear_unread_posts(id)
        if comments:
            posts.clear_unread_comments(id)

    menu = 'messages' if post.private else ''

    return Response(template='/pages/post.html',
                    menu=menu,
                    owner=post.author,
                    p={
                        'post': post,
                        'comments_count': post.comments_count(),
                        'subscribed': post.check_subscriber(env.user),
                        'bookmarked': post.check_bookmarked(env.user),
                        'recommended': post.check_recommended(env.user),
                        'rec_users': post.recommended_users()
                    },
                    comments=comments)
示例#18
0
def show_post(id, page=None):
    post = posts.show_post(id)

    if env.request.method == 'POST':
        return add_comment(post.id)

    if not env.owner or env.owner.id != post.author.id:
        return Response(redirect='%s://%s.%s/%s' % \
                        (env.request.protocol,
                         post.author.login.lower(), settings.domain, id))

    errors = []
    if env.request.args('expired'):
        errors.append('expired')
    if env.request.args('commented'):
        errors.append('commented')

    sess = Session()

    tree = env.request.args('tree')

    if tree:
        if tree.lower() in ('0', 'false', 'f'):
            tree = False
        else:
            tree = True
        sess['ctree'] = tree
        sess.save()
    elif sess['ctree'] is not None:
        tree = sess['ctree']
    else:
        env.user.get_profile('tree')

    comments_count = post.comments_count()

    if comments_count > 1000:
        climit = 100

        tree = False

        last_page = int(math.ceil(float(comments_count) / climit))

        try:
            page = int(page)
        except (TypeError, ValueError):
            page = last_page

        cstart = (page - 1) * climit
        comments = post.comments(cuser=env.user, offset=cstart, limit=climit)
    else:
        comments = post.comments(cuser=env.user)
        page = None
        last_page = None

    if env.user.is_authorized():
        posts.clear_unread_posts(id)
        if comments:
            posts.clear_unread_comments(id)

    if tree:
        cout = {}
        for c in comments:
            cout[c.id] = c
            if c.to_comment_id and c.to_comment_id in cout:
                cout[c.to_comment_id].comments.append(c)
            else:
                c.to_comment_id = None
        comments = filter(lambda c: not c.to_comment_id, cout.itervalues())

    sess = Session()
    clear_post_input = sess['clear_post_input']
    if clear_post_input:
        sess['clear_post_input'] = False
        sess.save()

    section = 'messages' if post.private else ''

    return render('/post.html', post=post, comments=comments,
                  comments_count=comments_count, tree=tree,
                  errors=errors, section=section,
                  page=page, last_page=last_page,
                  clear_post_input=clear_post_input)
示例#19
0
def show_post(id, page=None):
    post = posts.show_post(id)

    if env.request.method == 'POST':
        return add_comment(post.id)

    if not env.owner or env.owner.id != post.author.id:
        return Response(redirect='%s://%s.%s/%s' % \
                        (env.request.protocol,
                         post.author.login.lower(), settings.domain, id))

    errors = []
    if env.request.args('expired'):
        errors.append('expired')
    if env.request.args('commented'):
        errors.append('commented')

    sess = Session()

    tree = env.request.args('tree')

    if tree:
        if tree.lower() in ('0', 'false', 'f'):
            tree = False
        else:
            tree = True
        sess['ctree'] = tree
        sess.save()
    elif sess['ctree'] is not None:
        tree = sess['ctree']
    else:
        env.user.get_profile('tree')

    comments_count = post.comments_count()

    if comments_count > 1000:
        climit = 100

        tree = False

        last_page = int(math.ceil(float(comments_count) / climit))

        try:
            page = int(page)
        except (TypeError, ValueError):
            page = last_page

        cstart = (page - 1) * climit
        comments = post.comments(cuser=env.user, offset=cstart, limit=climit)
    else:
        comments = post.comments(cuser=env.user)
        page = None
        last_page = None

    if env.user.is_authorized():
        posts.clear_unread_posts(id)
        if comments:
            posts.clear_unread_comments(id)

    if tree:
        cout = {}
        for c in comments:
            cout[c.id] = c
            if c.to_comment_id and c.to_comment_id in cout:
                cout[c.to_comment_id].comments.append(c)
            else:
                c.to_comment_id = None
        comments = filter(lambda c: not c.to_comment_id, cout.itervalues())

    sess = Session()
    clear_post_input = sess['clear_post_input']
    if clear_post_input:
        sess['clear_post_input'] = False
        sess.save()

    section = 'messages' if post.private else ''

    return render('/post.html',
                  post=post,
                  comments=comments,
                  comments_count=comments_count,
                  tree=tree,
                  errors=errors,
                  section=section,
                  page=page,
                  last_page=last_page,
                  clear_post_input=clear_post_input)
示例#20
0
def show_post(id):
    post = posts.show_post(id)
    post_dict = posts.show_post(id).todict()
    post_dict["unread"] = posts.post_unread(id, env.user.id) if env.user.id else None
    return {"post": post_dict, "comments": post.comments(cuser=env.user)}