mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-12-17 23:24:20 +00:00
Working wiki edits
This commit is contained in:
parent
fb0f3d9395
commit
d4991576c9
1 changed files with 26 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
||||||
import flask as f
|
import flask as f
|
||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
|
import datetime
|
||||||
|
import difflib
|
||||||
from ... import Royalprint
|
from ... import Royalprint
|
||||||
from ....database.tables import Royal, WikiPage, WikiRevision
|
from ....database.tables import Royal, WikiPage, WikiRevision
|
||||||
|
|
||||||
|
@ -14,6 +16,9 @@ rp = Royalprint("wikiedit", __name__, url_prefix="/wikiedit", template_folder=tm
|
||||||
@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):
|
||||||
|
if "royal" not in f.session:
|
||||||
|
return "Please login to edit wiki pages", 403
|
||||||
|
|
||||||
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
alchemy, alchemy_session = f.current_app.config["ALCHEMY"], f.current_app.config["ALCHEMY_SESSION"]
|
||||||
page = alchemy_session.query(alchemy.WikiPage).filter(alchemy.WikiPage.page_id == page_id).one_or_none()
|
page = alchemy_session.query(alchemy.WikiPage).filter(alchemy.WikiPage.page_id == page_id).one_or_none()
|
||||||
if page is None:
|
if page is None:
|
||||||
|
@ -23,4 +28,24 @@ def wikiedit_by_id(page_id: uuid.UUID, title: str):
|
||||||
return f.render_template("wikiedit_page.html", page=page)
|
return f.render_template("wikiedit_page.html", page=page)
|
||||||
|
|
||||||
elif f.request.method == "POST":
|
elif f.request.method == "POST":
|
||||||
return ""
|
fd = f.request.form
|
||||||
|
if "content" not in fd:
|
||||||
|
return "Missing page content", 400
|
||||||
|
# Create new revision
|
||||||
|
revision = alchemy.WikiRevision(revision_id=uuid.uuid4(),
|
||||||
|
page_id=page.page_id,
|
||||||
|
author_id=f.session["royal"]["uid"],
|
||||||
|
timestamp=datetime.datetime.now(),
|
||||||
|
reason=fd.get("reason"),
|
||||||
|
diff="\n".join(difflib.unified_diff(page.content.split("\n"), fd["content"].split("\n"))))
|
||||||
|
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))
|
||||||
|
|
Loading…
Reference in a new issue