mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Complete wiki features
This commit is contained in:
parent
d4991576c9
commit
a72a97736d
3 changed files with 47 additions and 11 deletions
|
@ -13,6 +13,36 @@ rp = Royalprint("wikiedit", __name__, url_prefix="/wikiedit", template_folder=tm
|
|||
required_tables={Royal, WikiPage, WikiRevision})
|
||||
|
||||
|
||||
@rp.route("/newpage", methods=["GET", "POST"])
|
||||
def wikiedit_newpage():
|
||||
if "royal" not in f.session:
|
||||
return "Please login to edit wiki pages", 403
|
||||
|
||||
if f.request.method == "GET":
|
||||
return f.render_template("wikiedit_page.html", page=None)
|
||||
|
||||
elif f.request.method == "POST":
|
||||
fd = f.request.form
|
||||
if not ("title" in fd and "content" in fd and "css" in fd):
|
||||
return "Missing field", 400
|
||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||
page = alchemy.WikiPage(page_id=uuid.uuid4(),
|
||||
title=fd["title"],
|
||||
content=fd["content"],
|
||||
format="markdown",
|
||||
css=fd["css"] if fd["css"] != "None" else None)
|
||||
revision = alchemy.WikiRevision(revision_id=uuid.uuid4(),
|
||||
page=page,
|
||||
author_id=f.session["royal"]["uid"],
|
||||
timestamp=datetime.datetime.now(),
|
||||
reason=fd.get("reason"),
|
||||
diff="\n".join(difflib.unified_diff([], page.content.split("\n"))))
|
||||
alchemy_session.add(page)
|
||||
alchemy_session.add(revision)
|
||||
alchemy_session.commit()
|
||||
return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_id, title=page.title))
|
||||
|
||||
|
||||
@rp.route("/<uuid:page_id>", defaults={"title": ""}, methods=["GET", "POST"])
|
||||
@rp.route("/<uuid:page_id>/<title>", methods=["GET", "POST"])
|
||||
def wikiedit_by_id(page_id: uuid.UUID, title: str):
|
||||
|
@ -29,11 +59,11 @@ def wikiedit_by_id(page_id: uuid.UUID, title: str):
|
|||
|
||||
elif f.request.method == "POST":
|
||||
fd = f.request.form
|
||||
if "content" not in fd:
|
||||
return "Missing page content", 400
|
||||
if not ("title" in fd and "content" in fd and "css" in fd):
|
||||
return "Missing field", 400
|
||||
# Create new revision
|
||||
revision = alchemy.WikiRevision(revision_id=uuid.uuid4(),
|
||||
page_id=page.page_id,
|
||||
page=page,
|
||||
author_id=f.session["royal"]["uid"],
|
||||
timestamp=datetime.datetime.now(),
|
||||
reason=fd.get("reason"),
|
||||
|
@ -41,11 +71,7 @@ def wikiedit_by_id(page_id: uuid.UUID, title: str):
|
|||
alchemy_session.add(revision)
|
||||
# Apply changes
|
||||
page.content = fd["content"]
|
||||
if "title" in fd:
|
||||
page.title = fd["title"]
|
||||
if "format" in fd:
|
||||
page.format = fd["format"]
|
||||
if "css" in fd:
|
||||
page.css = fd["css"] if fd["css"] != "None" else None
|
||||
alchemy_session.commit()
|
||||
return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_id, title=page.title))
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
{% if session.royal %}
|
||||
<a href="{{ url_for("wikiedit.wikiedit_newpage") }}" class="btn no-icon">Crea nuova pagina</a>
|
||||
{% else %}
|
||||
<button disabled title="Devi fare il login per creare nuove pagine!">Crea nuova pagina</button>
|
||||
{% endif %}
|
||||
<ul>
|
||||
{% for page in pages %}
|
||||
<li><a href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_id|string, title=page.title) }}">{{ page.title }}</a></li>
|
||||
|
|
|
@ -11,8 +11,13 @@
|
|||
Wiki page
|
||||
</span>
|
||||
<span class="right">
|
||||
<a class="permalink no-icon" href="{{ url_for("wikiedit.wikiedit_by_id", page_id=page.page_id|string, title=page.title) }}">e</a>
|
||||
<a class="permalink no-icon" href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_id|string, title=page.title) }}">#</a>
|
||||
{% if session.royal %}
|
||||
<a class="edit no-icon" href="{{ url_for("wikiedit.wikiedit_by_id", page_id=page.page_id|string, title=page.title) }}">Modifica</a>
|
||||
{% else %}
|
||||
<a class="edit no-icon faded" title="Devi fare il login per creare nuove pagine!">Modifica</a>
|
||||
{% endif %}
|
||||
|
|
||||
<a class="permalink no-icon" href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_id|string, title=page.title) }}">Permalink</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="bot">
|
||||
|
|
Loading…
Reference in a new issue