Browse Source

refactoring selector page view

current_wdka_release
crunk 3 years ago
parent
commit
123e78d3c4
  1. 93
      verse/distribusiselector.py
  2. 68
      verse/start.py
  3. 11
      verse/static/css/style.css
  4. 2
      verse/templates/distribusi.html

93
verse/distribusiselector.py

@ -1,6 +1,6 @@
import os import os
import shutil import shutil
from flask import flash from flask import flash, render_template
from flask_login import current_user from flask_login import current_user
from sqlalchemy.exc import ( from sqlalchemy.exc import (
DataError, DataError,
@ -11,25 +11,70 @@ from sqlalchemy.exc import (
from usermodel import User from usermodel import User
from distribusimodel import Distribusis from distribusimodel import Distribusis
from distribusisinfo import DistribusisInfo
from forms.selectorform import SelectorForm from forms.selectorform import SelectorForm
from statuspengguna.helper import HasDistribusi from forms.uploadform import UploadForm
from forms.distribusiform import DistribusiForm
from forms.themeform import ThemeForm
from forms.publicthemeform import PublicThemeForm
# UserPengguna
from statuspengguna.helper import (
IsZipUploaded,
CurrentDistribusi,
HasDistribusi,
IsDistribusiLive,
DistribusiLimitReached,
)
from app import db from app import db
def SelectorPage():
uploadform = UploadForm()
selectorform = SelectorForm()
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames()
current_distribusi = CurrentDistribusi()
if selectorform.validate_on_submit():
if selectorform.new.data:
SelectNewDistribusi()
if selectorform.delete.data:
selectorform = DeleteDistribusi(selectorform.distribusis.data)
selectorform.distribusis.choices = (
DistribusisInfo.userdistribusinames()
)
if selectorform.update.data:
SelectUpdateDistribusi(selectorform.distribusis.data)
current_distribusi = CurrentDistribusi()
uploadform = AutoFillInUploadForm(uploadform, current_distribusi)
return RenderDistribusiTemplate(
selectorform, uploadform, current_distribusi
)
def AutoFillInUploadForm(uploadform, current_distribusi):
distribusi = Distribusis.query.filter_by(
distribusiname=current_distribusi
).first()
uploadform.sitename.data = distribusi.distribusiname
uploadform.sitename.render_kw = {"readonly": True}
uploadform.term.data = distribusi.term
uploadform.course.data = distribusi.course
uploadform.academicyear.data = distribusi.year
uploadform.tags.data = distribusi.tags
return uploadform
def SelectNewDistribusi(): def SelectNewDistribusi():
print("make a new distribusi") print("make a new distribusi")
selectorform = SelectorForm()
SelectCurrentDistribusi("new") SelectCurrentDistribusi("new")
return selectorform
def SelectUpdateDistribusi(distribusiname): def SelectUpdateDistribusi(distribusiname):
print(f"Update this distribusi {distribusiname}") print(f"Update this distribusi {distribusiname}")
selectorform = SelectorForm()
SelectCurrentDistribusi(distribusiname) SelectCurrentDistribusi(distribusiname)
return selectorform
def DeleteDistribusi(distribusiname): def DeleteDistribusi(distribusiname):
@ -49,10 +94,11 @@ def DeleteDistribusi(distribusiname):
"themes/userthemes", distribusi.distribusiname "themes/userthemes", distribusi.distribusiname
) )
shutil.rmtree(cssfolder) shutil.rmtree(cssfolder)
selectorform.delete.errors.append("Distribusi deleted!") # SelectField error is list is a tuple?? why??
# selectorform.distribusis.errors.append("Distribusi deleted!")
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
db.session.rollback() db.session.rollback()
selectorform.delete.errors.append("Unknown error occured!") # selectorform.distribusis.errors.append("Unknown error occured!")
flash("An error occured !", "danger") flash("An error occured !", "danger")
return selectorform return selectorform
@ -84,3 +130,32 @@ def SelectorVisible():
if not has_distribusi: if not has_distribusi:
return False return False
return True return True
def RenderDistribusiTemplate(selectorform, uploadform, current_distribusi):
distribusiform = DistribusiForm()
themeform = ThemeForm()
publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
files_uploaded = IsZipUploaded(current_distribusi)
distribusi_live = IsDistribusiLive(current_distribusi)
# because the user has chosen to update his distribusi, we assume
# no selected css.
css_selected = False
selectorvisible = SelectorVisible()
limit_reached = DistribusiLimitReached()
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
publicthemeform=publicthemeform,
selectorform=selectorform,
files_uploaded=files_uploaded,
distribusi_live=distribusi_live,
css_selected=css_selected,
selectorvisible=selectorvisible,
limit_reached=limit_reached,
)
return template

