Refactoring pass one, sub templates and the start of a user helper class

This commit is contained in:
crunk 2022-01-23 14:36:23 +01:00
parent b4b9b7ed58
commit 83b4816ccc
8 changed files with 98 additions and 68 deletions

View File

@ -44,6 +44,7 @@ from forms.distribusiform import DistribusiForm
from forms.themeform import ThemeForm
from forms.editorform import EditorForm
from statuspengguna.helper import AreFilesUploaded
# Tada!
from distribusi.cli import build_argparser
from distribusi.distribusi import distribusify
@ -134,9 +135,8 @@ def distribusi():
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
files_uploaded = AreFilesUploaded()
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)
userfolder = os.path.join("stash", user.distribusiname)
@ -163,6 +163,7 @@ def distribusi():
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
files_uploaded=files_uploaded,
)
return template
@ -170,10 +171,10 @@ def distribusi():
@APP.route("/upload", methods=["POST"])
@login_required
def upload():
success = False
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
files_uploaded = False
if uploadform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first()
user.distribusiname = uploadform.sitename.data
@ -189,13 +190,13 @@ def upload():
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
files_uploaded = AreFilesUploaded()
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
success=success,
themeform=themeform,
files_uploaded=files_uploaded,
)
return template
@ -206,6 +207,7 @@ def theme():
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
files_uploaded = AreFilesUploaded()
if themeform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first()
newuserfolder = os.path.join("stash", user.distribusiname)
@ -220,6 +222,7 @@ def theme():
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
files_uploaded=files_uploaded,
)
return template
@ -228,11 +231,8 @@ def theme():
@login_required
def editor():
editorform = EditorForm()
files_uploaded = AreFilesUploaded()
user = User.query.filter_by(email=current_user.email).first()
files_uploaded = True
if user.distribusiname is None:
files_uploaded = False
print("no folder to add css to!")
if editorform.validate_on_submit():
userfolder = os.path.join("stash", user.distribusiname)
cssfilename = "{}.css".format(editorform.cssname.data)

View File

@ -0,0 +1,17 @@
import os
from flask_login import current_user
from usermodel import User
def AreFilesUploaded():
user = User.query.filter_by(email=current_user.email).first()
if user.distribusiname is None:
print("distribusi name is empty")
return False;
userfolder = os.path.join("stash", user.distribusiname)
if os.path.exists(userfolder):
print("folder found, files are uploaded")
return True;
#def IsThemeSelected
#def IsCustomThemePresent
#def IsDistribusiLive

View File

@ -15,6 +15,8 @@
<body>
{% block main %}
{% endblock main %}
{% block body %}
{% endblock body %}
</body>
<script src="{{ url_for('static', filename='js/script.js')}}"></script>
</html>

View File

@ -1,66 +1,20 @@
{% extends "base.html" %}
{% block main %}
<div id="mainworkflow">
<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">
{{ uploadform.sitename.label }}
{{ uploadform.sitename }}
{% for message in uploadform.sitename.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="required">
{{ uploadform.zipfile.label }}
{{ uploadform.zipfile }}
{% for message in uploadform.zipfile.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="button required">
{{ uploadform.submit }}
</fieldset>
</form>
{% if success %}
<p>Your file has been uploaded successfully</h2>
{% endif %}
</div>
{% block upload %}
{% include "distribusiworkflow/upload.html" %}
{% endblock upload%}
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
<div id="theme" class="workflow">
<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>
{% block theme %}
{% include "distribusiworkflow/theme.html" %}
{% endblock theme%}
<img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" />
<div id="edit" class="workflow">
<h3>(Optional) Step 3: Edit</h3>
<a href="/editor"><p>Go to CSS editor</p></a>
</div>
{% block editcss %}
{% include "distribusiworkflow/editcss.html" %}
{% endblock editcss%}
<img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" />
<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>
{% block launch %}
{% include "distribusiworkflow/launch.html" %}
{% endblock launch%}
</div>
{% endblock main %}

View File

@ -0,0 +1,4 @@
<div id="edit" class="workflow">
<h3>(Optional) Step 3: Edit</h3>
<a href="/editor"><p>Go to CSS editor</p></a>
</div>

View File

@ -0,0 +1,11 @@
<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>

View File

@ -0,0 +1,15 @@
<div id="theme" class="workflow">
<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>

View File

@ -0,0 +1,27 @@
<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">
{{ uploadform.sitename.label }}
{{ uploadform.sitename }}
{% for message in uploadform.sitename.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="required">
{{ uploadform.zipfile.label }}
{{ uploadform.zipfile }}
{% for message in uploadform.zipfile.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="button required">
{{ uploadform.submit }}
</fieldset>
</form>
{% if files_uploaded %}
<p>Your files have been uploaded successfully</p>
{% endif %}
</div>