refactoring distribusi work flow page, upload section
This commit is contained in:
parent
123e78d3c4
commit
80f08d4bf9
@ -31,7 +31,7 @@ from statuspengguna.helper import (
|
|||||||
from app import db
|
from app import db
|
||||||
|
|
||||||
|
|
||||||
def SelectorPage():
|
def DistribusiSelector():
|
||||||
uploadform = UploadForm()
|
uploadform = UploadForm()
|
||||||
selectorform = SelectorForm()
|
selectorform = SelectorForm()
|
||||||
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames()
|
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames()
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
"""This is the main flask distribusi page"""
|
"""This is the main flask distribusi page"""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from flask import (
|
from flask import (
|
||||||
render_template,
|
render_template,
|
||||||
redirect,
|
redirect,
|
||||||
@ -13,37 +12,23 @@ from flask_login import (
|
|||||||
login_required,
|
login_required,
|
||||||
current_user,
|
current_user,
|
||||||
)
|
)
|
||||||
|
|
||||||
from flask_wtf.csrf import CSRFError
|
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
|
||||||
|
|
||||||
# Forms!
|
# Use upload form to populate filters
|
||||||
from forms.uploadform import UploadForm
|
from forms.uploadform import UploadForm
|
||||||
from forms.distribusiform import DistribusiForm
|
|
||||||
from forms.themeform import ThemeForm
|
|
||||||
from forms.publicthemeform import PublicThemeForm
|
|
||||||
from forms.selectorform import SelectorForm
|
|
||||||
|
|
||||||
# Interface!
|
# Interface! these are seperate files in main folder
|
||||||
from adminpage import AdminPage
|
from adminpage import AdminPage
|
||||||
from editor import Editor
|
from editor import Editor
|
||||||
from themeselector import ThemeSelector
|
from themeselector import ThemeSelector
|
||||||
from distribusiworkflow import DistribusiWorkflow
|
from distribusiworkflow import DistribusiWorkflow
|
||||||
from distribusiselector import SelectorPage, SelectorVisible
|
from distribusiselector import DistribusiSelector
|
||||||
from upload import UploadNewDistribusi, UploadUpdatedFiles
|
from uploadpage import UploadPage
|
||||||
|
|
||||||
# UserPengguna
|
# UserPengguna
|
||||||
from statuspengguna.helper import (
|
from statuspengguna.helper import ResetUserState
|
||||||
IsZipUploaded,
|
|
||||||
IsCssSelected,
|
|
||||||
CurrentDistribusi,
|
|
||||||
HasDistribusi,
|
|
||||||
IsDistribusiLive,
|
|
||||||
ResetUserState,
|
|
||||||
DistribusiLimitReached,
|
|
||||||
)
|
|
||||||
from statuspengguna.loginuser import LoginUser
|
from statuspengguna.loginuser import LoginUser
|
||||||
from statuspengguna.registeruser import RegisterUser
|
from statuspengguna.registeruser import RegisterUser
|
||||||
from distribusisinfo import DistribusisInfo
|
from distribusisinfo import DistribusisInfo
|
||||||
@ -98,36 +83,8 @@ def distribusi():
|
|||||||
@APP.route("/upload", methods=["POST"])
|
@APP.route("/upload", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def upload():
|
def upload():
|
||||||
distribusiform = DistribusiForm()
|
uploadfolder = APP.config["UPLOAD_FOLDER"]
|
||||||
themeform = ThemeForm()
|
return UploadPage(uploadfolder)
|
||||||
publicthemeform = PublicThemeForm()
|
|
||||||
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
|
||||||
selectorform = SelectorForm()
|
|
||||||
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames()
|
|
||||||
selectorvisible = SelectorVisible()
|
|
||||||
current_distribusi = CurrentDistribusi()
|
|
||||||
if current_distribusi == "new" or HasDistribusi() is False:
|
|
||||||
uploadform = UploadNewDistribusi(APP.config["UPLOAD_FOLDER"])
|
|
||||||
else:
|
|
||||||
uploadform = UploadUpdatedFiles(APP.config["UPLOAD_FOLDER"])
|
|
||||||
files_uploaded = IsZipUploaded(uploadform.sitename.data)
|
|
||||||
distribusi_live = IsDistribusiLive(current_distribusi)
|
|
||||||
css_selected = IsCssSelected(current_distribusi)
|
|
||||||
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("/theme", methods=["GET", "POST"])
|
@APP.route("/theme", methods=["GET", "POST"])
|
||||||
@ -145,7 +102,7 @@ def editor():
|
|||||||
@APP.route("/selector", methods=["GET", "POST"])
|
@APP.route("/selector", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def selector():
|
def selector():
|
||||||
return SelectorPage()
|
return DistribusiSelector()
|
||||||
|
|
||||||
|
|
||||||
@APP.route("/stash/<path:path>")
|
@APP.route("/stash/<path:path>")
|
||||||
|
@ -120,7 +120,8 @@ input[type="submit"]:disabled:focus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
.error {
|
||||||
color: #aa5050;
|
font-size: 110%;
|
||||||
|
color: #F92020;
|
||||||
}
|
}
|
||||||
|
|
||||||
#delete {
|
#delete {
|
||||||
|
@ -35,16 +35,18 @@ def UploadNewDistribusi(uploadfolder):
|
|||||||
user.currentdistribusi = uploadform.sitename.data
|
user.currentdistribusi = uploadform.sitename.data
|
||||||
db.session.add(newdistribusi)
|
db.session.add(newdistribusi)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
|
|
||||||
db.session.rollback()
|
|
||||||
uploadform.sitename.errors.append("Something went wrong!")
|
|
||||||
flash("Something went wrong!", "danger")
|
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
uploadform.sitename.errors.append(
|
uploadform.sitename.errors.append(
|
||||||
"distribusi name already exists!"
|
"distribusi name already exists!"
|
||||||
)
|
)
|
||||||
flash("distribusi name already exists!", "warning")
|
flash("distribusi name already exists!", "warning")
|
||||||
|
return uploadform
|
||||||
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
|
||||||
|
db.session.rollback()
|
||||||
|
uploadform.sitename.errors.append("Something went wrong!")
|
||||||
|
flash("Something went wrong!", "danger")
|
||||||
|
return uploadform
|
||||||
SelectCurrentDistribusi(newdistribusi.distribusiname)
|
SelectCurrentDistribusi(newdistribusi.distribusiname)
|
||||||
zipfilename = "{}.zip".format(newdistribusi.distribusiname)
|
zipfilename = "{}.zip".format(newdistribusi.distribusiname)
|
||||||
zipfile = uploadform.zipfile.data
|
zipfile = uploadform.zipfile.data
|
||||||
|
56
verse/uploadpage.py
Normal file
56
verse/uploadpage.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
from flask import render_template
|
||||||
|
|
||||||
|
from forms.distribusiform import DistribusiForm
|
||||||
|
from forms.themeform import ThemeForm
|
||||||
|
from forms.publicthemeform import PublicThemeForm
|
||||||
|
from forms.selectorform import SelectorForm
|
||||||
|
|
||||||
|
# UserPengguna
|
||||||
|
from statuspengguna.helper import (
|
||||||
|
IsZipUploaded,
|
||||||
|
CurrentDistribusi,
|
||||||
|
HasDistribusi,
|
||||||
|
IsDistribusiLive,
|
||||||
|
IsCssSelected,
|
||||||
|
DistribusiLimitReached,
|
||||||
|
)
|
||||||
|
|
||||||
|
from upload import UploadNewDistribusi, UploadUpdatedFiles
|
||||||
|
from distribusisinfo import DistribusisInfo
|
||||||
|
from distribusiselector import SelectorVisible
|
||||||
|
|
||||||
|
|
||||||
|
def UploadPage(uploadfolder):
|
||||||
|
"render upload page section of distribusi workflow"
|
||||||
|
distribusiform = DistribusiForm()
|
||||||
|
themeform = ThemeForm()
|
||||||
|
publicthemeform = PublicThemeForm()
|
||||||
|
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes()
|
||||||
|
selectorform = SelectorForm()
|
||||||
|
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames()
|
||||||
|
selectorvisible = SelectorVisible()
|
||||||
|
|
||||||
|
current_distribusi = CurrentDistribusi()
|
||||||
|
if current_distribusi == "new" or HasDistribusi() is False:
|
||||||
|
uploadform = UploadNewDistribusi(uploadfolder)
|
||||||
|
else:
|
||||||
|
uploadform = UploadUpdatedFiles(uploadfolder)
|
||||||
|
|
||||||
|
files_uploaded = IsZipUploaded(uploadform.sitename.data)
|
||||||
|
distribusi_live = IsDistribusiLive(current_distribusi)
|
||||||
|
css_selected = IsCssSelected(current_distribusi)
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user