68
verse/start.py

@ -18,7 +18,6 @@ from flask_wtf.csrf import CSRFError
from app import create_app, login_manager from app import create_app, login_manager
from usermodel import User from usermodel import User
from distribusimodel import Distribusis
# Forms! # Forms!
from forms.uploadform import UploadForm from forms.uploadform import UploadForm
@ -27,20 +26,13 @@ from forms.themeform import ThemeForm
from forms.publicthemeform import PublicThemeForm from forms.publicthemeform import PublicThemeForm
from forms.selectorform import SelectorForm from forms.selectorform import SelectorForm
# CRUD!
from distribusiselector import (
SelectNewDistribusi,
SelectUpdateDistribusi,
DeleteDistribusi,
SelectorVisible,
)
# Interface! # Interface!
from adminpage import AdminPage
from editor import Editor from editor import Editor
from themeselector import ThemeSelector from themeselector import ThemeSelector
from upload import UploadNewDistribusi, UploadUpdatedFiles
from adminpage import AdminPage
from distribusiworkflow import DistribusiWorkflow from distribusiworkflow import DistribusiWorkflow
from distribusiselector import SelectorPage, SelectorVisible
from upload import UploadNewDistribusi, UploadUpdatedFiles
# UserPengguna # UserPengguna
from statuspengguna.helper import ( from statuspengguna.helper import (
@ -153,59 +145,7 @@ def editor():
@APP.route("/selector", methods=["GET", "POST"]) @APP.route("/selector", methods=["GET", "POST"])
@login_required @login_required
def selector(): def selector():
selectorform = SelectorForm() return SelectorPage()
uploadform = UploadForm()
distribusiform = DistribusiForm()
themeform = ThemeForm()
publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
selectorform = SelectorForm()
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames()
current_distribusi = CurrentDistribusi()
if selectorform.validate_on_submit():
if selectorform.new.data:
selectorform = SelectNewDistribusi()
if selectorform.delete.data:
selectorform = DeleteDistribusi(selectorform.distribusis.data)
selectorform.distribusis.choices = (
DistribusisInfo.userdistribusinames()
)
if selectorform.update.data:
selectorform = SelectUpdateDistribusi(
selectorform.distribusis.data
)
current_distribusi = CurrentDistribusi()
distribusi = Distribusis.query.filter_by(
distribusiname=current_distribusi
).first()
uploadform.sitename.data = distribusi.distribusiname
uploadform.sitename.render_kw = {"readonly": True}
uploadform.term.data = distribusi.term
uploadform.course.data = distribusi.course
uploadform.academicyear.data = distribusi.year
uploadform.tags.data = distribusi.tags
files_uploaded = IsZipUploaded(current_distribusi)
distribusi_live = IsDistribusiLive(current_distribusi)
# because the user has chosen to update his distribusi, we assume
# no selected css.
css_selected = False
selectorvisible = SelectorVisible()
limit_reached = DistribusiLimitReached()
template = render_template(
"distribusi.html",
uploadform=uploadform,
distribusiform=distribusiform,
themeform=themeform,
publicthemeform=publicthemeform,
selectorform=selectorform,
files_uploaded=files_uploaded,
distribusi_live=distribusi_live,
css_selected=css_selected,
selectorvisible=selectorvisible,
limit_reached=limit_reached,
)
return template
@APP.route("/stash/<path:path>") @APP.route("/stash/<path:path>")

11
verse/static/css/style.css

@ -77,20 +77,16 @@ div#buttons{
align-items: center; align-items: center;
} }
div#buttons .logout input{
border: none;
background: #E0B0FF;
text-decoration: none;
margin: 1px;
}
div#buttons .distribusi input{ div#buttons .distribusi input{
border: none; border: none;
background: #fff600; background: #fff600;
text-decoration: none; text-decoration: none;
margin: 0.2em; margin: 0.2em;
} }
div#buttons .distribusi input:hover{
background: #ffbf00;
}
fieldset.required { fieldset.required {
border: none; border: none;
} }
@ -167,6 +163,7 @@ a:active {
#fancyboi::before { #fancyboi::before {
content: "$ "; content: "$ ";
} }
@media (prefers-reduced-motion: no-preference) { @media (prefers-reduced-motion: no-preference) {
@keyframes flash { @keyframes flash {
50% { opacity: 0; } 50% { opacity: 0; }

2
verse/templates/distribusi.html

@ -3,7 +3,7 @@
<div id="buttons"> <div id="buttons">
<div class="overview"> <div class="overview">
<a href="/"> <a href="/">
<input type="button" name="button" value="Overview"></input> <input type="button" name="button" value="Main page"></input>
</a> </a>
</div> </div>
<div class="logout"> <div class="logout">

Loading…
Cancel
Save