コード例 #1
0
ファイル: post_view.py プロジェクト: fabriziou/gae-blog-2
def feed(tag):
    """rss 2.0 feed"""
    if tag:
        tag = tag.replace('%2F', '/')
    config = Config()
    postlist = Post.get_postlist(privilege=PRIVILEGE_SHOW,
                                 offset=0,
                                 limit=config["feednum"],
                                 tag=tag,
                                 archive=None)
    title = config["heading"]
    if tag:
        title += u" - " + tag
    link = "http://" + config["host"]
    description = config["subheading"]
    items = []
    for post in postlist:
        items.append(
            PyRSS2Gen.RSSItem(
                title=post.title,
                link="http://" + config["host"] + "/post/" +
                str(post.key.id()),
                description=post.content,
                pubDate=post.date,
            ))
    rss = PyRSS2Gen.RSS2(
        title=title,
        link=link,
        description=description,
        items=items,
    )
    return Response(rss.to_xml(), mimetype='application/rss+xml')
コード例 #2
0
def comment_list(postid, page):
    post = Post.getpost(postid)
    count = post.commentCount
    if count is None:
        count = 0
    cpagesize = Config()["commentnumperpage"]
    commentlist = Comment.get_commentlist_bypost(postid,
                                                 (page - 1) * cpagesize,
                                                 cpagesize)

    isadmin = users.is_current_user_admin()
    result = {
        "count": count,
        "page": page,
        "pagecount": (count - 1) / cpagesize + 1,
        "clist": [comment.to_dict(isadmin) for comment in commentlist]
    }
    return jsonify(result)
コード例 #3
0
ファイル: post_view.py プロジェクト: fabriziou/gae-blog-2
def view_post(postid):
    """ show detail post."""
    post = Post.getpost(postid)
    if post is None:
        return abort(404)
    if post.privilege <= 0 and not users.is_current_user_admin():
        return abort(404)

    # get similar posts
    # try:
    #     similars = postindex.getsimilars(postid, post.title, post.tags)
    # except Exception as e:
    #     # search api may not be enabled, or have bugs.
    #     similars = []

    pf = platform.get_platform(request.headers.get('User-Agent'))
    if pf == platform.PHONE:
        tpl = "m/m_post.html"
    else:
        tpl = "post_view.html"
    return render_template(tpl, post=post, similars=[], config=Config())
コード例 #4
0
ファイル: post_view.py プロジェクト: fabriziou/gae-blog-2
def edit_post():
    """show post new/edit page."""
    if not users.is_current_user_admin():
        return abort(403)

    postidstr = request.args.get('postid')
    if postidstr:
        # edit
        postid = int(postidstr)
        post = Post.getpost(postid)
    else:
        # new
        post = _emptyPost()
    alltags = Tag.get_taglist(CID_TAG)
    taglist = [{
        "name": tag.name,
        "spell": pinyin.getpinyin(tag.name)
    } for tag in alltags if tag]
    return render_template('post_edit.html',
                           post=post,
                           taglist=taglist,
                           config=Config())
コード例 #5
0
def show_search(albumname):
    album = picasa.get_album(Config()["picasaalbumname"], albumname)
    return render_template('gallery.html', album=album, config=Config())
コード例 #6
0
def album_list():
    album_list = picasa.get_album_list(Config()["picasaalbumname"])
    return render_template('album_list.html',
                           albumlist=album_list,
                           config=Config())
コード例 #7
0
ファイル: post_view.py プロジェクト: fabriziou/gae-blog-2
@app.route('/post/archive/<archive>/',
           methods=['GET'],
           defaults={
               "pagenum": 1,
               "tag": None
           })
@app.route('/post/archive/<archive>/<int:pagenum>',
           methods=['GET'],
           defaults={"tag": None})
def post_list(pagenum, tag, archive):
    """show post list"""
    try:
        page = int(pagenum)
    except Exception, ex:
        page = 1
    config = Config()
    if tag:
        tag = tag.replace('%2F', '/')
        total_tag = Tag.get_tag(CID_TAG, tag)
    elif archive:
        total_tag = Tag.get_tag(CID_ARCHIVE, archive)
    else:
        total_tag = Tag.get_tag(CID_COUNTER, NAME_ALLPOST)
    if total_tag:
        total = total_tag.count
    else:
        total = 0
    pager = Pager(total, page, config["postnumperpage"])

    if tag:
        base = '/post/list/' + webtools.encodetag(tag) + '/'
コード例 #8
0
def search_page():
    return render_template('search.html', query=request.args.get('query'), config=Config())