From 80f08d4bf9c9b81f6215fc75830a9e25f4e53cf0 Mon Sep 17 00:00:00 2001 From: crunk Date: Wed, 23 Mar 2022 21:57:28 +0100 Subject: [PATCH] refactoring distribusi work flow page, upload section --- verse/distribusiselector.py | 2 +- verse/start.py | 59 +++++-------------------------------- verse/static/css/style.css | 3 +- verse/upload.py | 10 ++++--- verse/uploadpage.py | 56 +++++++++++++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 57 deletions(-) create mode 100644 verse/uploadpage.py diff --git a/verse/distribusiselector.py b/verse/distribusiselector.py index aef787b..c7749f7 100644 --- a/verse/distribusiselector.py +++ b/verse/distribusiselector.py @@ -31,7 +31,7 @@ from statuspengguna.helper import ( from app import db -def SelectorPage(): +def DistribusiSelector(): uploadform = UploadForm() selectorform = SelectorForm() selectorform.distribusis.choices = DistribusisInfo.userdistribusinames() diff --git a/verse/start.py b/verse/start.py index 9d64d29..34ab33e 100644 --- a/verse/start.py +++ b/verse/start.py @@ -1,6 +1,5 @@ """This is the main flask distribusi page""" from datetime import timedelta - from flask import ( render_template, redirect, @@ -13,37 +12,23 @@ from flask_login import ( login_required, current_user, ) - from flask_wtf.csrf import CSRFError - from app import create_app, login_manager from usermodel import User -# Forms! +# Use upload form to populate filters 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 editor import Editor from themeselector import ThemeSelector from distribusiworkflow import DistribusiWorkflow -from distribusiselector import SelectorPage, SelectorVisible -from upload import UploadNewDistribusi, UploadUpdatedFiles +from distribusiselector import DistribusiSelector +from uploadpage import UploadPage # UserPengguna -from statuspengguna.helper import ( - IsZipUploaded, - IsCssSelected, - CurrentDistribusi, - HasDistribusi, - IsDistribusiLive, - ResetUserState, - DistribusiLimitReached, -) +from statuspengguna.helper import ResetUserState from statuspengguna.loginuser import LoginUser from statuspengguna.registeruser import RegisterUser from distribusisinfo import DistribusisInfo @@ -98,36 +83,8 @@ def distribusi(): @APP.route("/upload", methods=["POST"]) @login_required def upload(): - 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(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 + uploadfolder = APP.config["UPLOAD_FOLDER"] + return UploadPage(uploadfolder) @APP.route("/theme", methods=["GET", "POST"]) @@ -145,7 +102,7 @@ def editor(): @APP.route("/selector", methods=["GET", "POST"]) @login_required def selector(): - return SelectorPage() + return DistribusiSelector() @APP.route("/stash/") diff --git a/verse/static/css/style.css b/verse/static/css/style.css index 69dd6d6..efc6f5a 100644 --- a/verse/static/css/style.css +++ b/verse/static/css/style.css @@ -120,7 +120,8 @@ input[type="submit"]:disabled:focus { } .error { - color: #aa5050; + font-size: 110%; + color: #F92020; } #delete { diff --git a/verse/upload.py b/verse/upload.py index df2560a..704e0f7 100644 --- a/verse/upload.py +++ b/verse/upload.py @@ -35,16 +35,18 @@ def UploadNewDistribusi(uploadfolder): user.currentdistribusi = uploadform.sitename.data db.session.add(newdistribusi) 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: db.session.rollback() uploadform.sitename.errors.append( "distribusi name already exists!" ) 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) zipfilename = "{}.zip".format(newdistribusi.distribusiname) zipfile = uploadform.zipfile.data diff --git a/verse/uploadpage.py b/verse/uploadpage.py new file mode 100644 index 0000000..cfa283e --- /dev/null +++ b/verse/uploadpage.py @@ -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