1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Complete wiki features

This commit is contained in:
Steffo 2019-06-20 19:57:54 +02:00
parent d4991576c9
commit a72a97736d
3 changed files with 47 additions and 11 deletions

View file

@ -13,6 +13,36 @@ rp = Royalprint("wikiedit", __name__, url_prefix="/wikiedit", template_folder=tm
required_tables={Royal, WikiPage, WikiRevision}) 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>", defaults={"title": ""}, methods=["GET", "POST"])
@rp.route("/<uuid:page_id>/<title>", methods=["GET", "POST"]) @rp.route("/<uuid:page_id>/<title>", methods=["GET", "POST"])
def wikiedit_by_id(page_id: uuid.UUID, title: str): 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": elif f.request.method == "POST":
fd = f.request.form fd = f.request.form
if "content" not in fd: if not ("title" in fd and "content" in fd and "css" in fd):
return "Missing page content", 400 return "Missing field", 400
# Create new revision # Create new revision
revision = alchemy.WikiRevision(revision_id=uuid.uuid4(), revision = alchemy.WikiRevision(revision_id=uuid.uuid4(),
page_id=page.page_id, page=page,
author_id=f.session["royal"]["uid"], author_id=f.session["royal"]["uid"],
timestamp=datetime.datetime.now(), timestamp=datetime.datetime.now(),
reason=fd.get("reason"), reason=fd.get("reason"),
@ -41,11 +71,7 @@ def wikiedit_by_id(page_id: uuid.UUID, title: str):
alchemy_session.add(revision) alchemy_session.add(revision)
# Apply changes # Apply changes
page.content = fd["content"] page.content = fd["content"]
if "title" in fd:
page.title = fd["title"] 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 page.css = fd["css"] if fd["css"] != "None" else None
alchemy_session.commit() alchemy_session.commit()
return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_id, title=page.title)) return f.redirect(f.url_for("wikiview.wikiview_by_id", page_id=page.page_id, title=page.title))

View file

@ -12,6 +12,11 @@
</span> </span>
</div> </div>
<div class="bot"> <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> <ul>
{% for page in pages %} {% 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> <li><a href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_id|string, title=page.title) }}">{{ page.title }}</a></li>

View file

@ -11,8 +11,13 @@
Wiki page Wiki page
</span> </span>
<span class="right"> <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> {% if session.royal %}
<a class="permalink no-icon" href="{{ url_for("wikiview.wikiview_by_id", page_id=page.page_id|string, title=page.title) }}">#</a> <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> </span>
</div> </div>
<div class="bot"> <div class="bot">