Browse Source

First semi-working prototype, just for distribusify

current_wdka_release
crunk 3 years ago
parent
commit
582978287c
  1. 4
      README.md
  2. 4
      verse/deploydb.py
  3. 8
      verse/distribusiform.py
  4. 59
      verse/start.py
  5. 40
      verse/static/css/style.css
  6. 40
      verse/templates/distribusi.html
  7. 10
      verse/templates/index.html
  8. 6
      verse/templates/login.html
  9. 6
      verse/templates/register.html
  10. 7
      verse/uploadform.py
  11. 2
      verse/usermodel.py

4
README.md

@ -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.
## 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!

4
verse/deploydb.py

@ -2,7 +2,9 @@ def deploy():
"""Run deployment of database."""
from app import create_app, db
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.app_context().push()

8
verse/distribusiform.py

@ -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!")

59
verse/start.py

@ -1,7 +1,10 @@
"""This is the main flask distribusi page"""
import os
import zipfile
import shutil
from datetime import timedelta
from flask import (
render_template,
redirect,
@ -31,9 +34,12 @@ from flask_wtf.csrf import CSRFError
from app import create_app, db, login_manager
from usermodel import User
# Forms!
from loginform import LoginForm
from registerform import RegisterForm
from uploadform import UploadForm
from distribusiform import DistribusiForm
# Tada!
from distribusi.cli import build_argparser
@ -112,21 +118,64 @@ def register():
return render_template("register.html", registerform=registerform)
@APP.route("/distribusi")
@APP.route("/distribusi", methods=["GET", "POST"])
@login_required
def distribusi():
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"])
@login_required
def upload():
success = False
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.save(os.path.join(APP.config['UPLOAD_FOLDER'], zipfile.filename))
return render_template("distribusi.html", uploadform=uploadform)
zipfile.save(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
success = True
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
success=success,
)
return template
@APP.route("/admin")

40
verse/static/css/style.css

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

40
verse/templates/distribusi.html

@ -1,8 +1,8 @@
{% extends "base.html" %}
{% block main %}
<section id="upload">
<h3>Upload</h3>
<p>Upload button</p>
<div id="upload" class="workflow">
<h3>Step 1: Upload</h3>
<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') }}">
{{ uploadform.csrf_token }}
<fieldset class="required">
@ -19,20 +19,32 @@
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="button required">
{{ uploadform.submit }}
</fieldset>
</form>
</section>
<section id="theme">
<h3>Theme</h3>
{% if success %}
<p>Your file has been uploaded successfully</h2>
{% endif %}
</div>
<div id="theme" class="workflow">
<h3>Step 2: Theme</h3>
<p>dropdown css file selector</p>
</section>
<section id="edit">
<h3>Edit</h3>
</div>
<div id="edit" class="workflow">
<h3>Step 3: Edit</h3>
<p>go to CSS editor</p>
</section>
<section id="distribusi">
<h3>Distribusi</h3>
<p>run distribusi on your files</p>
</section>
</div>
<div id="distribusi" class="workflow">
<h3>Step 4: Distribusi</h3>
<p>run distribusi on your files, this will generate your website and make
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 %}

10
verse/templates/index.html

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

6
verse/templates/login.html

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

6
verse/templates/register.html

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

7
verse/uploadform.py

@ -3,7 +3,6 @@ from flask_wtf.file import FileField, FileAllowed
from wtforms import validators
from wtforms.validators import Length
from wtforms import (
FileField,
SubmitField,
StringField,
)
@ -11,14 +10,14 @@ from wtforms import (
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!')]
"Upload your zip file with content here:",
validators=[FileAllowed(["zip"], "Zip archives only!")],
)
submit = SubmitField("Upload")

2
verse/usermodel.py

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

Loading…
Cancel
Save