Пример #1
0
def show_single(post_id):
    """ Show/edit a single post. """
    p = psblog.get_post(post_id)
    # TODO: proper form handling for html module
    o=""
    o+="<form action=\"?page=save\" method=\"POST\">"
    o+="<input type=\"text\" name=\"heading\" value=\""+p["meta"]["heading"]+"\"><br>"
    o+="<input type=\"text\" name=\"category\" value=\""+p["meta"]["category"]+"\"><br>"
    o+="<input type=\"hidden\" name=\"id\" value=\""+post_id+"\"><br>"
    o+="<input type=\"hidden\" name=\"save\" value=\"save\"><br>"
    o+="<textarea style='width:100%;height:40em;' name=\"text\">"+p["text"].decode("utf8")+"</textarea><br>"
    o+="<input type=\"submit\"><br>" 
    o+="</form>"
    i = 0
    for c in p["comments"]:
        # TODO: make delete link a POSTing form
        o2=html.a("?page=del_comment&id="+post_id+"&cid="+str(i), "delete")
        o2+="<br>"
        for key,item in c.items():
            # XXX HACK
            try:
                o2+=key+" - "+item.decode("utf8")+"<br>"
            except UnicodeEncodeError:
                o2+=key+" - "+item+"<br>"
        o += html.block(o2)
        i += 1
    o+=html.block(p["html"])
    print(html.render_admin(o.encode("utf8")))
Пример #2
0
def create_single(posts, index):
    """ Create a single html file for a single post. """
    # actual post
    p = posts[index]
    post_str = html.block(
        "".join([
            html.date(p["meta"]["datetime"]),
            html.h(2, p["meta"]["heading"]),
            html.p(p["html"]),
            html.author()]),
        "single")
    # links to previous and next posts
    prev_ls = []
    if index > 0:
        prev_ls.append("next: " + html.post_link(posts[index-1]))
    if index < len(posts) - 1:
        prev_ls.append("previous: " + html.post_link(posts[index+1]))
    prev_str = html.block("<br>".join(prev_ls), "btw")
    # comments and comment form
    comments_str = ""
    for c in p["comments"]:
        comments_str += html.block(
            "".join([
                html.p(markdown.markdown(c["text"])),
                html.comment_meta(c)]))
    comment_form_str = html.comment_form(
        post_id(p["meta"]), post_url(p["meta"]))
    # write to file
    file_contents = post_str+prev_str+comments_str+comment_form_str
    urlpath = str(p["meta"]["datetime"].year)+"/"+p["meta"]["url_heading"]
    write_out(urlpath+".html",
                  html.render_front(file_contents, p["meta"]["heading"]))
Пример #3
0
def show_overview():
    """ Show an overview over the blog. """
    posts = psblog.get_all_posts()
    comments_num = 0
    for p in posts:
        comments_num += len(p["comments"])
    o = [html.h(2, "Overview"),
         html.p(html.a("?page=list", str(len(posts))+" Posts")),
         html.p(html.a("#TODO", str(comments_num)+" Comments")),
         html.p(html.a("?page=add_new", "Add New Post")),
         html.p(html.a("?page=compile", "Re-Compile"))]
    o = html.block("".join(o))
    o += html.block(html.p("last compile log:"+html.pre(
            psblog.readfile(config.log_dir+"compile.log"))))
    log_ls = psblog.readfile(config.log_dir+"psblog.log").splitlines()
    log_ls.reverse()
    o += html.block(html.p("blog log:"+html.pre("\n".join(log_ls))))
    print(html.render_admin(o))
Пример #4
0
def show_list():
    """ Show a list of all posts. """
    posts = psblog.get_all_posts()
    ls_data = []
    for p in posts:
        ls_data.append("".join([
              p["meta"]["datetime"].strftime("%x")," - ",
              html.a("?page=single&id="+psblog.post_id(p["meta"]),
              p["meta"]["heading"]), " - ", 
              str(len(p["comments"])), " comment(s)"]))
    print(html.render_admin(html.block(html.ul(ls_data))))
Пример #5
0
def create_stats(p, start):
    """ Create a small compilation statistic page. """
    write_out("stats.html", html.render_front(
        html.block("".join([
            html.h(2, "Statistics"),
            html.pre("".join([
                "last compile on ",
                dt.datetime.now().strftime("%A, %x %T"),
                "\n\nnumber of posts: ",
                str(len(p)),
                "\nrendering took ",
                str(time.clock()-start),
                " seconds"]))])), "statistics"))
Пример #6
0
def create_errors():
    """ Create custom error pages. """
    log_compile("creating error pages")
    content = {
        401: ("401 Unauthorized", "Go away."),
        403: ("403 Forbidden", "Yep, forbidden."),
        404: ("404 Not Found", "Sorry."),
        500: ("500 Internal Server Error", "Please try again later.")}
    for n, msg in content.items():
        write_out(str(n)+".html",
                  html.render_front(
                      html.block(html.h(2, msg[0])+html.p(msg[1])),
                      msg[0]))
    log_compile("done")
Пример #7
0
def create_index(posts):
    """ Create the overview index.html file. """
    log_compile("creating index page")
    o = ""
    for p in posts:
        o += html.block(
            "".join([
                html.h(2, html.post_link(p)),
                html.hex_dump(p["text"]),
                html.pre(
                    "-rw-r--r-- 1 rwos rwos "
                    +str(len(p["text"]))+" "
                    +html.date(p["meta"]["datetime"])+" "
                    +p["meta"]["url_heading"][0:20]),
                html.pre(str(len(p["comments"]))+" comment(s)")]))
    # TODO: pagination, with configurable limit
    write_out("index.html", html.render_front(o))
    log_compile("done")
Пример #8
0
def add_new(params):
    """ Add a new post to the blog. """
    if "save" in params:
        add_post(
            params["heading"].value,
            params["category"].value,
            params["text"].value)
    else:
        # TODO: form handling, form handling, form handling!!!
        o=""
        o+="<form action='?page=add_new&save=save' method=\"POST\">"
        o+="Heading: <input type=\"text\" name=\"heading\"><br>"
        o+="Category: <input type=\"text\" name=\"category\"><br>"
        o+="<input type=\"hidden\" name=\"save\" value=\"save\"><br>"
        o+="<textarea style='width:100%;height:40em;' name=\"text\"></textarea><br>"
        o+="<input type=\"submit\"><br>" 
        o+="</form>"
        print(html.render_admin(html.block(o.encode("utf8"))))