diff options
Diffstat (limited to 'admin')
-rw-r--r-- | admin/admin.py | 39 | ||||
-rw-r--r-- | admin/static/cccms.js | 7 | ||||
-rw-r--r-- | admin/static/style.css | 27 | ||||
-rw-r--r-- | admin/templates/index.html | 45 |
4 files changed, 118 insertions, 0 deletions
diff --git a/admin/admin.py b/admin/admin.py new file mode 100644 index 00000000..cbd92192 --- /dev/null +++ b/admin/admin.py | |||
@@ -0,0 +1,39 @@ | |||
1 | #!python3 | ||
2 | |||
3 | import pygit2 | ||
4 | from flask import Flask, render_template, jsonify, request, redirect, send_from_directory | ||
5 | from flask_dropzone import Dropzone | ||
6 | from argparse import ArgumentParser | ||
7 | |||
8 | app = Flask(__name__) | ||
9 | app.config['SECRET_KEY'] = 'OlbodTyshnokTyafveg' | ||
10 | |||
11 | app.config['PREFERRED_URL_SCHEME'] = 'https' | ||
12 | app.config['DROPZONE_SERVE_LOCAL'] = True | ||
13 | app.config['DROPZONE_MAX_FILE_SIZE'] = 128 | ||
14 | app.config['DROPZONE_UPLOAD_MULTIPLE'] = True | ||
15 | app.config['DROPZONE_PARALLEL_UPLOADS'] = 10 | ||
16 | |||
17 | app.config['DROPZONE_ALLOWED_FILE_CUSTOM'] = True | ||
18 | app.config['DROPZONE_ALLOWED_FILE_TYPE'] = '' | ||
19 | |||
20 | app.config['DROPZONE_DEFAULT_MESSAGE'] = 'Ziehe die Dateien hier hin, um sie hochzuladen oder klicken Sie zur Auswahl.' | ||
21 | |||
22 | dropzone = Dropzone(app) | ||
23 | |||
24 | @app.route("/admin", methods=['GET']) | ||
25 | def admin(): | ||
26 | repo = pygit2.Repository('.') | ||
27 | commit = repo[repo.lookup_branch("master").target] | ||
28 | |||
29 | url_root = request.url_root.replace('http://', 'https://', 1) | ||
30 | return render_template('index.html', tree = commit.tree, url_root = url_root) | ||
31 | |||
32 | if __name__ == "__main__": | ||
33 | parser = ArgumentParser(description="CCCMS") | ||
34 | parser.add_argument("-H", "--host", help="Hostname of the Flask app " + "[default %s]" % "127.0.0.1", default="127.0.0.1") | ||
35 | parser.add_argument("-P", "--port", help="Port for the Flask app " + "[default %s]" % "5000", default="5000") | ||
36 | |||
37 | args = parser.parse_args() | ||
38 | |||
39 | app.run(host=args.host, port=int(args.port)) | ||
diff --git a/admin/static/cccms.js b/admin/static/cccms.js new file mode 100644 index 00000000..873007ce --- /dev/null +++ b/admin/static/cccms.js | |||
@@ -0,0 +1,7 @@ | |||
1 | function toggle_hide(oid) { | ||
2 | el = document.getElementById(oid); | ||
3 | el.classList.toggle('hidden'); | ||
4 | } | ||
5 | |||
6 | function load_object(oid) { | ||
7 | } | ||
diff --git a/admin/static/style.css b/admin/static/style.css new file mode 100644 index 00000000..1e66d2ef --- /dev/null +++ b/admin/static/style.css | |||
@@ -0,0 +1,27 @@ | |||
1 | .hidden { | ||
2 | display: none; | ||
3 | } | ||
4 | |||
5 | .tree li { | ||
6 | margin: 0; | ||
7 | list-style-type: none; | ||
8 | } | ||
9 | |||
10 | .tree .entry_node { | ||
11 | cursor: pointer; | ||
12 | } | ||
13 | |||
14 | .tree .entry_node:after { | ||
15 | content: ' >>'; | ||
16 | } | ||
17 | |||
18 | #edit_update label { | ||
19 | display: inline-block; | ||
20 | min-width: 8em; | ||
21 | } | ||
22 | |||
23 | #page_teaser, #page_content { | ||
24 | margin: 1em; | ||
25 | width: 100%; | ||
26 | min-height: 4em; | ||
27 | } | ||
diff --git a/admin/templates/index.html b/admin/templates/index.html new file mode 100644 index 00000000..87238d50 --- /dev/null +++ b/admin/templates/index.html | |||
@@ -0,0 +1,45 @@ | |||
1 | <!DOCTYPE html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CCCMS Admin</title> | ||
5 | <meta charset="UTF-8"> | ||
6 | {{ dropzone.load_css() }} | ||
7 | {{ dropzone.style('border: 2px dashed #0087F7; min-height: 3em;') }} | ||
8 | <script type=text/javascript src="static/cccms.js"></script> | ||
9 | <link rel="stylesheet" href="/static/style.css"> | ||
10 | </head> | ||
11 | <body> | ||
12 | {{ dropzone.load_js() }} | ||
13 | |||
14 | <button onclick="toggle_hide('edit_update')">Neues Update</button> | ||
15 | <div class="hidden" id="edit_update"> | ||
16 | <form action="/admin/submit_page"> | ||
17 | <div><label for="page_title">Titel:</label><input type="text" id="page_title"/></div> | ||
18 | <div><label for="page_slug">slug: updates/2020/</label><input type="text" id="page_slug"/></div> | ||
19 | <div><label for="page_author">Author:</label><input type="text" id="page_author"/></div> | ||
20 | <div><label for="page_date">Date:</label><input type="datetime-local" id="page_date"/></div> | ||
21 | <div><label for="page_teaser">Teaser:</label><textarea name="page_teaser" id="page_teaser"></textarea></div> | ||
22 | <div><label for="page_content">Content:</label><textarea name="page_content" id="page_content"></textarea></div> | ||
23 | </form> | ||
24 | </div> | ||
25 | |||
26 | <button>Neue Page</button> | ||
27 | <button>Neues File</button> | ||
28 | <div class="droppy">{{ dropzone.create(action='/admin') }}</div> | ||
29 | |||
30 | <ul class="tree"> | ||
31 | {% for obj in tree recursive %} | ||
32 | <li> | ||
33 | {%- if obj.type_str == 'tree' -%} | ||
34 | <div class="entry_title entry_node" title="{{ obj.id }}" onclick="toggle_hide('{{ obj.id }}')">{{ obj.name }}</div> | ||
35 | <ul id="{{ obj.id }}" class="hidden">{{ loop(obj) }}</ul> | ||
36 | {%- else -%} | ||
37 | <div class="entry_title" title="{{ obj.id }}" onclick="load_object('{{ obj.id }}')">{{ obj.name }}</div> | ||
38 | {%- endif %} | ||
39 | </li> | ||
40 | {% endfor %} | ||
41 | </ul> | ||
42 | |||
43 | {{ dropzone.config() }} | ||
44 | </body> | ||
45 | </html> | ||