Browse Source

fixes to selector, getting closer to alpha :)

current_wdka_release
crunk 3 years ago
parent
commit
ed9e9af4ac
  1. 61
      verse/selector.py
  2. 59
      verse/start.py
  3. 15
      verse/statuspengguna/helper.py
  4. 39
      verse/templates/distribusi.html
  5. 2
      verse/templates/distribusiworkflow/selector.html

61
verse/selector.py

@ -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

59
verse/start.py

@ -36,8 +36,15 @@ from forms.themeform import ThemeForm
from forms.editorform import EditorForm from forms.editorform import EditorForm
from forms.selectorform import SelectorForm 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 AreFilesUploaded
from statuspengguna.helper import HasDistribusi from statuspengguna.helper import CurrentDistribusi
from statuspengguna.loginuser import LoginUser from statuspengguna.loginuser import LoginUser
from statuspengguna.registeruser import RegisterUser from statuspengguna.registeruser import RegisterUser
@ -76,10 +83,14 @@ def distribusi():
selectorform.distribusis.choices = distribusisfields() selectorform.distribusis.choices = distribusisfields()
files_uploaded = AreFilesUploaded() files_uploaded = AreFilesUploaded()
has_distribusi = HasDistribusi() selectorvisible = SelectorVisible()
current_distribusi = CurrentDistribusi()
user = User.query.filter_by(email=current_user.email).first() 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(): if distribusiform.validate_on_submit():
zipfilename = "{}.zip".format(distribusi.distribusiname) zipfilename = "{}.zip".format(distribusi.distribusiname)
userfolder = os.path.join("stash", distribusi.distribusiname) userfolder = os.path.join("stash", distribusi.distribusiname)
@ -101,6 +112,7 @@ def distribusi():
args = parser.parse_args(["-s", cssfile]) args = parser.parse_args(["-s", cssfile])
distribusify(args, userfolder) distribusify(args, userfolder)
distribusi.visible = True distribusi.visible = True
user.currentdistribusi = None
db.session.commit() db.session.commit()
return redirect(url_for("index")) return redirect(url_for("index"))
template = render_template( template = render_template(
@ -110,7 +122,7 @@ def distribusi():
themeform=themeform, themeform=themeform,
selectorform=selectorform, selectorform=selectorform,
files_uploaded=files_uploaded, files_uploaded=files_uploaded,
has_distribusi=has_distribusi, selectorvisible=selectorvisible,
) )
return template return template
@ -125,7 +137,7 @@ def upload():
selectorform.distribusis.choices = distribusisfields() selectorform.distribusis.choices = distribusisfields()
files_uploaded = AreFilesUploaded() files_uploaded = AreFilesUploaded()
has_distribusi = HasDistribusi() selectorvisible = SelectorVisible()
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()
@ -139,6 +151,7 @@ def upload():
year=uploadform.academicyear.data, year=uploadform.academicyear.data,
tags=uploadform.tags.data, tags=uploadform.tags.data,
) )
user.currentdistribusi = uploadform.sitename.data
db.session.add(newdistribusi) db.session.add(newdistribusi)
db.session.commit() db.session.commit()
except InvalidRequestError: except InvalidRequestError:
@ -171,7 +184,7 @@ def upload():
themeform=themeform, themeform=themeform,
selectorform=selectorform, selectorform=selectorform,
files_uploaded=files_uploaded, files_uploaded=files_uploaded,
has_distribusi=has_distribusi, selectorvisible=selectorvisible,
) )
return template return template
@ -186,12 +199,11 @@ def theme():
selectorform.distribusis.choices = distribusisfields() selectorform.distribusis.choices = distribusisfields()
files_uploaded = AreFilesUploaded() files_uploaded = AreFilesUploaded()
has_distribusi = HasDistribusi() selectorvisible = SelectorVisible()
current_distribusi = CurrentDistribusi()
if themeform.validate_on_submit(): if themeform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first() newuserfolder = os.path.join("stash", current_distribusi)
distribusi = Distribusis.query.filter_by(userid=user.id).first()
newuserfolder = os.path.join("stash", distribusi.distribusiname)
copycssfile = os.path.join( copycssfile = os.path.join(
"themes", "themes",
"{}.css".format(themeform.theme.data), "{}.css".format(themeform.theme.data),
@ -205,7 +217,7 @@ def theme():
themeform=themeform, themeform=themeform,
selectorform=selectorform, selectorform=selectorform,
files_uploaded=files_uploaded, files_uploaded=files_uploaded,
has_distribusi=has_distribusi, selectorvisible=selectorvisible,
) )
return template return template
@ -215,9 +227,10 @@ def theme():
def editor(): def editor():
editorform = EditorForm() editorform = EditorForm()
files_uploaded = AreFilesUploaded() files_uploaded = AreFilesUploaded()
user = User.query.filter_by(email=current_user.email).first() current_distribusi = CurrentDistribusi()
if editorform.validate_on_submit(): 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) cssfilename = "{}.css".format(editorform.cssname.data)
with open(os.path.join(userfolder, cssfilename), "w") as cssfile: with open(os.path.join(userfolder, cssfilename), "w") as cssfile:
cssfile.write(editorform.css.data) cssfile.write(editorform.css.data)
@ -234,12 +247,23 @@ def editor():
@APP.route("/selector", methods=["GET", "POST"]) @APP.route("/selector", methods=["GET", "POST"])
@login_required @login_required
def selector(): def selector():
selectorform = SelectorForm()
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
selectorform = SelectorForm() selectorform = SelectorForm()
selectorform.distribusis.choices = distribusisfields() selectorform.distribusis.choices = distribusisfields()
user = User.query.filter_by(email=current_user.email).first()
files_uploaded = AreFilesUploaded()
selectorvisible = SelectorVisible()
if selectorform.validate_on_submit(): if selectorform.validate_on_submit():
print(selectorform.distribusis.data) if selectorform.new.data:
print() SelectNewDistribusi()
if selectorform.delete.data:
DeleteDistribusi(selectorform.distribusis.data)
if selectorform.update.data:
SelectUpdateDistribusi(selectorform.distribusis.data)
template = render_template( template = render_template(
"distribusi.html", "distribusi.html",
uploadform=uploadform, uploadform=uploadform,
@ -247,10 +271,11 @@ def selector():
themeform=themeform, themeform=themeform,
selectorform=selectorform, selectorform=selectorform,
files_uploaded=files_uploaded, files_uploaded=files_uploaded,
has_distribusi=has_distribusi, selectorvisible=selectorvisible,
) )
return template return template
@APP.route("/stash/<path:path>") @APP.route("/stash/<path:path>")
def distribusistash(path): def distribusistash(path):
return send_from_directory("stash", path) return send_from_directory("stash", path)

15
verse/statuspengguna/helper.py

@ -28,6 +28,21 @@ def HasDistribusi():
return True 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 IsThemeSelected
# def IsCustomThemePresent # def IsCustomThemePresent
# def IsDistribusiLive # def IsDistribusiLive

39
verse/templates/distribusi.html

@ -13,25 +13,26 @@
</div> </div>
</div> </div>
<div id="mainworkflow"> <div id="mainworkflow">
{% if has_distribusi %} {% if selectorvisible %}
{% block selector %} {% block selector %}
{% include "distribusiworkflow/selector.html" %} {% include "distribusiworkflow/selector.html" %}
{% endblock selector%} {% 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%} {%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> </div>
{% endblock main %} {% endblock main %}

2
verse/templates/distribusiworkflow/selector.html

@ -1,7 +1,7 @@
<div id="distribusi" class="workflow"> <div id="distribusi" class="workflow">
<h3>Welcome back to your Distribusi</h3> <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> <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 }} {{ selectorform.csrf_token }}
<fieldset class="required"> <fieldset class="required">
{{ selectorform.distribusis.label }} {{ selectorform.distribusis.label }}

Loading…
Cancel
Save