Browse Source

Css Theme selector buggy as hell, but it works for a bit.

current_wdka_release
crunk 3 years ago
parent
commit
fbd1887753
  1. 8
      verse/forms/distribusiform.py
  2. 23
      verse/forms/loginform.py
  3. 32
      verse/forms/registerform.py
  4. 21
      verse/forms/themeform.py
  5. 23
      verse/forms/uploadform.py
  6. 68
      verse/start.py
  7. 15
      verse/templates/distribusi.html
  8. 6
      verse/themes/hacking.css
  9. 4
      verse/themes/peachsunset.css
  10. 8
      verse/themes/wdka.css

8
verse/forms/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!")

23
verse/forms/loginform.py

@ -0,0 +1,23 @@
"""Login form to validate user."""
from wtforms import (
StringField,
SubmitField,
PasswordField,
)
from wtforms import validators
from wtforms.validators import Length, Email
from flask_wtf import FlaskForm
class LoginForm(FlaskForm):
"""Login distribusiverse form class."""
email = StringField(
"Email address:",
validators=[validators.InputRequired(), Email(), Length(6, 64)],
)
password = PasswordField(
"Password:", validators=[validators.InputRequired(), Length(12, 72)]
)
submit = SubmitField("Sign In")

32
verse/forms/registerform.py

@ -0,0 +1,32 @@
"""Register form to make a new user."""
from wtforms import (
StringField,
SubmitField,
PasswordField,
)
from wtforms import validators
from wtforms.validators import Length, Email, EqualTo
from flask_wtf import FlaskForm
class RegisterForm(FlaskForm):
"""Register for distribusi-verse form class"""
email = StringField(
"Email address:",
validators=[validators.InputRequired(), Email(), Length(6, 64)],
)
password = PasswordField(
"New password:",
validators=[validators.InputRequired(), Length(12, 72)],
)
confirmpassword = PasswordField(
"Confirm your password:",
validators=[
validators.InputRequired(),
Length(12, 72),
EqualTo("password", message="Passwords must match !"),
],
)
submit = SubmitField("Register to Distribusi-verse")

21
verse/forms/themeform.py

@ -0,0 +1,21 @@
"""Form object declaration."""
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import validators
from wtforms import (
RadioField,
SubmitField,
)
class ThemeForm(FlaskForm):
"""Publication upload form."""
theme = RadioField(
"Select your theme:",
choices=[
("hacking", "Hacking"),
("peachsunset", "Peach sunset"),
("wdka", "WdkA")
],
)
save = SubmitField("Save")

23
verse/forms/uploadform.py

@ -0,0 +1,23 @@
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import validators
from wtforms.validators import Length
from wtforms import (
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")

68
verse/start.py

@ -37,10 +37,11 @@ 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
from forms.loginform import LoginForm
from forms.registerform import RegisterForm
from forms.uploadform import UploadForm
from forms.distribusiform import DistribusiForm
from forms.themeform import ThemeForm
# Tada!
from distribusi.cli import build_argparser
@ -129,32 +130,35 @@ def register():
def distribusi():
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
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)
userfolder = os.path.join("stash", user.distribusiname)
unzipfile = os.path.join(userfolder, zipfilename)
with zipfile.ZipFile(unzipfile, "r") as zip_ref:
# To do, replace extractall with inspection and extract
zip_ref.extractall(newuserfolder)
zip_ref.extractall(userfolder)
os.remove(os.path.join(userfolder, zipfilename))
# To Do: Make sure nothing can be executed from the upload folder
# add the css file
cssfile = ""
for filename in os.listdir(userfolder):
if filename.endswith('.css'):
cssfile = os.path.join(userfolder, filename)
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)
args = parser.parse_args(['-s', cssfile])
distribusify(args, userfolder)
return redirect(url_for("index"))
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
)
return template
@ -165,6 +169,7 @@ def upload():
success = False
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
if uploadform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first()
user.distribusiname = uploadform.sitename.data
@ -174,12 +179,43 @@ def upload():
zipfile = uploadform.zipfile.data
zipfile.save(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
newuserfolder = os.path.join("stash", user.distribusiname)
if not os.path.exists(newuserfolder):
os.mkdir(newuserfolder)
copyzipfile = os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)
shutil.copy(copyzipfile, newuserfolder)
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
success = True
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
success=success,
themeform=themeform,
)
return template
@APP.route("/theme", methods=["POST"])
@login_required
def theme():
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
if themeform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first()
newuserfolder = os.path.join("stash", user.distribusiname)
copycssfile = os.path.join(
"themes",
"{}.css".format(themeform.theme.data),
)
shutil.copy(copycssfile, newuserfolder)
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
)
return template

15
verse/templates/distribusi.html

@ -31,8 +31,19 @@
</div>
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
<div id="theme" class="workflow">
<h3>Step 2: Theme</h3>
<p>dropdown css file selector</p>
<h3>(Optional) Step 2: Theme</h3>
<p>Select your Theme here. If you want your own custom css, skip and go to
step 3. Don't forget to press Save</p>
<form method="POST" enctype="multipart/form-data" action="{{ url_for('theme') }}">
{{ themeform.csrf_token }}
<fieldset class="required">
{{ themeform.theme.label }}
{{ themeform.theme }}
</fieldset>
<fieldset class="button required">
{{ themeform.save }}
</fieldset>
</form>
</div>
<img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" />
<div id="edit" class="workflow">

6
verse/themes/hacking.css

@ -0,0 +1,6 @@
body {
font-family: courier monospace;
background-color: black;
color: rgb(0, 255, 0);
border: 3px solid rgb(0, 255, 0);
}

4
verse/themes/peachsunset.css

@ -0,0 +1,4 @@
body {
background:linear-gradient(to top, #040308, #AD4A28, #DD723C, #FC7001, #DCB697, #9BA5AE, #3E5879, #020B1A);
color: white;
}

8
verse/themes/wdka.css

@ -0,0 +1,8 @@
body {
color: black;
font-family: Arial;
font-style: italic;
font-weight: 900;
letter-spacing: 0;
background-color: #FFD300;
}
Loading…
Cancel
Save