First semi-working prototype, just for distribusify

This commit is contained in:
crunk 2022-01-07 16:55:40 +01:00
parent 41402e688d
commit 582978287c
11 changed files with 135 additions and 51 deletions

View File

@ -11,7 +11,9 @@ This particular work in progress project is an attempt to make distribusi into a
This project is made for Autonomous Practices at the WDKA in Rotterdam. This project is made for Autonomous Practices at the WDKA in Rotterdam.
## Work in progress ## Work in progress
Nothing is working yet but I need to do this project in smaller steps then everything in one go. ~~Nothing is working yet but I need to do this project in smaller steps then everything in one go.~~
So far, in this project you can make a user, upload a zip, make a website name and have distribusi
run it for you.
## Start your engines! ## Start your engines!

View File

@ -2,7 +2,9 @@ def deploy():
"""Run deployment of database.""" """Run deployment of database."""
from app import create_app, db from app import create_app, db
from flask_migrate import upgrade, migrate, init, stamp from flask_migrate import upgrade, migrate, init, stamp
from usermodel import User
# This model is required for flask_migrate to make the table
from usermodel import User # noqa: F401
app = create_app() app = create_app()
app.app_context().push() app.app_context().push()

8
verse/distribusiform.py Normal file
View File

@ -0,0 +1,8 @@
from flask_wtf import FlaskForm
from wtforms import SubmitField
class DistribusiForm(FlaskForm):
"""Distribusi class to launch your distribusi website"""
submit = SubmitField("Distribusi!")

View File

@ -1,7 +1,10 @@
"""This is the main flask distribusi page""" """This is the main flask distribusi page"""
import os import os
import zipfile
import shutil
from datetime import timedelta from datetime import timedelta
from flask import ( from flask import (
render_template, render_template,
redirect, redirect,
@ -31,9 +34,12 @@ from flask_wtf.csrf import CSRFError
from app import create_app, db, login_manager from app import create_app, db, login_manager
from usermodel import User from usermodel import User
# Forms!
from loginform import LoginForm from loginform import LoginForm
from registerform import RegisterForm from registerform import RegisterForm
from uploadform import UploadForm from uploadform import UploadForm
from distribusiform import DistribusiForm
# Tada! # Tada!
from distribusi.cli import build_argparser from distribusi.cli import build_argparser
@ -112,21 +118,64 @@ def register():
return render_template("register.html", registerform=registerform) return render_template("register.html", registerform=registerform)
@APP.route("/distribusi") @APP.route("/distribusi", methods=["GET", "POST"])
@login_required @login_required
def distribusi(): def distribusi():
uploadform = UploadForm() uploadform = UploadForm()
return render_template("distribusi.html", uploadform=uploadform) distribusiform = DistribusiForm()
user = User.query.filter_by(email=current_user.email).first()
if user.distribusiname is None:
print("nothing to deploy!")
if distribusiform.validate_on_submit():
zipfilename = "{}.zip".format(user.distribusiname)
copyzipfile = os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)
newuserfolder = os.path.join("stash", user.distribusiname)
os.mkdir(newuserfolder)
shutil.copy(copyzipfile, newuserfolder)
unzipfile = os.path.join(newuserfolder, zipfilename)
with zipfile.ZipFile(unzipfile, "r") as zip_ref:
# To do, replace extractall with inspection and extract
zip_ref.extractall(newuserfolder)
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
os.remove(os.path.join(newuserfolder, zipfilename))
# Make sure nothing can be executed from the upload folder
parser = build_argparser()
args = parser.parse_args()
distribusify(args, newuserfolder)
return render_template("index.html")
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
)
return template
@APP.route("/upload", methods=["POST"]) @APP.route("/upload", methods=["POST"])
@login_required @login_required
def upload(): def upload():
success = False
uploadform = UploadForm() uploadform = UploadForm()
if (uploadform.validate_on_submit()): distribusiform = DistribusiForm()
if uploadform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first()
user.distribusiname = uploadform.sitename.data
db.session.commit()
zipfilename = "{}.zip".format(user.distribusiname)
zipfile = uploadform.zipfile.data zipfile = uploadform.zipfile.data
zipfile.save(os.path.join(APP.config['UPLOAD_FOLDER'], zipfile.filename)) zipfile.save(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
return render_template("distribusi.html", uploadform=uploadform)
success = True
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
success=success,
)
return template
@APP.route("/admin") @APP.route("/admin")

