Refactoring pass one, sub templates and the start of a user helper class
This commit is contained in:
parent
b4b9b7ed58
commit
83b4816ccc
@ -44,6 +44,7 @@ from forms.distribusiform import DistribusiForm
|
|||||||
from forms.themeform import ThemeForm
|
from forms.themeform import ThemeForm
|
||||||
from forms.editorform import EditorForm
|
from forms.editorform import EditorForm
|
||||||
|
|
||||||
|
from statuspengguna.helper import AreFilesUploaded
|
||||||
# Tada!
|
# Tada!
|
||||||
from distribusi.cli import build_argparser
|
from distribusi.cli import build_argparser
|
||||||
from distribusi.distribusi import distribusify
|
from distribusi.distribusi import distribusify
|
||||||
@ -134,9 +135,8 @@ def distribusi():
|
|||||||
uploadform = UploadForm()
|
uploadform = UploadForm()
|
||||||
distribusiform = DistribusiForm()
|
distribusiform = DistribusiForm()
|
||||||
themeform = ThemeForm()
|
themeform = ThemeForm()
|
||||||
|
files_uploaded = AreFilesUploaded()
|
||||||
user = User.query.filter_by(email=current_user.email).first()
|
user = User.query.filter_by(email=current_user.email).first()
|
||||||
if user.distribusiname is None:
|
|
||||||
print("nothing to deploy!")
|
|
||||||
if distribusiform.validate_on_submit():
|
if distribusiform.validate_on_submit():
|
||||||
zipfilename = "{}.zip".format(user.distribusiname)
|
zipfilename = "{}.zip".format(user.distribusiname)
|
||||||
userfolder = os.path.join("stash", user.distribusiname)
|
userfolder = os.path.join("stash", user.distribusiname)
|
||||||
@ -163,6 +163,7 @@ def distribusi():
|
|||||||
uploadform=uploadform,
|
uploadform=uploadform,
|
||||||
distribusiform=distribusiform,
|
distribusiform=distribusiform,
|
||||||
themeform=themeform,
|
themeform=themeform,
|
||||||
|
files_uploaded=files_uploaded,
|
||||||
)
|
)
|
||||||
return template
|
return template
|
||||||
|
|
||||||
@ -170,10 +171,10 @@ def distribusi():
|
|||||||
@APP.route("/upload", methods=["POST"])
|
@APP.route("/upload", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def upload():
|
def upload():
|
||||||
success = False
|
|
||||||
uploadform = UploadForm()
|
uploadform = UploadForm()
|
||||||
distribusiform = DistribusiForm()
|
distribusiform = DistribusiForm()
|
||||||
themeform = ThemeForm()
|
themeform = ThemeForm()
|
||||||
|
files_uploaded = False
|
||||||
if uploadform.validate_on_submit():
|
if uploadform.validate_on_submit():
|
||||||
user = User.query.filter_by(email=current_user.email).first()
|
user = User.query.filter_by(email=current_user.email).first()
|
||||||
user.distribusiname = uploadform.sitename.data
|
user.distribusiname = uploadform.sitename.data
|
||||||
@ -189,13 +190,13 @@ def upload():
|
|||||||
copyzipfile = os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)
|
copyzipfile = os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename)
|
||||||
shutil.copy(copyzipfile, newuserfolder)
|
shutil.copy(copyzipfile, newuserfolder)
|
||||||
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
|
os.remove(os.path.join(APP.config["UPLOAD_FOLDER"], zipfilename))
|
||||||
success = True
|
files_uploaded = AreFilesUploaded()
|
||||||
template = render_template(
|
template = render_template(
|
||||||
"distribusi.html",
|
"distribusi.html",
|
||||||
uploadform=uploadform,
|
uploadform=uploadform,
|
||||||
distribusiform=distribusiform,
|
distribusiform=distribusiform,
|
||||||
success=success,
|
|
||||||
themeform=themeform,
|
themeform=themeform,
|
||||||
|
files_uploaded=files_uploaded,
|
||||||
)
|
)
|
||||||
return template
|
return template
|
||||||
|
|
||||||
@ -206,6 +207,7 @@ def theme():
|
|||||||
uploadform = UploadForm()
|
uploadform = UploadForm()
|
||||||
distribusiform = DistribusiForm()
|
distribusiform = DistribusiForm()
|
||||||
themeform = ThemeForm()
|
themeform = ThemeForm()
|
||||||
|
files_uploaded = AreFilesUploaded()
|
||||||
if themeform.validate_on_submit():
|
if themeform.validate_on_submit():
|
||||||
user = User.query.filter_by(email=current_user.email).first()
|
user = User.query.filter_by(email=current_user.email).first()
|
||||||
newuserfolder = os.path.join("stash", user.distribusiname)
|
newuserfolder = os.path.join("stash", user.distribusiname)
|
||||||
@ -220,6 +222,7 @@ def theme():
|
|||||||
uploadform=uploadform,
|
uploadform=uploadform,
|
||||||
distribusiform=distribusiform,
|
distribusiform=distribusiform,
|
||||||
themeform=themeform,
|
themeform=themeform,
|
||||||
|
files_uploaded=files_uploaded,
|
||||||
)
|
)
|
||||||
return template
|
return template
|
||||||
|
|
||||||
@ -228,11 +231,8 @@ def theme():
|
|||||||
@login_required
|
@login_required
|
||||||
def editor():
|
def editor():
|
||||||
editorform = EditorForm()
|
editorform = EditorForm()
|
||||||
|
files_uploaded = AreFilesUploaded()
|
||||||
user = User.query.filter_by(email=current_user.email).first()
|
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():
|
if editorform.validate_on_submit():
|
||||||
userfolder = os.path.join("stash", user.distribusiname)
|
userfolder = os.path.join("stash", user.distribusiname)
|
||||||
cssfilename = "{}.css".format(editorform.cssname.data)
|
cssfilename = "{}.css".format(editorform.cssname.data)
|
||||||
|
17
verse/statuspengguna/helper.py
Normal file
17
verse/statuspengguna/helper.py
Normal 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
|
@ -15,6 +15,8 @@
|
|||||||
<body>
|
<body>
|
||||||
{% block main %}
|
{% block main %}
|
||||||
{% endblock main %}
|
{% endblock main %}
|
||||||
|
{% block body %}
|
||||||
|
{% endblock body %}
|
||||||
</body>
|
</body>
|
||||||
<script src="{{ url_for('static', filename='js/script.js')}}"></script>
|
<script src="{{ url_for('static', filename='js/script.js')}}"></script>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,66 +1,20 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<div id="mainworkflow">
|
<div id="mainworkflow">
|
||||||
|
{% block upload %}
|
||||||
<div id="upload" class="workflow">
|
{% include "distribusiworkflow/upload.html" %}
|
||||||
<h3>Step 1: Upload</h3>
|
{% endblock upload%}
|
||||||
<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>
|
|
||||||
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
|
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
|
||||||
<div id="theme" class="workflow">
|
{% block theme %}
|
||||||
<h3>(Optional) Step 2: Theme</h3>
|
{% include "distribusiworkflow/theme.html" %}
|
||||||
<p>Select your Theme here. If you want your own custom css, skip and go to
|
{% endblock theme%}
|
||||||
step 3. Don't forget to press Save</p>
|
<img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" />
|
||||||
<form method="POST" enctype="multipart/form-data" action="{{ url_for('theme') }}">
|
{% block editcss %}
|
||||||
{{ themeform.csrf_token }}
|
{% include "distribusiworkflow/editcss.html" %}
|
||||||
<fieldset class="required">
|
{% endblock editcss%}
|
||||||
{{ 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">
|
|
||||||
<h3>(Optional) Step 3: Edit</h3>
|
|
||||||
<a href="/editor"><p>Go to CSS editor</p></a>
|
|
||||||
</div>
|
|
||||||
<img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" />
|
<img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" />
|
||||||
<div id="distribusi" class="workflow">
|
{% block launch %}
|
||||||
<h3>Step 4: Distribusi</h3>
|
{% include "distribusiworkflow/launch.html" %}
|
||||||
<p>run distribusi on your files, this will generate your website and make
|
{% endblock launch%}
|
||||||
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>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock main %}
|
{% endblock main %}
|
||||||
|
4
verse/templates/distribusiworkflow/editcss.html
Normal file
4
verse/templates/distribusiworkflow/editcss.html
Normal 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>
|
11
verse/templates/distribusiworkflow/launch.html
Normal file
11
verse/templates/distribusiworkflow/launch.html
Normal 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>
|
15
verse/templates/distribusiworkflow/theme.html
Normal file
15
verse/templates/distribusiworkflow/theme.html
Normal 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>
|
27
verse/templates/distribusiworkflow/upload.html
Normal file
27
verse/templates/distribusiworkflow/upload.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user