diff --git a/verse/admin.py b/verse/admin.py index 834af10..f95623b 100644 --- a/verse/admin.py +++ b/verse/admin.py @@ -1,6 +1,7 @@ from flask_login import current_user from models.user_model import User + def is_adminuser(): if not current_user.is_authenticated: return False diff --git a/verse/admin_page/admin_page.py b/verse/admin_page/admin_page.py index 3857cfe..faf46ac 100644 --- a/verse/admin_page/admin_page.py +++ b/verse/admin_page/admin_page.py @@ -12,7 +12,7 @@ from sqlalchemy.exc import ( from app import db from admin import is_adminuser -from distribusikan.distribusisinfo import DistribusisInfo +from distribusikan.distribusis_info import DistribusisInfo from admin_page.forms.admindistribusiform import AdminDistribusiForm from admin_page.forms.adminuserform import AdminUserForm from models.distribusi_model import Distribusis @@ -68,7 +68,7 @@ def delete_user_from_db(user): def delete_User_distribusis(user): - distribusis = DistribusisInfo.getuserdistribusis(user.email) + distribusis = DistribusisInfo.get_user_distribusis(user.email) for distribusi in distribusis: delete_distribusi_files(distribusi.distribusiname) delete_distribusi_from_db(distribusi) @@ -105,7 +105,7 @@ def delete_distribusi_files(distribusiname): def add_distribusis_to_form(admindistribusiform): - distribusis = DistribusisInfo.visibledistribusis() + distribusis = DistribusisInfo.visible_distribusis() admindistribusiform = AdminDistribusiForm.distribusi_list_form_builder( distribusis ) diff --git a/verse/distribusikan/editor.py b/verse/distribusikan/css_editor_page.py similarity index 74% rename from verse/distribusikan/editor.py rename to verse/distribusikan/css_editor_page.py index 384c8b1..8e9997e 100644 --- a/verse/distribusikan/editor.py +++ b/verse/distribusikan/css_editor_page.py @@ -13,7 +13,7 @@ from sqlalchemy.exc import ( from werkzeug.utils import secure_filename from app import db -from distribusikan.distribusisinfo import DistribusisInfo +from distribusikan.distribusis_info import DistribusisInfo from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.editorform import EditorForm from distribusikan.forms.publicthemeform import PublicThemeForm @@ -24,17 +24,17 @@ from models.distribusi_model import Distribusis from statuspengguna.helper import UserHelper -def Editor(): +def css_editor_page(): editorform = EditorForm() current_distribusi = UserHelper.current_distribusi() if editorform.validate_on_submit(): - ValidateEditCssForm(editorform, current_distribusi) - return RenderDistribusiTemplate(current_distribusi) + validate_edit_css_form(editorform, current_distribusi) + return render_distribusi_template(current_distribusi) - return RenderEditorTemplate(editorform, current_distribusi) + return render_editor_template(editorform, current_distribusi) -def ValidateEditCssForm(editorform, current_distribusi): +def validate_edit_css_form(editorform, current_distribusi): newcssfolder = os.path.join("themes/userthemes", current_distribusi) if os.path.exists(newcssfolder): shutil.rmtree(newcssfolder) @@ -44,22 +44,22 @@ def ValidateEditCssForm(editorform, current_distribusi): shutil.rmtree(publicfolder) if editorform.public.data: - MakePublicTheme(editorform, current_distribusi) + make_public_theme(editorform, current_distribusi) if editorform.cssfile.data: - SaveUploadCssFile(editorform, publicfolder) - CopyPublicToUserFolder(editorform, publicfolder, newcssfolder) + save_upload_css_file(editorform, publicfolder) + copy_public_to_user_folder(editorform, publicfolder, newcssfolder) return else: - WriteCssToFile(editorform, publicfolder) + write_css_to_file(editorform, publicfolder) if editorform.cssfile.data: - SaveUploadCssFile(editorform, newcssfolder) + save_upload_css_file(editorform, newcssfolder) return if editorform.cssname.data: - WriteCssToFile(editorform, newcssfolder) + write_css_to_file(editorform, newcssfolder) -def SaveUploadCssFile(editorform, newcssfolder): +def save_upload_css_file(editorform, newcssfolder): if not os.path.exists(newcssfolder): os.mkdir(newcssfolder) cssfile = editorform.cssfile.data @@ -74,7 +74,7 @@ def SaveUploadCssFile(editorform, newcssfolder): cleanfile.close() -def WriteCssToFile(editorform, newcssfolder): +def write_css_to_file(editorform, newcssfolder): if not os.path.exists(newcssfolder): os.mkdir(newcssfolder) @@ -86,7 +86,7 @@ def WriteCssToFile(editorform, newcssfolder): cssfile.close -def CopyPublicToUserFolder(editorform, publicfolder, newcssfolder): +def copy_public_to_user_folder(editorform, publicfolder, newcssfolder): if not os.path.exists(newcssfolder): os.mkdir(newcssfolder) copycssfile = os.path.join( @@ -97,7 +97,7 @@ def CopyPublicToUserFolder(editorform, publicfolder, newcssfolder): shutil.copy(copycssfile, newcssfolder) -def MakePublicTheme(editorform, current_distribusi): +def make_public_theme(editorform, current_distribusi): try: distribusi = Distribusis.query.filter_by( distribusiname=current_distribusi @@ -119,12 +119,12 @@ def MakePublicTheme(editorform, current_distribusi): editorform.public.errors.append("Error connecting to the database") -def RenderDistribusiTemplate(current_distribusi): +def render_distribusi_template(current_distribusi): uploadform = UploadForm() distribusiform = DistribusiForm() themeform = ThemeForm() publicthemeform = PublicThemeForm() - publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() + publicthemeform.publicthemes.choices = DistribusisInfo.public_themes() selectorform = SelectorForm() files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) @@ -148,11 +148,11 @@ def RenderDistribusiTemplate(current_distribusi): return template -def RenderEditorTemplate(editorform, current_distribusi): - htmlplaceholder = HtmlPlaceholder() +def render_editor_template(editorform, current_distribusi): + html_placeholder = get_html_placeholder() - cssplaceholder = CssPlaceholder(current_distribusi) - editorform.css.data = cssplaceholder + css_placeholder = get_css_placeholder(current_distribusi) + editorform.css.data = css_placeholder files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) distribusi_live = UserHelper.is_distribusi_live(current_distribusi) @@ -161,33 +161,33 @@ def RenderEditorTemplate(editorform, current_distribusi): files_uploaded=files_uploaded, distribusi_live=distribusi_live, editorform=editorform, - htmlplaceholder=htmlplaceholder, + html_placeholder=html_placeholder, ) return template -def CssPlaceholder(current_distribusi): - cssplaceholder = "Try out your CSS here" +def get_css_placeholder(current_distribusi): + css_placeholder = "Try out your CSS here" distribusi = Distribusis.query.filter_by( distribusiname=current_distribusi ).first() if distribusi is not None and distribusi.publictheme is not None: - cssplaceholder = GetPublicCssFile(distribusi) + css_placeholder = get_public_css_file(distribusi) else: with open("themes/editor/placeholder.css") as f: - cssplaceholder = f.read() - return cssplaceholder + css_placeholder = f.read() + return css_placeholder -def HtmlPlaceholder(): - htmlplaceholder = "Write some test HTML here" +def get_html_placeholder(): + html_placeholder = "Write some test HTML here" with open("themes/editor/placeholder.html") as f: - htmlplaceholder = f.read() - return htmlplaceholder + html_placeholder = f.read() + return html_placeholder -def GetPublicCssFile(distribusi): - cssplaceholder = "" +def get_public_css_file(distribusi): + css_placeholder = "" publicthemefolder = os.path.join( "themes/publicthemes", distribusi.distribusiname ) @@ -195,5 +195,5 @@ def GetPublicCssFile(distribusi): if filename.endswith(".css"): cssfile = os.path.join(publicthemefolder, filename) with open(cssfile) as f: - cssplaceholder = f.read() - return cssplaceholder + css_placeholder = f.read() + return css_placeholder diff --git a/verse/distribusikan/distribusiselector.py b/verse/distribusikan/distribusi_selector.py similarity index 81% rename from verse/distribusikan/distribusiselector.py rename to verse/distribusikan/distribusi_selector.py index ac0e040..39f46ca 100644 --- a/verse/distribusikan/distribusiselector.py +++ b/verse/distribusikan/distribusi_selector.py @@ -11,7 +11,7 @@ from sqlalchemy.exc import ( ) from app import db -from distribusikan.distribusisinfo import DistribusisInfo +from distribusikan.distribusis_info import DistribusisInfo from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.selectorform import SelectorForm @@ -24,49 +24,50 @@ from models.user_model import User from statuspengguna.helper import UserHelper -def DistribusiSelector(): +def distribusi_selector(): uploadform = UploadForm() selectorform = SelectorForm() - selectorform.distribusis.choices = DistribusisInfo.userdistribusinames() + selectorform.distribusis.choices = DistribusisInfo.user_distribusinames() current_distribusi = UserHelper.current_distribusi() if selectorform.validate_on_submit(): if selectorform.new.data: - SelectNewDistribusi() + select_new_distribusi() if selectorform.describe.data: - return SelectDescribeDistribusi(selectorform.distribusis.data) + return select_describe_distribusi(selectorform.distribusis.data) if selectorform.delete.data: - selectorform = DeleteDistribusi(selectorform.distribusis.data) + selectorform = delete_distribusi(selectorform.distribusis.data) selectorform.distribusis.choices = ( - DistribusisInfo.userdistribusinames() + DistribusisInfo.user_distribusinames() ) if selectorform.update.data: - SelectUpdateDistribusi(selectorform.distribusis.data) + select_update_distribusi(selectorform.distribusis.data) current_distribusi = UserHelper.current_distribusi() - uploadform = AutoFillInUploadForm(uploadform, current_distribusi) + uploadform = auto_fill_in_upload_form(uploadform, current_distribusi) - return RenderDistribusiTemplate( + return render_distribusi_template( selectorform, uploadform, current_distribusi ) -def AutoFillInUploadForm(uploadform, current_distribusi): +def auto_fill_in_upload_form(uploadform, current_distribusi): distribusi = Distribusis.query.filter_by( distribusiname=current_distribusi ).first() uploadform.sitename.data = distribusi.distribusiname uploadform.sitename.render_kw = {"readonly": True} + uploadform.description.data = distribusi.description uploadform.category.data = distribusi.category uploadform.year.data = distribusi.year uploadform.tags.data = distribusi.tags return uploadform -def SelectNewDistribusi(): +def select_new_distribusi(): print("make a new distribusi") - SelectCurrentDistribusi("new") + select_current_distribusi("new") -def SelectDescribeDistribusi(distribusiname): +def select_describe_distribusi(distribusiname): return redirect( url_for( "describer.show_distribusi_files", @@ -75,12 +76,12 @@ def SelectDescribeDistribusi(distribusiname): ) -def SelectUpdateDistribusi(distribusiname): +def select_update_distribusi(distribusiname): print(f"Update this distribusi {distribusiname}") - SelectCurrentDistribusi(distribusiname) + select_current_distribusi(distribusiname) -def DeleteDistribusi(distribusiname): +def delete_distribusi(distribusiname): print(f"delete this distribusi {distribusiname}") selectorform = SelectorForm() try: @@ -114,7 +115,7 @@ def DeleteDistribusi(distribusiname): return selectorform -def SelectCurrentDistribusi(distribusiname): +def select_current_distribusi(distribusiname): if not current_user.is_authenticated: return user = User.query.filter_by(email=current_user.email).first() @@ -143,11 +144,11 @@ def SelectorVisible(): return True -def RenderDistribusiTemplate(selectorform, uploadform, current_distribusi): +def render_distribusi_template(selectorform, uploadform, current_distribusi): distribusiform = DistribusiForm() themeform = ThemeForm() publicthemeform = PublicThemeForm() - publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() + publicthemeform.publicthemes.choices = DistribusisInfo.public_themes() files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) distribusi_live = UserHelper.is_distribusi_live(current_distribusi) diff --git a/verse/distribusikan/distribusiworkflow.py b/verse/distribusikan/distribusi_workflow.py similarity index 78% rename from verse/distribusikan/distribusiworkflow.py rename to verse/distribusikan/distribusi_workflow.py index f728292..0f91425 100644 --- a/verse/distribusikan/distribusiworkflow.py +++ b/verse/distribusikan/distribusi_workflow.py @@ -15,8 +15,8 @@ from sqlalchemy.exc import ( ) from app import db -from distribusikan.distribusiselector import SelectorVisible -from distribusikan.distribusisinfo import DistribusisInfo +from distribusikan.distribusi_selector import SelectorVisible +from distribusikan.distribusis_info import DistribusisInfo from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.selectorform import SelectorForm @@ -31,7 +31,7 @@ from models.user_model import User from statuspengguna.helper import UserHelper -def DistribusiWorkflow(): +def distribusi_workflow(): distribusiform = DistribusiForm() current_distribusi = UserHelper.current_distribusi() user = User.query.filter_by(email=current_user.email).first() @@ -41,18 +41,18 @@ def DistribusiWorkflow(): if distribusiform.validate_on_submit(): userfolder = os.path.join("stash", distribusi.distribusiname) - cssfile = GetCssFile(distribusi) - UnzipDistribusiFiles(distribusi, userfolder) - CleanUpDistribusiFiles(userfolder) - RunDistribusi(userfolder, cssfile) - SetDistribusiToVisible(distribusi, user) - DeleteCssFile(cssfile) + cssfile = get_css_file(distribusi) + unzip_distribusi_files(distribusi, userfolder) + clean_up_distribusi_files(userfolder) + run_distribusi(userfolder, cssfile) + set_distribusi_to_visible(distribusi, user) + delete_css_file(cssfile) return redirect(url_for("index")) - return RenderDistribusiTemplate(distribusiform, current_distribusi) + return render_distribusi_template(distribusiform, current_distribusi) -def UnzipDistribusiFiles(distribusi, userfolder): +def unzip_distribusi_files(distribusi, userfolder): zipfilename = "{}.zip".format(distribusi.distribusiname) unzipfile = os.path.join(userfolder, zipfilename) @@ -64,12 +64,12 @@ def UnzipDistribusiFiles(distribusi, userfolder): os.remove(os.path.join(userfolder, zipfilename)) -def CleanUpDistribusiFiles(userfolder): +def clean_up_distribusi_files(userfolder): if os.path.exists(userfolder): - RemoveMacFolders(userfolder) + remove_mac_folders(userfolder) -def RemoveMacFolders(path): +def remove_mac_folders(path): for filename in os.listdir(path): fullpath = os.path.join(path, filename) if filename.startswith("."): @@ -80,10 +80,10 @@ def RemoveMacFolders(path): if filename == "__MACOSX": shutil.rmtree(fullpath) if os.path.isdir(fullpath): - RemoveMacFolders(fullpath) + remove_mac_folders(fullpath) -def GetCssFile(distribusi): +def get_css_file(distribusi): cssfile = "" cssfolder = os.path.join("themes/userthemes", distribusi.distribusiname) if os.path.exists(cssfolder): @@ -93,13 +93,13 @@ def GetCssFile(distribusi): return cssfile -def RunDistribusi(userfolder, cssfile): +def run_distribusi(userfolder, cssfile): parser = build_argparser() args = parser.parse_args(["-t", "--menu-with-index", "-s", cssfile]) distribusify(args, userfolder) -def SetDistribusiToVisible(distribusi, user): +def set_distribusi_to_visible(distribusi, user): try: distribusi.visible = True user.currentdistribusi = None @@ -109,18 +109,18 @@ def SetDistribusiToVisible(distribusi, user): flash("Unknown error occured!") -def DeleteCssFile(cssfile): +def delete_css_file(cssfile): if os.path.exists(cssfile): os.remove(cssfile) -def RenderDistribusiTemplate(distribusiform, current_distribusi): +def render_distribusi_template(distribusiform, current_distribusi): uploadform = UploadForm() themeform = ThemeForm() publicthemeform = PublicThemeForm() - publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() + publicthemeform.publicthemes.choices = DistribusisInfo.public_themes() selectorform = SelectorForm() - selectorform.distribusis.choices = DistribusisInfo.userdistribusinames() + selectorform.distribusis.choices = DistribusisInfo.user_distribusinames() selectorvisible = SelectorVisible() files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) diff --git a/verse/distribusikan/distribusikan.py b/verse/distribusikan/distribusikan.py index 444cb96..870ac47 100644 --- a/verse/distribusikan/distribusikan.py +++ b/verse/distribusikan/distribusikan.py @@ -1,13 +1,13 @@ from flask import Blueprint from flask_login import login_required -from distribusikan.distribusiselector import DistribusiSelector +from distribusikan.distribusi_selector import distribusi_selector # Distribusi Information -from distribusikan.distribusiworkflow import DistribusiWorkflow -from distribusikan.editor import Editor -from distribusikan.themeselector import ThemeSelector -from distribusikan.uploadpage import UploadPage +from distribusikan.distribusi_workflow import distribusi_workflow +from distribusikan.css_editor_page import css_editor_page +from distribusikan.theme_selector import theme_selector +from distribusikan.upload_page import upload_page distribusikan = Blueprint( "distribusikan", @@ -20,28 +20,28 @@ distribusikan = Blueprint( @distribusikan.route("/distribusi", methods=["GET", "POST"]) @login_required def distribusi(): - return DistribusiWorkflow() + return distribusi_workflow() @distribusikan.route("/upload", methods=["POST"]) @login_required def upload(): - return UploadPage() + return upload_page() @distribusikan.route("/theme", methods=["GET", "POST"]) @login_required def theme(): - return ThemeSelector() + return theme_selector() @distribusikan.route("/editor", methods=["GET", "POST"]) @login_required def editor(): - return Editor() + return css_editor_page() @distribusikan.route("/selector", methods=["GET", "POST"]) @login_required def selector(): - return DistribusiSelector() + return distribusi_selector() diff --git a/verse/distribusikan/distribusisinfo.py b/verse/distribusikan/distribusis_info.py similarity index 90% rename from verse/distribusikan/distribusisinfo.py rename to verse/distribusikan/distribusis_info.py index 19ef284..aa614bb 100644 --- a/verse/distribusikan/distribusisinfo.py +++ b/verse/distribusikan/distribusis_info.py @@ -5,14 +5,14 @@ from models.user_model import User class DistribusisInfo: - def userdistribusinames(): + def user_distribusinames(): distribusinames = [] user = User.query.filter_by(email=current_user.email).first() for distribusi in Distribusis.query.filter_by(userid=user.id).all(): distribusinames.append(distribusi.distribusiname) return distribusinames - def publicthemes(): + def public_themes(): publicthemes = [] distribusis = Distribusis.query.filter( Distribusis.publictheme.isnot(None) @@ -27,12 +27,12 @@ made by {user.username}""", publicthemes.append(publictheme) return publicthemes - def visibledistribusis(): + def visible_distribusis(): distribusis = Distribusis.query.filter( Distribusis.visible.isnot(False) ).all() return distribusis - def getuserdistribusis(useremail): + def get_user_distribusis(useremail): user = User.query.filter_by(email=useremail).first() return Distribusis.query.filter_by(userid=user.id).all() diff --git a/verse/distribusikan/forms/uploadform.py b/verse/distribusikan/forms/uploadform.py index 8bec973..f0af89b 100644 --- a/verse/distribusikan/forms/uploadform.py +++ b/verse/distribusikan/forms/uploadform.py @@ -57,17 +57,6 @@ class UploadForm(FlaskForm): ], widget=TextArea(), ) - mdfile = FileField( - "Alternatively upload a markdown file with a description:", - validators=[ - FileAllowed(["md"], "markdown only"), - FileRequired(), - FileSize( - max_size=10485760, - message="markdown file size should be smaller than 10MB", - ), - ], - ) year = SelectField( "Year:", validate_choice=True, diff --git a/verse/distribusikan/templates/distribusikan/distribusi.html b/verse/distribusikan/templates/distribusikan/distribusi.html index e85f04c..38874d5 100644 --- a/verse/distribusikan/templates/distribusikan/distribusi.html +++ b/verse/distribusikan/templates/distribusikan/distribusi.html @@ -20,23 +20,23 @@