From 61c8a74e8419227b530e3bd0bff47d34d49c37ab Mon Sep 17 00:00:00 2001 From: crunk Date: Wed, 5 Jan 2022 18:14:45 +0100 Subject: [PATCH] added zipfile upload functionality and described workflow in notes.md --- .gitignore | 1 + README.md | 5 +++++ notes.md | 38 +++++++++++++++++++++++++++++++++ verse/start.py | 21 ++++++++++++++++-- verse/static/css/style.css | 8 +++---- verse/templates/distribusi.html | 27 ++++++++++++++++++++++- verse/uploadform.py | 24 +++++++++++++++++++++ 7 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 notes.md create mode 100644 verse/uploadform.py diff --git a/.gitignore b/.gitignore index d6e2191..a9f4413 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ build/ dist/ pip-wheel-metadata/ +verse/tmpupload/* *.db diff --git a/README.md b/README.md index c7e23aa..e2f59ef 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,8 @@ $ python deploydb.py ## Distribusi This is currently added as a git submodule but I have no clue how that actually works +to install a local git repository into your virtual env pip you can try. + +``` +$ pip install git+file:///home/full/path/to/distribusi#egg=distribusi +``` diff --git a/notes.md b/notes.md new file mode 100644 index 0000000..4e8c358 --- /dev/null +++ b/notes.md @@ -0,0 +1,38 @@ +#notes +pip install git+file:///distribusi#egg=distribusi + + +# Shit! We need entire CRUD functionality. + +##Create: + +### Uploading +User can upload based on $distribusiname field in db. +the zip file is changed to $distribusiname. +and a folder is made in the stash called $distribusiname + +### CSS editing. +a user can edit CSS of a file in the folder called $distribusiname + +### Theme selection +a user can select a CSS file from a dropdown menu. + +### Distribusi +A flag in de DB is set to true and distribusi is run on the folder of the users +called $distribusiname + +## Read: +Based on flags set in the user DB the distribusi folders are set to visible. +on the main index page there is a listing of distribusi sites. + +## Update: +Same as create, uploading just redoes the entire process. +$distribusiname is overwritten. + +CSS editing, and Theme selection is editing a single file in the folder. +$distribusiname stays the same + +Distribusi button can only be reset when a new file is uploaded. + +## Delete +$distribusiname is deleted, files are removed, visible flag is set to false. diff --git a/verse/start.py b/verse/start.py index dc2ed87..adcc308 100644 --- a/verse/start.py +++ b/verse/start.py @@ -1,4 +1,7 @@ """This is the main flask distribusi page""" +import os +from datetime import timedelta + from flask import ( render_template, redirect, @@ -25,12 +28,15 @@ from flask_login import ( from werkzeug.routing import BuildError from flask_bcrypt import generate_password_hash, check_password_hash from flask_wtf.csrf import CSRFError -from datetime import timedelta from app import create_app, db, login_manager from usermodel import User from loginform import LoginForm from registerform import RegisterForm +from uploadform import UploadForm + +# Tada! +import distribusi APP = create_app() @@ -108,7 +114,18 @@ def register(): @APP.route("/distribusi") @login_required def distribusi(): - return "distribusi" + uploadform = UploadForm() + return render_template("distribusi.html", uploadform=uploadform) + + +@APP.route("/upload", methods=["POST"]) +@login_required +def upload(): + uploadform = UploadForm() + if (uploadform.validate_on_submit()): + zipfile = uploadform.zipfile.data + zipfile.save(os.path.join(APP.config['UPLOAD_FOLDER'], zipfile.filename)) + return render_template("distribusi.html", uploadform=uploadform) @APP.route("/admin") diff --git a/verse/static/css/style.css b/verse/static/css/style.css index a601248..89e6457 100644 --- a/verse/static/css/style.css +++ b/verse/static/css/style.css @@ -1,7 +1,7 @@ body { font-family: monospace; - background-color: black; + background-color: #383C4A; color:#E0B0FF; } @@ -9,7 +9,7 @@ section#login{ width: 30%; margin-left: auto; margin-right: auto; - background-color:black; + background-color:#383C4A; text-decoration: none; } @@ -20,14 +20,14 @@ section#login form { padding-right: 15%; } -section#login .required{ +fieldset.required { padding: 6px; border: none; float: left; } section#login input[type=text], input[type=password]{ - background-color: black; + background-color: #383C4A; color: white; border: 1px solid #E0B0FF; } diff --git a/verse/templates/distribusi.html b/verse/templates/distribusi.html index a5d0c56..22539ac 100644 --- a/verse/templates/distribusi.html +++ b/verse/templates/distribusi.html @@ -1,4 +1,29 @@ {% extends "base.html" %} {% block main %} - +

Upload

+

Upload button

+
+ {{ uploadform.csrf_token }} +
+ {{ uploadform.sitename.label }} + {{ uploadform.sitename }} + {% for message in uploadform.sitename.errors %} +
{{ message }}
+ {% endfor %} +
+
+ {{ uploadform.zipfile.label }} + {{ uploadform.zipfile }} + {% for message in uploadform.zipfile.errors %} +
{{ message }}
+ {% endfor %} +
+ {{ uploadform.submit }} +
+

Theme

+

dropdown css file selector

+

Edit

+

go to CSS editor

+

Distribusi

+

run distribusi on your files

{% endblock main %} diff --git a/verse/uploadform.py b/verse/uploadform.py new file mode 100644 index 0000000..6921f45 --- /dev/null +++ b/verse/uploadform.py @@ -0,0 +1,24 @@ +from flask_wtf import FlaskForm +from flask_wtf.file import FileField, FileAllowed +from wtforms import validators +from wtforms.validators import Length +from wtforms import ( + FileField, + SubmitField, + StringField, +) + + +class UploadForm(FlaskForm): + """File upload class for a new site in distribusi-verse""" + + sitename = StringField( + "Name of your website:", + validators=[validators.InputRequired(), Length(6, 100)], + ) + zipfile = FileField( + 'Upload your zip file with content here:', + validators=[FileAllowed(['zip'], 'Zip archives only!')] + ) + + submit = SubmitField("Upload")