forked from crunk/distribusi-verse
fixes to selector, getting closer to alpha :)
This commit is contained in:
parent
6e4ae4b419
commit
ed9e9af4ac
61
verse/selector.py
Normal file
61
verse/selector.py
Normal file
@ -0,0 +1,61 @@
|
||||
from flask import (
|
||||
render_template,
|
||||
redirect,
|
||||
request,
|
||||
flash,
|
||||
url_for,
|
||||
abort,
|
||||
)
|
||||
|
||||
from usermodel import User
|
||||
from flask_login import current_user
|
||||
|
||||
from forms.loginform import LoginForm
|
||||
from forms.uploadform import UploadForm
|
||||
from forms.distribusiform import DistribusiForm
|
||||
from forms.themeform import ThemeForm
|
||||
from forms.editorform import EditorForm
|
||||
from forms.selectorform import SelectorForm
|
||||
|
||||
from statuspengguna.helper import HasDistribusi
|
||||
from statuspengguna.helper import DistribusiSelected
|
||||
|
||||
from app import db
|
||||
|
||||
|
||||
def SelectNewDistribusi():
|
||||
print("make a new distribusi")
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
try:
|
||||
user.currentdistribusi = "new"
|
||||
db.session.commit()
|
||||
except:
|
||||
db.session.rollback()
|
||||
selectorform.new.errors.append("Unknown error occured!")
|
||||
flash("An error occured !", "danger")
|
||||
|
||||
|
||||
def SelectUpdateDistribusi(distribusiname):
|
||||
print(f"Update this distribusi {distribusiname}")
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
try:
|
||||
user.currentdistribusi = distribusiname
|
||||
db.session.commit()
|
||||
except:
|
||||
db.session.rollback()
|
||||
selectorform.new.errors.append("Unknown error occured!")
|
||||
flash("An error occured !", "danger")
|
||||
|
||||
|
||||
def DeleteDistribusi(distribusiname):
|
||||
print(f"delete this distribusi {distribusiname}")
|
||||
|
||||
|
||||
def SelectorVisible():
|
||||
has_distribusi = HasDistribusi()
|
||||
distribusi_selected = DistribusiSelected()
|
||||
if distribusi_selected:
|
||||
return False
|
||||
if not has_distribusi:
|
||||
return False
|
||||
return True
|
@ -36,8 +36,15 @@ from forms.themeform import ThemeForm
|
||||
from forms.editorform import EditorForm
|
||||
from forms.selectorform import SelectorForm
|
||||
|
||||
# CRUD!
|
||||
from selector import SelectNewDistribusi
|
||||
from selector import SelectUpdateDistribusi
|
||||
from selector import DeleteDistribusi
|
||||
from selector import SelectorVisible
|
||||
|
||||
|
||||
from statuspengguna.helper import AreFilesUploaded
|
||||
from statuspengguna.helper import HasDistribusi
|
||||
from statuspengguna.helper import CurrentDistribusi
|
||||
from statuspengguna.loginuser import LoginUser
|
||||
from statuspengguna.registeruser import RegisterUser
|
||||
|
||||
@ -76,10 +83,14 @@ def distribusi():
|
||||
selectorform.distribusis.choices = distribusisfields()
|
||||
|
||||
files_uploaded = AreFilesUploaded()
|
||||
has_distribusi = HasDistribusi()
|
||||
selectorvisible = SelectorVisible()
|
||||
current_distribusi = CurrentDistribusi()
|
||||
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
distribusi = Distribusis.query.filter_by(userid=user.id).first()
|
||||
distribusi = Distribusis.query.filter_by(
|
||||
distribusiname=current_distribusi
|
||||
).first()
|
||||
|
||||
if distribusiform.validate_on_submit():
|
||||
zipfilename = "{}.zip".format(distribusi.distribusiname)
|
||||
userfolder = os.path.join("stash", distribusi.distribusiname)
|
||||
@ -101,6 +112,7 @@ def distribusi():
|
||||
args = parser.parse_args(["-s", cssfile])
|
||||
distribusify(args, userfolder)
|
||||
distribusi.visible = True
|
||||
user.currentdistribusi = None
|
||||
db.session.commit()
|
||||
return redirect(url_for("index"))
|
||||
template = render_template(
|
||||
@ -110,7 +122,7 @@ def distribusi():
|
||||
themeform=themeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
has_distribusi=has_distribusi,
|
||||
selectorvisible=selectorvisible,
|
||||
)
|
||||
return template
|
||||
|
||||
@ -125,7 +137,7 @@ def upload():
|
||||
selectorform.distribusis.choices = distribusisfields()
|
||||
|
||||
files_uploaded = AreFilesUploaded()
|
||||
has_distribusi = HasDistribusi()
|
||||
selectorvisible = SelectorVisible()
|
||||
|
||||
if uploadform.validate_on_submit():
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
@ -139,6 +151,7 @@ def upload():
|
||||
year=uploadform.academicyear.data,
|
||||
tags=uploadform.tags.data,
|
||||
)
|
||||
user.currentdistribusi = uploadform.sitename.data
|
||||
db.session.add(newdistribusi)
|
||||
db.session.commit()
|
||||
except InvalidRequestError:
|
||||
@ -171,7 +184,7 @@ def upload():
|
||||
themeform=themeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
has_distribusi=has_distribusi,
|
||||
selectorvisible=selectorvisible,
|
||||
)
|
||||
return template
|
||||
|
||||
@ -186,12 +199,11 @@ def theme():
|
||||
selectorform.distribusis.choices = distribusisfields()
|
||||
|
||||
files_uploaded = AreFilesUploaded()
|
||||
has_distribusi = HasDistribusi()
|
||||
selectorvisible = SelectorVisible()
|
||||
current_distribusi = CurrentDistribusi()
|
||||
|
||||
if themeform.validate_on_submit():
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
distribusi = Distribusis.query.filter_by(userid=user.id).first()
|
||||
newuserfolder = os.path.join("stash", distribusi.distribusiname)
|
||||
newuserfolder = os.path.join("stash", current_distribusi)
|
||||
copycssfile = os.path.join(
|
||||
"themes",
|
||||
"{}.css".format(themeform.theme.data),
|
||||
@ -205,7 +217,7 @@ def theme():
|
||||
themeform=themeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
has_distribusi=has_distribusi,
|
||||
selectorvisible=selectorvisible,
|
||||
)
|
||||
return template
|
||||
|
||||
@ -215,9 +227,10 @@ def theme():
|
||||
def editor():
|
||||
editorform = EditorForm()
|
||||
files_uploaded = AreFilesUploaded()
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
current_distribusi = CurrentDistribusi()
|
||||
|
||||
if editorform.validate_on_submit():
|
||||
userfolder = os.path.join("stash", user.distribusiname)
|
||||
userfolder = os.path.join("stash", current_distribusi)
|
||||
cssfilename = "{}.css".format(editorform.cssname.data)
|
||||
with open(os.path.join(userfolder, cssfilename), "w") as cssfile:
|
||||
cssfile.write(editorform.css.data)
|
||||
@ -234,12 +247,23 @@ def editor():
|
||||
@APP.route("/selector", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def selector():
|
||||
selectorform = SelectorForm()
|
||||
uploadform = UploadForm()
|
||||
distribusiform = DistribusiForm()
|
||||
themeform = ThemeForm()
|
||||
selectorform = SelectorForm()
|
||||
selectorform.distribusis.choices = distribusisfields()
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
|
||||
files_uploaded = AreFilesUploaded()
|
||||
selectorvisible = SelectorVisible()
|
||||
|
||||
if selectorform.validate_on_submit():
|
||||
print(selectorform.distribusis.data)
|
||||
print()
|
||||
if selectorform.new.data:
|
||||
SelectNewDistribusi()
|
||||
if selectorform.delete.data:
|
||||
DeleteDistribusi(selectorform.distribusis.data)
|
||||
if selectorform.update.data:
|
||||
SelectUpdateDistribusi(selectorform.distribusis.data)
|
||||
template = render_template(
|
||||
"distribusi.html",
|
||||
uploadform=uploadform,
|
||||
@ -247,10 +271,11 @@ def selector():
|
||||
themeform=themeform,
|
||||
selectorform=selectorform,
|
||||
files_uploaded=files_uploaded,
|
||||
has_distribusi=has_distribusi,
|
||||
selectorvisible=selectorvisible,
|
||||
)
|
||||
return template
|
||||
|
||||
|
||||
@APP.route("/stash/<path:path>")
|
||||
def distribusistash(path):
|
||||
return send_from_directory("stash", path)
|
||||
|
@ -28,6 +28,21 @@ def HasDistribusi():
|
||||
return True
|
||||
|
||||
|
||||
def CurrentDistribusi():
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
if user.currentdistribusi is None:
|
||||
return "None"
|
||||
if user.currentdistribusi is "new":
|
||||
return "new"
|
||||
return user.currentdistribusi
|
||||
|
||||
|
||||
def DistribusiSelected():
|
||||
user = User.query.filter_by(email=current_user.email).first()
|
||||
if user.currentdistribusi is None:
|
||||
return False
|
||||
return True
|
||||
|
||||
# def IsThemeSelected
|
||||
# def IsCustomThemePresent
|
||||
# def IsDistribusiLive
|
||||
|
@ -13,25 +13,26 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="mainworkflow">
|
||||
{% if has_distribusi %}
|
||||
{% block selector %}
|
||||
{% include "distribusiworkflow/selector.html" %}
|
||||
{% endblock selector%}
|
||||
{% if selectorvisible %}
|
||||
{% block selector %}
|
||||
{% include "distribusiworkflow/selector.html" %}
|
||||
{% endblock selector%}
|
||||
{% else %}
|
||||
{% block upload %}
|
||||
{% include "distribusiworkflow/upload.html" %}
|
||||
{% endblock upload%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
|
||||
{% block theme %}
|
||||
{% include "distribusiworkflow/theme.html" %}
|
||||
{% endblock theme%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" />
|
||||
{% block editcss %}
|
||||
{% include "distribusiworkflow/editcss.html" %}
|
||||
{% endblock editcss%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" />
|
||||
{% block launch %}
|
||||
{% include "distribusiworkflow/launch.html" %}
|
||||
{% endblock launch%}
|
||||
{%endif%}
|
||||
{% block upload %}
|
||||
{% include "distribusiworkflow/upload.html" %}
|
||||
{% endblock upload%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
|
||||
{% block theme %}
|
||||
{% include "distribusiworkflow/theme.html" %}
|
||||
{% endblock theme%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" />
|
||||
{% block editcss %}
|
||||
{% include "distribusiworkflow/editcss.html" %}
|
||||
{% endblock editcss%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" />
|
||||
{% block launch %}
|
||||
{% include "distribusiworkflow/launch.html" %}
|
||||
{% endblock launch%}
|
||||
</div>
|
||||
{% endblock main %}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<div id="distribusi" class="workflow">
|
||||
<h3>Welcome back to your Distribusi</h3>
|
||||
<p>You have already uploaded a distribusi website, do you want to make a new one, update or delete?</p>
|
||||
<form method="POST" enctype="multipart/form-data" action="{{ url_for('distribusi') }}">
|
||||
<form method="POST" enctype="multipart/form-data" action="{{ url_for('selector') }}">
|
||||
{{ selectorform.csrf_token }}
|
||||
<fieldset class="required">
|
||||
{{ selectorform.distribusis.label }}
|
||||
|
Loading…
Reference in New Issue
Block a user