コード例 #1
0
ファイル: __init__.py プロジェクト: kirsle/rophako
def history(name):
    """Page history."""
    name = Wiki.url_to_name(name)

    # Look up the page.
    page = Wiki.get_page(name)
    if not page:
        flash("Wiki page not found.")
        return redirect(url_for(".index"))

    authors = dict()
    history = list()
    for rev in page["revisions"]:
        uid = rev["author"]
        if not uid in authors:
            authors[uid] = User.get_user(uid=uid)

        history.append(
            dict(
                id=rev["id"],
                author=authors[uid],
                note=rev["note"],
                pretty_time=pretty_time(Config.wiki.time_format, rev["time"]),
            )
        )

    g.info["link"] = Wiki.name_to_url(name)
    g.info["title"] = name
    g.info["history"] = history
    return template("wiki/history.html")
コード例 #2
0
ファイル: __init__.py プロジェクト: TeMbl4/rophako
def history(name):
    """Page history."""
    name = Wiki.url_to_name(name)

    # Look up the page.
    page = Wiki.get_page(name)
    if not page:
        flash("Wiki page not found.")
        return redirect(url_for(".index"))

    authors = dict()
    history = list()
    for rev in page["revisions"]:
        uid = rev["author"]
        if not uid in authors:
            authors[uid] = User.get_user(uid=uid)

        history.append(
            dict(
                id=rev["id"],
                author=authors[uid],
                note=rev["note"],
                pretty_time=pretty_time(Config.wiki.time_format, rev["time"]),
            ))

    g.info["link"] = Wiki.name_to_url(name)
    g.info["title"] = name
    g.info["history"] = history
    return template("wiki/history.html")
コード例 #3
0
ファイル: __init__.py プロジェクト: TeMbl4/rophako
def list_pages():
    """Wiki page list."""
    g.info["pages"] = [
        {"name": name, "link": Wiki.name_to_url(name)} \
            for name in Wiki.list_pages()
    ]
    return template("wiki/list.html")
コード例 #4
0
ファイル: __init__.py プロジェクト: TeMbl4/rophako
def edit():
    """Wiki page editor."""
    title = request.args.get("name", "")
    body = ""
    history = True  # Update History box is always checked by default
    note = request.args.get("note", "")

    # Editing an existing page?
    page = Wiki.get_page(title)
    if page:
        head = page["revisions"][0]
        body = head["body"]

    if request.method == "POST":
        # Submitting the form.
        action = request.form.get("action", "preview")
        title = request.form.get("name", "")
        body = request.form.get("body", "")
        history = request.form.get("history", "false") == "true"
        note = request.form.get("note", "")

        if action == "preview":
            # Just previewing it.
            g.info["preview"] = True

            # Render markdown
            g.info["rendered_body"] = Wiki.render_page(body)

            # Render emoticons.
            g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"])
        elif action == "publish":
            # Publishing! Validate inputs.
            invalid = False

            if len(title) == 0:
                invalid = True
                flash("You must have a page title.")
            if len(body) == 0:
                invalid = True
                flash("You must have a page body.")

            if not invalid:
                # Update the page.
                Wiki.edit_page(
                    author=g.info["session"]["uid"],
                    name=title,
                    body=body,
                    note=note,
                    history=history,
                )
                return redirect(
                    url_for("wiki.view_page", name=Wiki.name_to_url(title)))

    g.info["title"] = title
    g.info["body"] = body
    g.info["note"] = note
    g.info["history"] = history
    return template("wiki/edit.html")
コード例 #5
0
ファイル: __init__.py プロジェクト: kirsle/rophako
def edit():
    """Wiki page editor."""
    title = request.args.get("name", "")
    body = ""
    history = True  # Update History box is always checked by default
    note = request.args.get("note", "")

    # Editing an existing page?
    page = Wiki.get_page(title)
    if page:
        head = page["revisions"][0]
        body = head["body"]

    if request.method == "POST":
        # Submitting the form.
        action = request.form.get("action", "preview")
        title = request.form.get("name", "")
        body = request.form.get("body", "")
        history = request.form.get("history", "false") == "true"
        note = request.form.get("note", "")

        if action == "preview":
            # Just previewing it.
            g.info["preview"] = True

            # Render markdown
            g.info["rendered_body"] = Wiki.render_page(body)

            # Render emoticons.
            g.info["rendered_body"] = Emoticons.render(g.info["rendered_body"])
        elif action == "publish":
            # Publishing! Validate inputs.
            invalid = False

            if len(title) == 0:
                invalid = True
                flash("You must have a page title.")
            if len(body) == 0:
                invalid = True
                flash("You must have a page body.")

            if not invalid:
                # Update the page.
                Wiki.edit_page(author=g.info["session"]["uid"], name=title, body=body, note=note, history=history)
                return redirect(url_for("wiki.view_page", name=Wiki.name_to_url(title)))

    g.info["title"] = title
    g.info["body"] = body
    g.info["note"] = note
    g.info["history"] = history
    return template("wiki/edit.html")
コード例 #6
0
ファイル: __init__.py プロジェクト: kirsle/rophako
def delete_revision(name, revision):
    """Delete a wiki page revision from history."""
    link = name
    name = Wiki.url_to_name(name)

    if request.method == "POST":
        Wiki.delete_history(name, revision)
        flash("Revision deleted.")
        return redirect(url_for("wiki.view_page", name=Wiki.name_to_url(name)))

    g.info["confirm_url"] = url_for("wiki.delete_revision", name=link, revision=revision)
    g.info["title"] = name
    g.info["type"] = "revision"
    return template("wiki/delete.html")
コード例 #7
0
ファイル: __init__.py プロジェクト: TeMbl4/rophako
def delete_revision(name, revision):
    """Delete a wiki page revision from history."""
    link = name
    name = Wiki.url_to_name(name)

    if request.method == "POST":
        Wiki.delete_history(name, revision)
        flash("Revision deleted.")
        return redirect(url_for("wiki.view_page", name=Wiki.name_to_url(name)))

    g.info["confirm_url"] = url_for("wiki.delete_revision",
                                    name=link,
                                    revision=revision)
    g.info["title"] = name
    g.info["type"] = "revision"
    return template("wiki/delete.html")
コード例 #8
0
ファイル: __init__.py プロジェクト: kirsle/rophako
def list_pages():
    """Wiki page list."""
    g.info["pages"] = [{"name": name, "link": Wiki.name_to_url(name)} for name in Wiki.list_pages()]
    return template("wiki/list.html")
コード例 #9
0
ファイル: __init__.py プロジェクト: kirsle/rophako
def index():
    """Wiki index. Redirects to the default page from the config."""
    default = Wiki.name_to_url(Config.wiki.default_page)
    return redirect(url_for("wiki.view_page", name=default))
コード例 #10
0
ファイル: __init__.py プロジェクト: TeMbl4/rophako
def index():
    """Wiki index. Redirects to the default page from the config."""
    default = Wiki.name_to_url(Config.wiki.default_page)
    return redirect(url_for("wiki.view_page", name=default))