From 62428e84ae3a56f0f87d1259a159056b64969b6c Mon Sep 17 00:00:00 2001 From: crunk Date: Mon, 17 Jun 2024 22:36:23 +0200 Subject: [PATCH] refactor after hours: added description with md file to distribusi --- verse/admin.py | 1 + verse/admin_page/admin_page.py | 6 +- .../{editor.py => css_editor_page.py} | 72 +++++++++---------- ...busiselector.py => distribusi_selector.py} | 41 +++++------ ...busiworkflow.py => distribusi_workflow.py} | 44 ++++++------ verse/distribusikan/distribusikan.py | 20 +++--- ...distribusisinfo.py => distribusis_info.py} | 8 +-- verse/distribusikan/forms/uploadform.py | 11 --- .../templates/distribusikan/distribusi.html | 10 +-- .../editcss.html | 0 .../launch.html | 0 .../selector.html | 0 .../theme.html | 0 .../upload.html | 7 -- .../templates/distribusikan/editor.html | 2 +- .../{themeselector.py => theme_selector.py} | 16 ++--- verse/distribusikan/upload.py | 10 +-- .../{uploadpage.py => upload_page.py} | 16 ++--- verse/models/distribusi_model.py | 1 + verse/start.py | 6 +- verse/statuspengguna/helper.py | 4 +- 21 files changed, 131 insertions(+), 144 deletions(-) rename verse/distribusikan/{editor.py => css_editor_page.py} (74%) rename verse/distribusikan/{distribusiselector.py => distribusi_selector.py} (81%) rename verse/distribusikan/{distribusiworkflow.py => distribusi_workflow.py} (78%) rename verse/distribusikan/{distribusisinfo.py => distribusis_info.py} (90%) rename verse/distribusikan/templates/distribusikan/{distribusiworkflow => distribusi_workflow}/editcss.html (100%) rename verse/distribusikan/templates/distribusikan/{distribusiworkflow => distribusi_workflow}/launch.html (100%) rename verse/distribusikan/templates/distribusikan/{distribusiworkflow => distribusi_workflow}/selector.html (100%) rename verse/distribusikan/templates/distribusikan/{distribusiworkflow => distribusi_workflow}/theme.html (100%) rename verse/distribusikan/templates/distribusikan/{distribusiworkflow => distribusi_workflow}/upload.html (89%) rename verse/distribusikan/{themeselector.py => theme_selector.py} (83%) rename verse/distribusikan/{uploadpage.py => upload_page.py} (78%) 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 @@
{% if selectorvisible %} {% block selector %} - {% include "distribusiworkflow/selector.html" %} + {% include "distribusi_workflow/selector.html" %} {% endblock selector%} {% else %} {% block upload %} - {% include "distribusiworkflow/upload.html" %} + {% include "distribusi_workflow/upload.html" %} {% endblock upload%} {% block theme %} - {% include "distribusiworkflow/theme.html" %} + {% include "distribusi_workflow/theme.html" %} {% endblock theme%} {% block editcss %} - {% include "distribusiworkflow/editcss.html" %} + {% include "distribusi_workflow/editcss.html" %} {% endblock editcss%} {% block launch %} - {% include "distribusiworkflow/launch.html" %} + {% include "distribusi_workflow/launch.html" %} {% endblock launch%} {%endif%}
diff --git a/verse/distribusikan/templates/distribusikan/distribusiworkflow/editcss.html b/verse/distribusikan/templates/distribusikan/distribusi_workflow/editcss.html similarity index 100% rename from verse/distribusikan/templates/distribusikan/distribusiworkflow/editcss.html rename to verse/distribusikan/templates/distribusikan/distribusi_workflow/editcss.html diff --git a/verse/distribusikan/templates/distribusikan/distribusiworkflow/launch.html b/verse/distribusikan/templates/distribusikan/distribusi_workflow/launch.html similarity index 100% rename from verse/distribusikan/templates/distribusikan/distribusiworkflow/launch.html rename to verse/distribusikan/templates/distribusikan/distribusi_workflow/launch.html diff --git a/verse/distribusikan/templates/distribusikan/distribusiworkflow/selector.html b/verse/distribusikan/templates/distribusikan/distribusi_workflow/selector.html similarity index 100% rename from verse/distribusikan/templates/distribusikan/distribusiworkflow/selector.html rename to verse/distribusikan/templates/distribusikan/distribusi_workflow/selector.html diff --git a/verse/distribusikan/templates/distribusikan/distribusiworkflow/theme.html b/verse/distribusikan/templates/distribusikan/distribusi_workflow/theme.html similarity index 100% rename from verse/distribusikan/templates/distribusikan/distribusiworkflow/theme.html rename to verse/distribusikan/templates/distribusikan/distribusi_workflow/theme.html diff --git a/verse/distribusikan/templates/distribusikan/distribusiworkflow/upload.html b/verse/distribusikan/templates/distribusikan/distribusi_workflow/upload.html similarity index 89% rename from verse/distribusikan/templates/distribusikan/distribusiworkflow/upload.html rename to verse/distribusikan/templates/distribusikan/distribusi_workflow/upload.html index 38157af..f8a0502 100644 --- a/verse/distribusikan/templates/distribusikan/distribusiworkflow/upload.html +++ b/verse/distribusikan/templates/distribusikan/distribusi_workflow/upload.html @@ -17,13 +17,6 @@
{{ message }}
{% endfor %} -
- {{ uploadform.mdfile.label }} - {{ uploadform.mdfile }} - {% for message in uploadform.mdfile.errors %} -
{{ message }}
- {% endfor %} -
{{ uploadform.year.label }}
diff --git a/verse/distribusikan/templates/distribusikan/editor.html b/verse/distribusikan/templates/distribusikan/editor.html index b6e39f4..273d3fe 100644 --- a/verse/distribusikan/templates/distribusikan/editor.html +++ b/verse/distribusikan/templates/distribusikan/editor.html @@ -5,7 +5,7 @@
diff --git a/verse/distribusikan/themeselector.py b/verse/distribusikan/theme_selector.py similarity index 83% rename from verse/distribusikan/themeselector.py rename to verse/distribusikan/theme_selector.py index b32a338..30388e4 100644 --- a/verse/distribusikan/themeselector.py +++ b/verse/distribusikan/theme_selector.py @@ -3,7 +3,7 @@ import shutil from flask import render_template -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 @@ -12,36 +12,36 @@ from distribusikan.forms.uploadform import UploadForm from statuspengguna.helper import UserHelper -def ThemeSelector(): +def theme_selector(): themeform = ThemeForm() publicthemeform = PublicThemeForm() - publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() + publicthemeform.publicthemes.choices = DistribusisInfo.public_themes() current_distribusi = UserHelper.current_distribusi() if themeform.validate_on_submit(): copycssfile = os.path.join( "themes", f"{themeform.theme.data}.css", ) - MoveCssToUserFolder(current_distribusi, copycssfile) + move_css_to_user_folder(current_distribusi, copycssfile) if publicthemeform.validate_on_submit(): copycssfile = os.path.join( "themes/publicthemes/", f"{publicthemeform.publicthemes.data}.css", ) - MoveCssToUserFolder(current_distribusi, copycssfile) - return RenderDistribusiTemplate( + move_css_to_user_folder(current_distribusi, copycssfile) + return render_distribusi_template( themeform, publicthemeform, current_distribusi ) -def MoveCssToUserFolder(current_distribusi, copycssfile): +def move_css_to_user_folder(current_distribusi, copycssfile): newcssfolder = os.path.join("themes/userthemes", current_distribusi) if not os.path.exists(newcssfolder): os.mkdir(newcssfolder) shutil.copy(copycssfile, newcssfolder) -def RenderDistribusiTemplate(themeform, publicthemeform, current_distribusi): +def render_distribusi_template(themeform, publicthemeform, current_distribusi): uploadform = UploadForm() distribusiform = DistribusiForm() selectorform = SelectorForm() diff --git a/verse/distribusikan/upload.py b/verse/distribusikan/upload.py index 47a9009..b81e3e6 100644 --- a/verse/distribusikan/upload.py +++ b/verse/distribusikan/upload.py @@ -12,14 +12,14 @@ from sqlalchemy.exc import ( ) from app import db -from distribusikan.distribusiselector import SelectCurrentDistribusi +from distribusikan.distribusi_selector import select_current_distribusi from distribusikan.forms.uploadform import UploadForm from models.distribusi_model import Distribusis from models.user_model import User from statuspengguna.helper import UserHelper -def UploadNewDistribusi(uploadfolder): +def upload_new_distribusi(uploadfolder): uploadform = UploadForm() if uploadform.validate_on_submit(): user = User.query.filter_by(email=current_user.email).first() @@ -28,6 +28,7 @@ def UploadNewDistribusi(uploadfolder): distribusiname=uploadform.sitename.data, userid=user.id, category=uploadform.category.data, + description=uploadform.description.data, year=uploadform.year.data, tags=uploadform.tags.data, ) @@ -46,7 +47,7 @@ def UploadNewDistribusi(uploadfolder): uploadform.sitename.errors.append("Something went wrong!") flash("Something went wrong!", "danger") return uploadform - SelectCurrentDistribusi(newdistribusi.distribusiname) + select_current_distribusi(newdistribusi.distribusiname) zipfilename = "{}.zip".format(newdistribusi.distribusiname) zipfile = uploadform.zipfile.data zipfile.save(os.path.join(uploadfolder, zipfilename)) @@ -62,7 +63,7 @@ def UploadNewDistribusi(uploadfolder): return uploadform -def UploadUpdatedFiles(uploadfolder): +def upload_updates_files(uploadfolder): uploadform = UploadForm() if uploadform.validate_on_submit(): try: @@ -71,6 +72,7 @@ def UploadUpdatedFiles(uploadfolder): distribusiname=current_distribusi ).first() distribusi.category = uploadform.category.data + distribusi.description = (uploadform.description.data,) distribusi.year = uploadform.year.data distribusi.tags = uploadform.tags.data distribusi.visible = False diff --git a/verse/distribusikan/uploadpage.py b/verse/distribusikan/upload_page.py similarity index 78% rename from verse/distribusikan/uploadpage.py rename to verse/distribusikan/upload_page.py index 8a500cd..fc3b7d1 100644 --- a/verse/distribusikan/uploadpage.py +++ b/verse/distribusikan/upload_page.py @@ -1,9 +1,9 @@ from flask import render_template from app import APP -from distribusikan.distribusiselector import SelectorVisible -from distribusikan.distribusisinfo import DistribusisInfo -from distribusikan.upload import UploadNewDistribusi, UploadUpdatedFiles +from distribusikan.distribusi_selector import SelectorVisible +from distribusikan.distribusis_info import DistribusisInfo +from distribusikan.upload import upload_new_distribusi, upload_updates_files from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.selectorform import SelectorForm @@ -13,22 +13,22 @@ from distribusikan.forms.themeform import ThemeForm from statuspengguna.helper import UserHelper -def UploadPage(): +def upload_page(): "render upload page section of distribusi workflow" uploadfolder = APP.config["UPLOAD_FOLDER"] distribusiform = DistribusiForm() 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() current_distribusi = UserHelper.current_distribusi() if current_distribusi == "new" or UserHelper.has_distribusi() is False: - uploadform = UploadNewDistribusi(uploadfolder) + uploadform = upload_new_distribusi(uploadfolder) else: - uploadform = UploadUpdatedFiles(uploadfolder) + uploadform = upload_updates_files(uploadfolder) files_uploaded = UserHelper.is_zip_uploaded(uploadform.sitename.data) distribusi_live = UserHelper.is_distribusi_live(current_distribusi) diff --git a/verse/models/distribusi_model.py b/verse/models/distribusi_model.py index d8f114e..dd9f040 100644 --- a/verse/models/distribusi_model.py +++ b/verse/models/distribusi_model.py @@ -11,6 +11,7 @@ class Distribusis(db.Model): userid = db.Column(db.Integer, db.ForeignKey("users.id")) category = db.Column(db.String(500), nullable=True, unique=False) year = db.Column(db.String(9), nullable=True, unique=False) + description = db.Column(db.String(32000), nullable=True, unique=False) tags = db.Column(db.String(500), nullable=True, unique=False) publictheme = db.Column(db.String(300), unique=True, nullable=True) visible = db.Column(db.Boolean, default=False) diff --git a/verse/start.py b/verse/start.py index 7deb7e5..7391dcb 100644 --- a/verse/start.py +++ b/verse/start.py @@ -18,7 +18,7 @@ from admin_page.admin_page import admin_page from app import create_app, login_manager, db from describer.describe_files import describer from distribusikan.distribusikan import distribusikan -from distribusikan.distribusisinfo import DistribusisInfo +from distribusikan.distribusis_info import DistribusisInfo from distribusikan.forms.uploadform import UploadForm from models.distribusi_model import Distribusis from models.user_model import User @@ -34,7 +34,7 @@ APP.register_blueprint(describer, url_prefix="/describer") APP.register_blueprint(login_section, url_prefix="/login") APP.register_blueprint(register_user, url_prefix="/register") APP.register_blueprint(forgot_password, url_prefix="/login/forgotpassword") -APP.register_blueprint (admin_page, url_prefix="/admin") +APP.register_blueprint(admin_page, url_prefix="/admin") APP.register_blueprint(distribusikan) @@ -48,7 +48,7 @@ def session_handler(): def index(): UserHelper.reset_user_state() uploadform = UploadForm() - distribusis = DistribusisInfo.visibledistribusis() + distribusis = DistribusisInfo.visible_distribusis() distribusisindex = {} for distribusi in distribusis: user = User.query.filter_by(id=distribusi.userid).first() diff --git a/verse/statuspengguna/helper.py b/verse/statuspengguna/helper.py index a8b26bd..5605bd9 100644 --- a/verse/statuspengguna/helper.py +++ b/verse/statuspengguna/helper.py @@ -10,7 +10,7 @@ from sqlalchemy.exc import ( ) from app import db -from distribusikan.distribusisinfo import DistribusisInfo +from distribusikan.distribusis_info import DistribusisInfo from models.distribusi_model import Distribusis from models.user_model import User @@ -76,7 +76,7 @@ class UserHelper: def distribusi_limit_reached(): user = User.query.filter_by(email=current_user.email).first() - distribusiamount = len(DistribusisInfo.getuserdistribusis(user.email)) + distribusiamount = len(DistribusisInfo.get_user_distribusis(user.email)) if distribusiamount > 19: print("user already has 20 distribusis") return True