aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pysite/views/main/ws_test_rst.py15
-rw-r--r--pysite/views/wiki/edit.py18
-rw-r--r--pysite/views/wiki/page.py30
-rw-r--r--pysite/views/ws/rst.py27
-rw-r--r--templates/main/ws_test_rst.html39
-rw-r--r--templates/wiki/page_edit.html11
-rw-r--r--templates/wiki/page_missing.html11
-rw-r--r--templates/wiki/page_view.html11
8 files changed, 157 insertions, 5 deletions
diff --git a/pysite/views/main/ws_test_rst.py b/pysite/views/main/ws_test_rst.py
new file mode 100644
index 00000000..9c2ee805
--- /dev/null
+++ b/pysite/views/main/ws_test_rst.py
@@ -0,0 +1,15 @@
+# coding=utf-8
+import os
+
+from pysite.base_route import RouteView
+
+
+class WSTest(RouteView):
+ path = "/ws_test_rst"
+ name = "ws_test_rst"
+
+ def get(self):
+ return self.render(
+ "main/ws_test_rst.html",
+ server_name=os.environ.get("SERVER_NAME", "localhost")
+ )
diff --git a/pysite/views/wiki/edit.py b/pysite/views/wiki/edit.py
index 5c914c16..fac5532e 100644
--- a/pysite/views/wiki/edit.py
+++ b/pysite/views/wiki/edit.py
@@ -1,13 +1,25 @@
# coding=utf-8
+from flask import url_for
+from werkzeug.utils import redirect
+
from pysite.base_route import RouteView
from pysite.constants import ALL_STAFF_ROLES
-from pysite.decorators import require_roles
+from pysite.decorators import require_roles, csrf
+from pysite.mixins import DBMixin
-class EditView(RouteView):
+class EditView(RouteView, DBMixin):
path = "/edit/<path:page>" # "path" means that it accepts slashes
name = "edit"
+ table_name = "wiki"
+ table_primary_key = "slug"
+
@require_roles(*ALL_STAFF_ROLES)
def get(self, page):
- return self.render("staff/staff.html")
+ return self.render("wiki/page_edit.html", page=page)
+
+ @require_roles(*ALL_STAFF_ROLES)
+ @csrf
+ def post(self, page):
+ return redirect(url_for("wiki.page", page=page), code=303) # Redirect, ensuring a GET
diff --git a/pysite/views/wiki/page.py b/pysite/views/wiki/page.py
index 6f9f15c1..70cec002 100644
--- a/pysite/views/wiki/page.py
+++ b/pysite/views/wiki/page.py
@@ -1,10 +1,36 @@
# coding=utf-8
+from flask import url_for, redirect
+
from pysite.base_route import RouteView
+from pysite.constants import ALL_STAFF_ROLES
+from pysite.mixins import DBMixin
-class PageView(RouteView):
+class PageView(RouteView, DBMixin):
path = "/wiki/<path:page>" # "path" means that it accepts slashes
name = "page"
+ table_name = "wiki"
+ table_primary_key = "slug"
+
def get(self, page):
- return self.render("wiki/index.html")
+ obj = self.db.get(self.table_name, page)
+
+ if obj is None:
+ if self.is_staff():
+ return redirect(url_for("wiki.edit", page=page))
+
+ return self.render("wiki/page_missing.html", page=page)
+ return self.render("wiki/page_view.html", page=page, data=obj)
+
+ def is_staff(self):
+ if not self.logged_in:
+ return False
+
+ roles = self.user_data["roles"]
+
+ for role in roles:
+ if role in ALL_STAFF_ROLES:
+ return True
+
+ return False
diff --git a/pysite/views/ws/rst.py b/pysite/views/ws/rst.py
new file mode 100644
index 00000000..c85c10a0
--- /dev/null
+++ b/pysite/views/ws/rst.py
@@ -0,0 +1,27 @@
+# coding=utf-8
+import logging
+
+from docutils.core import publish_parts
+from geventwebsocket.websocket import WebSocket
+
+from pysite.websockets import WS
+
+
+class RSTWebsocket(WS):
+ path = "/rst"
+ name = "ws.rst"
+
+ def __init__(self, socket: WebSocket):
+ super().__init__(socket)
+ self.log = logging.getLogger()
+
+ def on_open(self):
+ self.log.debug("RST | WS opened.")
+ self.send("Hey, welcome!")
+
+ def on_message(self, message):
+ self.log.debug(f"RST | Message: {message}")
+ self.send(publish_parts(source=message, writer_name="html5")["html_body"])
+
+ def on_close(self):
+ self.log.debug("RST | WS closed.")
diff --git a/templates/main/ws_test_rst.html b/templates/main/ws_test_rst.html
new file mode 100644
index 00000000..a0bae79b
--- /dev/null
+++ b/templates/main/ws_test_rst.html
@@ -0,0 +1,39 @@
+{% extends "main/base.html" %}
+{% block title %}WS Test{% endblock %}
+{% block og_title %}WS Test{% endblock %}
+{% block og_description %}A test page for our Websockets implementation{% endblock %}
+{% block content %}
+ <div class="uk-container uk-section">
+ <h1>Enter some text to test.</h1>
+
+ <textarea title="RST Input" id="rst"></textarea>
+ <input type="button" value="Submit" id="submit-button" />
+
+ <br />
+
+ <div id="output"></div>
+
+ <script type="application/javascript">
+ let ws = new WebSocket("wss://api.{{ server_name }}/ws/rst");
+
+ ws.onopen = function(event) {
+ console.log("WS opened! Use send() to send a message.");
+ };
+
+ ws.onmessage = function (event) {
+ document.getElementById("output").innerHTML = event.data;
+ };
+
+ function send(text) {
+ console.log("-> " + text);
+ ws.send(text);
+ }
+
+ document.getElementById("submit-button").onclick = function() {
+ send(
+ document.getElementById("rst").value
+ );
+ }
+ </script>
+ </div>
+{% endblock %}
diff --git a/templates/wiki/page_edit.html b/templates/wiki/page_edit.html
new file mode 100644
index 00000000..5601cbbf
--- /dev/null
+++ b/templates/wiki/page_edit.html
@@ -0,0 +1,11 @@
+{% extends "main/base.html" %}
+{% block title %}Wiki | Home{% endblock %}
+{% block og_title %}Wiki | Home{% endblock %}
+{% block og_description %}Landing page for the wiki{% endblock %}
+{% block content %}
+ <div class="uk-container uk-section">
+ <h1 class="uk-title uk-text-center">
+ Placeholder text.
+ </h1>
+ </div>
+{% endblock %} \ No newline at end of file
diff --git a/templates/wiki/page_missing.html b/templates/wiki/page_missing.html
new file mode 100644
index 00000000..5601cbbf
--- /dev/null
+++ b/templates/wiki/page_missing.html
@@ -0,0 +1,11 @@
+{% extends "main/base.html" %}
+{% block title %}Wiki | Home{% endblock %}
+{% block og_title %}Wiki | Home{% endblock %}
+{% block og_description %}Landing page for the wiki{% endblock %}
+{% block content %}
+ <div class="uk-container uk-section">
+ <h1 class="uk-title uk-text-center">
+ Placeholder text.
+ </h1>
+ </div>
+{% endblock %} \ No newline at end of file
diff --git a/templates/wiki/page_view.html b/templates/wiki/page_view.html
new file mode 100644
index 00000000..5601cbbf
--- /dev/null
+++ b/templates/wiki/page_view.html
@@ -0,0 +1,11 @@
+{% extends "main/base.html" %}
+{% block title %}Wiki | Home{% endblock %}
+{% block og_title %}Wiki | Home{% endblock %}
+{% block og_description %}Landing page for the wiki{% endblock %}
+{% block content %}
+ <div class="uk-container uk-section">
+ <h1 class="uk-title uk-text-center">
+ Placeholder text.
+ </h1>
+ </div>
+{% endblock %} \ No newline at end of file