View File

@ -5,7 +5,7 @@ body
color:#E0B0FF; color:#E0B0FF;
} }
section#login{ div#login{
width: 30%; width: 30%;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
@ -13,26 +13,34 @@ section#login{
text-decoration: none; text-decoration: none;
} }
section#login form { div#login form {
width: 200px; width: 200px;
margin: 0 auto; margin: 0 auto;
padding-left: 15%; padding-left: 15%;
padding-right: 15%; padding-right: 15%;
} }
fieldset.required { div#login input[type=text], input[type=password]{
padding: 6px;
border: none;
float: left;
}
section#login input[type=text], input[type=password]{
background-color: #383C4A; background-color: #383C4A;
color: white; color: white;
border: 1px solid #E0B0FF; border: 1px solid #E0B0FF;
} }
section#buttons{ div#upload form {
padding-right: 15%;
}
.workflow{
margin-top: 1em;
padding: 0.5em;
width: 25em;
border: 3px solid #E0B0FF;
background-color:#383C4A;
text-decoration: none;
}
div#buttons{
position: fixed; position: fixed;
top: 0.5em; top: 0.5em;
right: 0.5em; right: 0.5em;
@ -42,27 +50,31 @@ section#buttons{
align-items: center; align-items: center;
} }
section#buttons .logout input{ div#buttons .logout input{
border: none; border: none;
background: #E0B0FF; background: #E0B0FF;
text-decoration: none; text-decoration: none;
margin: 1px; margin: 1px;
} }
section#buttons .distribusi input{ div#buttons .distribusi input{
border: none; border: none;
background: #fff600; background: #fff600;
text-decoration: none; text-decoration: none;
margin: 1px; margin: 1px;
} }
.signin input { fieldset.required {
border: none;
}
.button input {
border: none; border: none;
background: #E0B0FF; background: #E0B0FF;
text-decoration: none; text-decoration: none;
margin: 1px; margin: 1px;
} }
.signin input:hover { .button input:hover {
background: #60337F; background: #60337F;
} }

View File

@ -1,8 +1,8 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block main %} {% block main %}
<section id="upload"> <div id="upload" class="workflow">
<h3>Upload</h3> <h3>Step 1: Upload</h3>
<p>Upload button</p> <p>Upload your files here, the only accepted file type is a zip file</p>
<form method="POST" enctype="multipart/form-data" action="{{ url_for('upload') }}"> <form method="POST" enctype="multipart/form-data" action="{{ url_for('upload') }}">
{{ uploadform.csrf_token }} {{ uploadform.csrf_token }}
<fieldset class="required"> <fieldset class="required">
@ -19,20 +19,32 @@
<div class="error">{{ message }}</div> <div class="error">{{ message }}</div>
{% endfor %} {% endfor %}
</fieldset> </fieldset>
<fieldset class="button required">
{{ uploadform.submit }} {{ uploadform.submit }}
</fieldset>
</form> </form>
</section> {% if success %}
<section id="theme"> <p>Your file has been uploaded successfully</h2>
<h3>Theme</h3> {% endif %}
</div>
<div id="theme" class="workflow">
<h3>Step 2: Theme</h3>
<p>dropdown css file selector</p> <p>dropdown css file selector</p>
</section> </div>
<section id="edit"> <div id="edit" class="workflow">
<h3>Edit</h3> <h3>Step 3: Edit</h3>
<p>go to CSS editor</p> <p>go to CSS editor</p>
</section> </div>
<section id="distribusi"> <div id="distribusi" class="workflow">
<h3>Distribusi</h3> <h3>Step 4: Distribusi</h3>
<p>run distribusi on your files</p> <p>run distribusi on your files, this will generate your website and make
</section> your content public.</p>
<form method="POST" enctype="multipart/form-data" action="{{ url_for('distribusi') }}">
{{ distribusiform.csrf_token }}
<fieldset class="button required">
{{ distribusiform.submit }}
</fieldset>
</form>
</div>
{% endblock main %} {% endblock main %}

View File

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block main %} {% block main %}
<section id="buttons"> <div id="buttons">
{% if not current_user.is_authenticated %} {% if not current_user.is_authenticated %}
<div class="signin"> <div class="signin">
<a href="/login"> <a href="/login">
@ -24,14 +24,14 @@
</a> </a>
</div> </div>
{% endif %} {% endif %}
</section> </div>
{% if current_user.is_authenticated %} {% if current_user.is_authenticated %}
<h2> Hi {{ current_user.email }}! </h2> <h2> Hi {{ current_user.email }}! </h2>
{% endif %} {% endif %}
<!-- a section with all the distribusis listed in the distribusiverse --> <!-- a div with all the distribusis listed in the distribusiverse -->
<section id="distribusiverse"> <div id="distribusiverse">
<h2>List of distribusis</h2> <h2>List of distribusis</h2>
<ul> <ul>
<li>CCL</li> <li>CCL</li>
@ -41,5 +41,5 @@
<li>Other Names</li> <li>Other Names</li>
<li>List of stuff</li> <li>List of stuff</li>
</ul> </ul>
</section> </div>
{% endblock %} {% endblock %}

View File

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block main %} {% block main %}
<section id="login"> <div id="login">
<form class="form" action="{{ url_for('login') }}" method="post"> <form class="form" action="{{ url_for('login') }}" method="post">
{{ loginform.csrf_token }} {{ loginform.csrf_token }}
<fieldset class="required"> <fieldset class="required">
@ -17,10 +17,10 @@
<div class="error">{{ message }}</div> <div class="error">{{ message }}</div>
{% endfor %} {% endfor %}
</fieldset> </fieldset>
<fieldset class="signin required"> <fieldset class="button required">
{{ loginform.submit }} {{ loginform.submit }}
<a href="/forgotpassword">Forgot Password?</a> <a href="/forgotpassword">Forgot Password?</a>
</fieldset> </fieldset>
</form> </form>
</section> </div>
{% endblock main %} {% endblock main %}

View File

@ -1,6 +1,6 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block main %} {% block main %}
<section id="login"> <div id="login">
<form class="form" action="{{ url_for('register') }}" method="post"> <form class="form" action="{{ url_for('register') }}" method="post">
{{ registerform.csrf_token }} {{ registerform.csrf_token }}
<fieldset class="required"> <fieldset class="required">
@ -24,9 +24,9 @@
<div class="error">{{ message }}</div> <div class="error">{{ message }}</div>
{% endfor %} {% endfor %}
</fieldset> </fieldset>
<fieldset class="signin required"> <fieldset class="button required">
{{ registerform.submit }} {{ registerform.submit }}
</fieldset> </fieldset>
</form> </form>
</section> </div>
{% endblock main %} {% endblock main %}

View File

@ -3,7 +3,6 @@ from flask_wtf.file import FileField, FileAllowed
from wtforms import validators from wtforms import validators
from wtforms.validators import Length from wtforms.validators import Length
from wtforms import ( from wtforms import (
FileField,
SubmitField, SubmitField,
StringField, StringField,
) )
@ -11,14 +10,14 @@ from wtforms import (
class UploadForm(FlaskForm): class UploadForm(FlaskForm):
"""File upload class for a new site in distribusi-verse""" """File upload class for a new site in distribusi-verse"""
sitename = StringField( sitename = StringField(
"Name of your website:", "Name of your website:",
validators=[validators.InputRequired(), Length(6, 100)], validators=[validators.InputRequired(), Length(6, 100)],
) )
zipfile = FileField( zipfile = FileField(
'Upload your zip file with content here:', "Upload your zip file with content here:",
validators=[FileAllowed(['zip'], 'Zip archives only!')] validators=[FileAllowed(["zip"], "Zip archives only!")],
) )
submit = SubmitField("Upload") submit = SubmitField("Upload")

View File

@ -14,4 +14,4 @@ class User(UserMixin, db.Model):
visible = db.Column(db.Boolean, server_default=u'false') visible = db.Column(db.Boolean, server_default=u'false')
def __repr__(self): def __repr__(self):
return "<User %r>" % self.username return "<User %r>" % self.email