Browse Source

refactor after hours: added description with md file to distribusi

pull/12/head
crunk 5 months ago
parent
commit
62428e84ae
  1. 1
      verse/admin.py
  2. 6
      verse/admin_page/admin_page.py
  3. 72
      verse/distribusikan/css_editor_page.py
  4. 41
      verse/distribusikan/distribusi_selector.py
  5. 44
      verse/distribusikan/distribusi_workflow.py
  6. 20
      verse/distribusikan/distribusikan.py
  7. 8
      verse/distribusikan/distribusis_info.py
  8. 11
      verse/distribusikan/forms/uploadform.py
  9. 10
      verse/distribusikan/templates/distribusikan/distribusi.html
  10. 0
      verse/distribusikan/templates/distribusikan/distribusi_workflow/editcss.html
  11. 0
      verse/distribusikan/templates/distribusikan/distribusi_workflow/launch.html
  12. 0
      verse/distribusikan/templates/distribusikan/distribusi_workflow/selector.html
  13. 0
      verse/distribusikan/templates/distribusikan/distribusi_workflow/theme.html
  14. 7
      verse/distribusikan/templates/distribusikan/distribusi_workflow/upload.html
  15. 2
      verse/distribusikan/templates/distribusikan/editor.html
  16. 16
      verse/distribusikan/theme_selector.py
  17. 10
      verse/distribusikan/upload.py
  18. 16
      verse/distribusikan/upload_page.py
  19. 1
      verse/models/distribusi_model.py
  20. 6
      verse/start.py
  21. 4
      verse/statuspengguna/helper.py

1
verse/admin.py

@ -1,6 +1,7 @@
from flask_login import current_user from flask_login import current_user
from models.user_model import User from models.user_model import User
def is_adminuser(): def is_adminuser():
if not current_user.is_authenticated: if not current_user.is_authenticated:
return False return False

6
verse/admin_page/admin_page.py

@ -12,7 +12,7 @@ from sqlalchemy.exc import (
from app import db from app import db
from admin import is_adminuser 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.admindistribusiform import AdminDistribusiForm
from admin_page.forms.adminuserform import AdminUserForm from admin_page.forms.adminuserform import AdminUserForm
from models.distribusi_model import Distribusis from models.distribusi_model import Distribusis
@ -68,7 +68,7 @@ def delete_user_from_db(user):
def delete_User_distribusis(user): def delete_User_distribusis(user):
distribusis = DistribusisInfo.getuserdistribusis(user.email) distribusis = DistribusisInfo.get_user_distribusis(user.email)
for distribusi in distribusis: for distribusi in distribusis:
delete_distribusi_files(distribusi.distribusiname) delete_distribusi_files(distribusi.distribusiname)
delete_distribusi_from_db(distribusi) delete_distribusi_from_db(distribusi)
@ -105,7 +105,7 @@ def delete_distribusi_files(distribusiname):
def add_distribusis_to_form(admindistribusiform): def add_distribusis_to_form(admindistribusiform):
distribusis = DistribusisInfo.visibledistribusis() distribusis = DistribusisInfo.visible_distribusis()
admindistribusiform = AdminDistribusiForm.distribusi_list_form_builder( admindistribusiform = AdminDistribusiForm.distribusi_list_form_builder(
distribusis distribusis
) )

72
verse/distribusikan/editor.py → verse/distribusikan/css_editor_page.py

@ -13,7 +13,7 @@ from sqlalchemy.exc import (
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from app import db from app import db
from distribusikan.distribusisinfo import DistribusisInfo from distribusikan.distribusis_info import DistribusisInfo
from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.distribusiform import DistribusiForm
from distribusikan.forms.editorform import EditorForm from distribusikan.forms.editorform import EditorForm
from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.publicthemeform import PublicThemeForm
@ -24,17 +24,17 @@ from models.distribusi_model import Distribusis
from statuspengguna.helper import UserHelper from statuspengguna.helper import UserHelper
def Editor(): def css_editor_page():
editorform = EditorForm() editorform = EditorForm()
current_distribusi = UserHelper.current_distribusi() current_distribusi = UserHelper.current_distribusi()
if editorform.validate_on_submit(): if editorform.validate_on_submit():
ValidateEditCssForm(editorform, current_distribusi) validate_edit_css_form(editorform, current_distribusi)
return RenderDistribusiTemplate(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) newcssfolder = os.path.join("themes/userthemes", current_distribusi)
if os.path.exists(newcssfolder): if os.path.exists(newcssfolder):
shutil.rmtree(newcssfolder) shutil.rmtree(newcssfolder)
@ -44,22 +44,22 @@ def ValidateEditCssForm(editorform, current_distribusi):
shutil.rmtree(publicfolder) shutil.rmtree(publicfolder)
if editorform.public.data: if editorform.public.data:
MakePublicTheme(editorform, current_distribusi) make_public_theme(editorform, current_distribusi)
if editorform.cssfile.data: if editorform.cssfile.data:
SaveUploadCssFile(editorform, publicfolder) save_upload_css_file(editorform, publicfolder)
CopyPublicToUserFolder(editorform, publicfolder, newcssfolder) copy_public_to_user_folder(editorform, publicfolder, newcssfolder)
return return
else: else:
WriteCssToFile(editorform, publicfolder) write_css_to_file(editorform, publicfolder)
if editorform.cssfile.data: if editorform.cssfile.data:
SaveUploadCssFile(editorform, newcssfolder) save_upload_css_file(editorform, newcssfolder)
return return
if editorform.cssname.data: 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): if not os.path.exists(newcssfolder):
os.mkdir(newcssfolder) os.mkdir(newcssfolder)
cssfile = editorform.cssfile.data cssfile = editorform.cssfile.data
@ -74,7 +74,7 @@ def SaveUploadCssFile(editorform, newcssfolder):
cleanfile.close() cleanfile.close()
def WriteCssToFile(editorform, newcssfolder): def write_css_to_file(editorform, newcssfolder):
if not os.path.exists(newcssfolder): if not os.path.exists(newcssfolder):
os.mkdir(newcssfolder) os.mkdir(newcssfolder)
@ -86,7 +86,7 @@ def WriteCssToFile(editorform, newcssfolder):
cssfile.close cssfile.close
def CopyPublicToUserFolder(editorform, publicfolder, newcssfolder): def copy_public_to_user_folder(editorform, publicfolder, newcssfolder):
if not os.path.exists(newcssfolder): if not os.path.exists(newcssfolder):
os.mkdir(newcssfolder) os.mkdir(newcssfolder)
copycssfile = os.path.join( copycssfile = os.path.join(
@ -97,7 +97,7 @@ def CopyPublicToUserFolder(editorform, publicfolder, newcssfolder):
shutil.copy(copycssfile, newcssfolder) shutil.copy(copycssfile, newcssfolder)
def MakePublicTheme(editorform, current_distribusi): def make_public_theme(editorform, current_distribusi):
try: try:
distribusi = Distribusis.query.filter_by( distribusi = Distribusis.query.filter_by(
distribusiname=current_distribusi distribusiname=current_distribusi
@ -119,12 +119,12 @@ def MakePublicTheme(editorform, current_distribusi):
editorform.public.errors.append("Error connecting to the database") editorform.public.errors.append("Error connecting to the database")
def RenderDistribusiTemplate(current_distribusi): def render_distribusi_template(current_distribusi):
uploadform = UploadForm() uploadform = UploadForm()
distribusiform = DistribusiForm() distribusiform = DistribusiForm()
themeform = ThemeForm() themeform = ThemeForm()
publicthemeform = PublicThemeForm() publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() publicthemeform.publicthemes.choices = DistribusisInfo.public_themes()
selectorform = SelectorForm() selectorform = SelectorForm()
files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) files_uploaded = UserHelper.is_zip_uploaded(current_distribusi)
@ -148,11 +148,11 @@ def RenderDistribusiTemplate(current_distribusi):
return template return template
def RenderEditorTemplate(editorform, current_distribusi): def render_editor_template(editorform, current_distribusi):
htmlplaceholder = HtmlPlaceholder() html_placeholder = get_html_placeholder()
cssplaceholder = CssPlaceholder(current_distribusi) css_placeholder = get_css_placeholder(current_distribusi)
editorform.css.data = cssplaceholder editorform.css.data = css_placeholder
files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) files_uploaded = UserHelper.is_zip_uploaded(current_distribusi)
distribusi_live = UserHelper.is_distribusi_live(current_distribusi) distribusi_live = UserHelper.is_distribusi_live(current_distribusi)
@ -161,33 +161,33 @@ def RenderEditorTemplate(editorform, current_distribusi):
files_uploaded=files_uploaded, files_uploaded=files_uploaded,
distribusi_live=distribusi_live, distribusi_live=distribusi_live,
editorform=editorform, editorform=editorform,
htmlplaceholder=htmlplaceholder, html_placeholder=html_placeholder,
) )
return template return template
def CssPlaceholder(current_distribusi): def get_css_placeholder(current_distribusi):
cssplaceholder = "Try out your CSS here" css_placeholder = "Try out your CSS here"
distribusi = Distribusis.query.filter_by( distribusi = Distribusis.query.filter_by(
distribusiname=current_distribusi distribusiname=current_distribusi
).first() ).first()
if distribusi is not None and distribusi.publictheme is not None: if distribusi is not None and distribusi.publictheme is not None:
cssplaceholder = GetPublicCssFile(distribusi) css_placeholder = get_public_css_file(distribusi)
else: else:
with open("themes/editor/placeholder.css") as f: with open("themes/editor/placeholder.css") as f:
cssplaceholder = f.read() css_placeholder = f.read()
return cssplaceholder return css_placeholder
def HtmlPlaceholder(): def get_html_placeholder():
htmlplaceholder = "Write some test HTML here" html_placeholder = "Write some test HTML here"
with open("themes/editor/placeholder.html") as f: with open("themes/editor/placeholder.html") as f:
htmlplaceholder = f.read() html_placeholder = f.read()
return htmlplaceholder return html_placeholder
def GetPublicCssFile(distribusi): def get_public_css_file(distribusi):
cssplaceholder = "" css_placeholder = ""
publicthemefolder = os.path.join( publicthemefolder = os.path.join(
"themes/publicthemes", distribusi.distribusiname "themes/publicthemes", distribusi.distribusiname
) )
@ -195,5 +195,5 @@ def GetPublicCssFile(distribusi):
if filename.endswith(".css"): if filename.endswith(".css"):
cssfile = os.path.join(publicthemefolder, filename) cssfile = os.path.join(publicthemefolder, filename)
with open(cssfile) as f: with open(cssfile) as f:
cssplaceholder = f.read() css_placeholder = f.read()
return cssplaceholder return css_placeholder

41
verse/distribusikan/distribusiselector.py → verse/distribusikan/distribusi_selector.py

@ -11,7 +11,7 @@ from sqlalchemy.exc import (
) )
from app import db from app import db
from distribusikan.distribusisinfo import DistribusisInfo from distribusikan.distribusis_info import DistribusisInfo
from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.distribusiform import DistribusiForm
from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.publicthemeform import PublicThemeForm
from distribusikan.forms.selectorform import SelectorForm from distribusikan.forms.selectorform import SelectorForm
@ -24,49 +24,50 @@ from models.user_model import User
from statuspengguna.helper import UserHelper from statuspengguna.helper import UserHelper
def DistribusiSelector(): def distribusi_selector():
uploadform = UploadForm() uploadform = UploadForm()
selectorform = SelectorForm() selectorform = SelectorForm()
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames() selectorform.distribusis.choices = DistribusisInfo.user_distribusinames()
current_distribusi = UserHelper.current_distribusi() current_distribusi = UserHelper.current_distribusi()
if selectorform.validate_on_submit(): if selectorform.validate_on_submit():
if selectorform.new.data: if selectorform.new.data:
SelectNewDistribusi() select_new_distribusi()
if selectorform.describe.data: if selectorform.describe.data:
return SelectDescribeDistribusi(selectorform.distribusis.data) return select_describe_distribusi(selectorform.distribusis.data)
if selectorform.delete.data: if selectorform.delete.data:
selectorform = DeleteDistribusi(selectorform.distribusis.data) selectorform = delete_distribusi(selectorform.distribusis.data)
selectorform.distribusis.choices = ( selectorform.distribusis.choices = (
DistribusisInfo.userdistribusinames() DistribusisInfo.user_distribusinames()
) )
if selectorform.update.data: if selectorform.update.data:
SelectUpdateDistribusi(selectorform.distribusis.data) select_update_distribusi(selectorform.distribusis.data)
current_distribusi = UserHelper.current_distribusi() 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 selectorform, uploadform, current_distribusi
) )
def AutoFillInUploadForm(uploadform, current_distribusi): def auto_fill_in_upload_form(uploadform, current_distribusi):
distribusi = Distribusis.query.filter_by( distribusi = Distribusis.query.filter_by(
distribusiname=current_distribusi distribusiname=current_distribusi
).first() ).first()
uploadform.sitename.data = distribusi.distribusiname uploadform.sitename.data = distribusi.distribusiname
uploadform.sitename.render_kw = {"readonly": True} uploadform.sitename.render_kw = {"readonly": True}
uploadform.description.data = distribusi.description
uploadform.category.data = distribusi.category uploadform.category.data = distribusi.category
uploadform.year.data = distribusi.year uploadform.year.data = distribusi.year
uploadform.tags.data = distribusi.tags uploadform.tags.data = distribusi.tags
return uploadform return uploadform
def SelectNewDistribusi(): def select_new_distribusi():
print("make a new distribusi") print("make a new distribusi")
SelectCurrentDistribusi("new") select_current_distribusi("new")
def SelectDescribeDistribusi(distribusiname): def select_describe_distribusi(distribusiname):
return redirect( return redirect(
url_for( url_for(
"describer.show_distribusi_files", "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}") 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}") print(f"delete this distribusi {distribusiname}")
selectorform = SelectorForm() selectorform = SelectorForm()
try: try:
@ -114,7 +115,7 @@ def DeleteDistribusi(distribusiname):
return selectorform return selectorform
def SelectCurrentDistribusi(distribusiname): def select_current_distribusi(distribusiname):
if not current_user.is_authenticated: if not current_user.is_authenticated:
return return
user = User.query.filter_by(email=current_user.email).first() user = User.query.filter_by(email=current_user.email).first()
@ -143,11 +144,11 @@ def SelectorVisible():
return True return True
def RenderDistribusiTemplate(selectorform, uploadform, current_distribusi): def render_distribusi_template(selectorform, uploadform, current_distribusi):
distribusiform = DistribusiForm() distribusiform = DistribusiForm()
themeform = ThemeForm() themeform = ThemeForm()
publicthemeform = PublicThemeForm() publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() publicthemeform.publicthemes.choices = DistribusisInfo.public_themes()
files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) files_uploaded = UserHelper.is_zip_uploaded(current_distribusi)
distribusi_live = UserHelper.is_distribusi_live(current_distribusi) distribusi_live = UserHelper.is_distribusi_live(current_distribusi)

44
verse/distribusikan/distribusiworkflow.py → verse/distribusikan/distribusi_workflow.py

@ -15,8 +15,8 @@ from sqlalchemy.exc import (
) )
from app import db from app import db
from distribusikan.distribusiselector import SelectorVisible from distribusikan.distribusi_selector import SelectorVisible
from distribusikan.distribusisinfo import DistribusisInfo from distribusikan.distribusis_info import DistribusisInfo
from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.distribusiform import DistribusiForm
from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.publicthemeform import PublicThemeForm
from distribusikan.forms.selectorform import SelectorForm from distribusikan.forms.selectorform import SelectorForm
@ -31,7 +31,7 @@ from models.user_model import User
from statuspengguna.helper import UserHelper from statuspengguna.helper import UserHelper
def DistribusiWorkflow(): def distribusi_workflow():
distribusiform = DistribusiForm() distribusiform = DistribusiForm()
current_distribusi = UserHelper.current_distribusi() current_distribusi = UserHelper.current_distribusi()
user = User.query.filter_by(email=current_user.email).first() user = User.query.filter_by(email=current_user.email).first()
@ -41,18 +41,18 @@ def DistribusiWorkflow():
if distribusiform.validate_on_submit(): if distribusiform.validate_on_submit():
userfolder = os.path.join("stash", distribusi.distribusiname) userfolder = os.path.join("stash", distribusi.distribusiname)
cssfile = GetCssFile(distribusi) cssfile = get_css_file(distribusi)
UnzipDistribusiFiles(distribusi, userfolder) unzip_distribusi_files(distribusi, userfolder)
CleanUpDistribusiFiles(userfolder) clean_up_distribusi_files(userfolder)
RunDistribusi(userfolder, cssfile) run_distribusi(userfolder, cssfile)
SetDistribusiToVisible(distribusi, user) set_distribusi_to_visible(distribusi, user)
DeleteCssFile(cssfile) delete_css_file(cssfile)
return redirect(url_for("index")) 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) zipfilename = "{}.zip".format(distribusi.distribusiname)
unzipfile = os.path.join(userfolder, zipfilename) unzipfile = os.path.join(userfolder, zipfilename)
@ -64,12 +64,12 @@ def UnzipDistribusiFiles(distribusi, userfolder):
os.remove(os.path.join(userfolder, zipfilename)) os.remove(os.path.join(userfolder, zipfilename))
def CleanUpDistribusiFiles(userfolder): def clean_up_distribusi_files(userfolder):
if os.path.exists(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): for filename in os.listdir(path):
fullpath = os.path.join(path, filename) fullpath = os.path.join(path, filename)
if filename.startswith("."): if filename.startswith("."):
@ -80,10 +80,10 @@ def RemoveMacFolders(path):
if filename == "__MACOSX": if filename == "__MACOSX":
shutil.rmtree(fullpath) shutil.rmtree(fullpath)
if os.path.isdir(fullpath): if os.path.isdir(fullpath):
RemoveMacFolders(fullpath) remove_mac_folders(fullpath)
def GetCssFile(distribusi): def get_css_file(distribusi):
cssfile = "" cssfile = ""
cssfolder = os.path.join("themes/userthemes", distribusi.distribusiname) cssfolder = os.path.join("themes/userthemes", distribusi.distribusiname)
if os.path.exists(cssfolder): if os.path.exists(cssfolder):
@ -93,13 +93,13 @@ def GetCssFile(distribusi):
return cssfile return cssfile
def RunDistribusi(userfolder, cssfile): def run_distribusi(userfolder, cssfile):
parser = build_argparser() parser = build_argparser()
args = parser.parse_args(["-t", "--menu-with-index", "-s", cssfile]) args = parser.parse_args(["-t", "--menu-with-index", "-s", cssfile])
distribusify(args, userfolder) distribusify(args, userfolder)
def SetDistribusiToVisible(distribusi, user): def set_distribusi_to_visible(distribusi, user):
try: try:
distribusi.visible = True distribusi.visible = True
user.currentdistribusi = None user.currentdistribusi = None
@ -109,18 +109,18 @@ def SetDistribusiToVisible(distribusi, user):
flash("Unknown error occured!") flash("Unknown error occured!")
def DeleteCssFile(cssfile): def delete_css_file(cssfile):
if os.path.exists(cssfile): if os.path.exists(cssfile):
os.remove(cssfile) os.remove(cssfile)
def RenderDistribusiTemplate(distribusiform, current_distribusi): def render_distribusi_template(distribusiform, current_distribusi):
uploadform = UploadForm() uploadform = UploadForm()
themeform = ThemeForm() themeform = ThemeForm()
publicthemeform = PublicThemeForm() publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() publicthemeform.publicthemes.choices = DistribusisInfo.public_themes()
selectorform = SelectorForm() selectorform = SelectorForm()
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames() selectorform.distribusis.choices = DistribusisInfo.user_distribusinames()
selectorvisible = SelectorVisible() selectorvisible = SelectorVisible()
files_uploaded = UserHelper.is_zip_uploaded(current_distribusi) files_uploaded = UserHelper.is_zip_uploaded(current_distribusi)

20
verse/distribusikan/distribusikan.py

@ -1,13 +1,13 @@
from flask import Blueprint from flask import Blueprint
from flask_login import login_required from flask_login import login_required
from distribusikan.distribusiselector import DistribusiSelector from distribusikan.distribusi_selector import distribusi_selector
# Distribusi Information # Distribusi Information
from distribusikan.distribusiworkflow import DistribusiWorkflow from distribusikan.distribusi_workflow import distribusi_workflow
from distribusikan.editor import Editor from distribusikan.css_editor_page import css_editor_page
from distribusikan.themeselector import ThemeSelector from distribusikan.theme_selector import theme_selector
from distribusikan.uploadpage import UploadPage from distribusikan.upload_page import upload_page
distribusikan = Blueprint( distribusikan = Blueprint(
"distribusikan", "distribusikan",
@ -20,28 +20,28 @@ distribusikan = Blueprint(
@distribusikan.route("/distribusi", methods=["GET", "POST"]) @distribusikan.route("/distribusi", methods=["GET", "POST"])
@login_required @login_required
def distribusi(): def distribusi():
return DistribusiWorkflow() return distribusi_workflow()
@distribusikan.route("/upload", methods=["POST"]) @distribusikan.route("/upload", methods=["POST"])
@login_required @login_required
def upload(): def upload():
return UploadPage() return upload_page()
@distribusikan.route("/theme", methods=["GET", "POST"]) @distribusikan.route("/theme", methods=["GET", "POST"])
@login_required @login_required
def theme(): def theme():
return ThemeSelector() return theme_selector()
@distribusikan.route("/editor", methods=["GET", "POST"]) @distribusikan.route("/editor", methods=["GET", "POST"])
@login_required @login_required
def editor(): def editor():
return Editor() return css_editor_page()
@distribusikan.route("/selector", methods=["GET", "POST"]) @distribusikan.route("/selector", methods=["GET", "POST"])
@login_required @login_required
def selector(): def selector():
return DistribusiSelector() return distribusi_selector()

8
verse/distribusikan/distribusisinfo.py → verse/distribusikan/distribusis_info.py

@ -5,14 +5,14 @@ from models.user_model import User
class DistribusisInfo: class DistribusisInfo:
def userdistribusinames(): def user_distribusinames():
distribusinames = [] distribusinames = []
user = User.query.filter_by(email=current_user.email).first() user = User.query.filter_by(email=current_user.email).first()
for distribusi in Distribusis.query.filter_by(userid=user.id).all(): for distribusi in Distribusis.query.filter_by(userid=user.id).all():
distribusinames.append(distribusi.distribusiname) distribusinames.append(distribusi.distribusiname)
return distribusinames return distribusinames
def publicthemes(): def public_themes():
publicthemes = [] publicthemes = []
distribusis = Distribusis.query.filter( distribusis = Distribusis.query.filter(
Distribusis.publictheme.isnot(None) Distribusis.publictheme.isnot(None)
@ -27,12 +27,12 @@ made by {user.username}""",
publicthemes.append(publictheme) publicthemes.append(publictheme)
return publicthemes return publicthemes
def visibledistribusis(): def visible_distribusis():
distribusis = Distribusis.query.filter( distribusis = Distribusis.query.filter(
Distribusis.visible.isnot(False) Distribusis.visible.isnot(False)
).all() ).all()
return distribusis return distribusis
def getuserdistribusis(useremail): def get_user_distribusis(useremail):
user = User.query.filter_by(email=useremail).first() user = User.query.filter_by(email=useremail).first()
return Distribusis.query.filter_by(userid=user.id).all() return Distribusis.query.filter_by(userid=user.id).all()

11
verse/distribusikan/forms/uploadform.py

@ -57,17 +57,6 @@ class UploadForm(FlaskForm):
], ],
widget=TextArea(), 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 = SelectField(
"Year:", "Year:",
validate_choice=True, validate_choice=True,

10
verse/distribusikan/templates/distribusikan/distribusi.html

@ -20,23 +20,23 @@
<div id="mainworkflow"> <div id="mainworkflow">
{% if selectorvisible %} {% if selectorvisible %}
{% block selector %} {% block selector %}
{% include "distribusiworkflow/selector.html" %} {% include "distribusi_workflow/selector.html" %}
{% endblock selector%} {% endblock selector%}
{% else %} {% else %}
{% block upload %} {% block upload %}
{% include "distribusiworkflow/upload.html" %} {% include "distribusi_workflow/upload.html" %}
{% endblock upload%} {% endblock upload%}
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" /> <img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
{% block theme %} {% block theme %}
{% include "distribusiworkflow/theme.html" %} {% include "distribusi_workflow/theme.html" %}
{% endblock theme%} {% endblock theme%}
<img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" /> <img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" />
{% block editcss %} {% block editcss %}
{% include "distribusiworkflow/editcss.html" %} {% include "distribusi_workflow/editcss.html" %}
{% endblock editcss%} {% endblock editcss%}
<img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" /> <img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" />
{% block launch %} {% block launch %}
{% include "distribusiworkflow/launch.html" %} {% include "distribusi_workflow/launch.html" %}
{% endblock launch%} {% endblock launch%}
{%endif%} {%endif%}
</div> </div>

0
verse/distribusikan/templates/distribusikan/distribusiworkflow/editcss.html → verse/distribusikan/templates/distribusikan/distribusi_workflow/editcss.html

0
verse/distribusikan/templates/distribusikan/distribusiworkflow/launch.html → verse/distribusikan/templates/distribusikan/distribusi_workflow/launch.html

0
verse/distribusikan/templates/distribusikan/distribusiworkflow/selector.html → verse/distribusikan/templates/distribusikan/distribusi_workflow/selector.html

0
verse/distribusikan/templates/distribusikan/distribusiworkflow/theme.html → verse/distribusikan/templates/distribusikan/distribusi_workflow/theme.html

7
verse/distribusikan/templates/distribusikan/distribusiworkflow/upload.html → verse/distribusikan/templates/distribusikan/distribusi_workflow/upload.html

@ -17,13 +17,6 @@
<div class="error">{{ message }}</div> <div class="error">{{ message }}</div>
{% endfor %} {% endfor %}
</fieldset> </fieldset>
<fieldset class="required">
{{ uploadform.mdfile.label }}
{{ uploadform.mdfile }}
{% for message in uploadform.mdfile.errors %}
<div class="error">{{ message }}</div>
{% endfor %}
</fieldset>
<fieldset class="required"> <fieldset class="required">
{{ uploadform.year.label }} {{ uploadform.year.label }}
<div class="selector-style"> <div class="selector-style">

2
verse/distribusikan/templates/distribusikan/editor.html

@ -5,7 +5,7 @@
<div class="editarea editor"> <div class="editarea editor">
<fieldset class="required"> <fieldset class="required">
<textarea id="html" placeholder="Write some test HTML here" readonly> <textarea id="html" placeholder="Write some test HTML here" readonly>
{{htmlplaceholder}} {{html_placeholder}}
</textarea> </textarea>
</fieldset> </fieldset>
</div> </div>

16
verse/distribusikan/themeselector.py → verse/distribusikan/theme_selector.py

@ -3,7 +3,7 @@ import shutil
from flask import render_template 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.distribusiform import DistribusiForm
from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.publicthemeform import PublicThemeForm
from distribusikan.forms.selectorform import SelectorForm from distribusikan.forms.selectorform import SelectorForm
@ -12,36 +12,36 @@ from distribusikan.forms.uploadform import UploadForm
from statuspengguna.helper import UserHelper from statuspengguna.helper import UserHelper
def ThemeSelector(): def theme_selector():
themeform = ThemeForm() themeform = ThemeForm()
publicthemeform = PublicThemeForm() publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() publicthemeform.publicthemes.choices = DistribusisInfo.public_themes()
current_distribusi = UserHelper.current_distribusi() current_distribusi = UserHelper.current_distribusi()
if themeform.validate_on_submit(): if themeform.validate_on_submit():
copycssfile = os.path.join( copycssfile = os.path.join(
"themes", "themes",
f"{themeform.theme.data}.css", f"{themeform.theme.data}.css",
) )
MoveCssToUserFolder(current_distribusi, copycssfile) move_css_to_user_folder(current_distribusi, copycssfile)
if publicthemeform.validate_on_submit(): if publicthemeform.validate_on_submit():
copycssfile = os.path.join( copycssfile = os.path.join(
"themes/publicthemes/", "themes/publicthemes/",
f"{publicthemeform.publicthemes.data}.css", f"{publicthemeform.publicthemes.data}.css",
) )
MoveCssToUserFolder(current_distribusi, copycssfile) move_css_to_user_folder(current_distribusi, copycssfile)
return RenderDistribusiTemplate( return render_distribusi_template(
themeform, publicthemeform, current_distribusi 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) newcssfolder = os.path.join("themes/userthemes", current_distribusi)
if not os.path.exists(newcssfolder): if not os.path.exists(newcssfolder):
os.mkdir(newcssfolder) os.mkdir(newcssfolder)
shutil.copy(copycssfile, newcssfolder) shutil.copy(copycssfile, newcssfolder)
def RenderDistribusiTemplate(themeform, publicthemeform, current_distribusi): def render_distribusi_template(themeform, publicthemeform, current_distribusi):
uploadform = UploadForm() uploadform = UploadForm()
distribusiform = DistribusiForm() distribusiform = DistribusiForm()
selectorform = SelectorForm() selectorform = SelectorForm()

10
verse/distribusikan/upload.py

@ -12,14 +12,14 @@ from sqlalchemy.exc import (
) )
from app import db from app import db
from distribusikan.distribusiselector import SelectCurrentDistribusi from distribusikan.distribusi_selector import select_current_distribusi
from distribusikan.forms.uploadform import UploadForm from distribusikan.forms.uploadform import UploadForm
from models.distribusi_model import Distribusis from models.distribusi_model import Distribusis
from models.user_model import User from models.user_model import User
from statuspengguna.helper import UserHelper from statuspengguna.helper import UserHelper
def UploadNewDistribusi(uploadfolder): def upload_new_distribusi(uploadfolder):
uploadform = UploadForm() uploadform = UploadForm()
if uploadform.validate_on_submit(): if uploadform.validate_on_submit():
user = User.query.filter_by(email=current_user.email).first() user = User.query.filter_by(email=current_user.email).first()
@ -28,6 +28,7 @@ def UploadNewDistribusi(uploadfolder):
distribusiname=uploadform.sitename.data, distribusiname=uploadform.sitename.data,
userid=user.id, userid=user.id,
category=uploadform.category.data, category=uploadform.category.data,
description=uploadform.description.data,
year=uploadform.year.data, year=uploadform.year.data,
tags=uploadform.tags.data, tags=uploadform.tags.data,
) )
@ -46,7 +47,7 @@ def UploadNewDistribusi(uploadfolder):
uploadform.sitename.errors.append("Something went wrong!") uploadform.sitename.errors.append("Something went wrong!")
flash("Something went wrong!", "danger") flash("Something went wrong!", "danger")
return uploadform return uploadform
SelectCurrentDistribusi(newdistribusi.distribusiname) select_current_distribusi(newdistribusi.distribusiname)
zipfilename = "{}.zip".format(newdistribusi.distribusiname) zipfilename = "{}.zip".format(newdistribusi.distribusiname)
zipfile = uploadform.zipfile.data zipfile = uploadform.zipfile.data
zipfile.save(os.path.join(uploadfolder, zipfilename)) zipfile.save(os.path.join(uploadfolder, zipfilename))
@ -62,7 +63,7 @@ def UploadNewDistribusi(uploadfolder):
return uploadform return uploadform
def UploadUpdatedFiles(uploadfolder): def upload_updates_files(uploadfolder):
uploadform = UploadForm() uploadform = UploadForm()
if uploadform.validate_on_submit(): if uploadform.validate_on_submit():
try: try:
@ -71,6 +72,7 @@ def UploadUpdatedFiles(uploadfolder):
distribusiname=current_distribusi distribusiname=current_distribusi
).first() ).first()
distribusi.category = uploadform.category.data distribusi.category = uploadform.category.data
distribusi.description = (uploadform.description.data,)
distribusi.year = uploadform.year.data distribusi.year = uploadform.year.data
distribusi.tags = uploadform.tags.data distribusi.tags = uploadform.tags.data
distribusi.visible = False distribusi.visible = False

16
verse/distribusikan/uploadpage.py → verse/distribusikan/upload_page.py

@ -1,9 +1,9 @@
from flask import render_template from flask import render_template
from app import APP from app import APP
from distribusikan.distribusiselector import SelectorVisible from distribusikan.distribusi_selector import SelectorVisible
from distribusikan.distribusisinfo import DistribusisInfo from distribusikan.distribusis_info import DistribusisInfo
from distribusikan.upload import UploadNewDistribusi, UploadUpdatedFiles from distribusikan.upload import upload_new_distribusi, upload_updates_files
from distribusikan.forms.distribusiform import DistribusiForm from distribusikan.forms.distribusiform import DistribusiForm
from distribusikan.forms.publicthemeform import PublicThemeForm from distribusikan.forms.publicthemeform import PublicThemeForm
from distribusikan.forms.selectorform import SelectorForm from distribusikan.forms.selectorform import SelectorForm
@ -13,22 +13,22 @@ from distribusikan.forms.themeform import ThemeForm
from statuspengguna.helper import UserHelper from statuspengguna.helper import UserHelper
def UploadPage(): def upload_page():
"render upload page section of distribusi workflow" "render upload page section of distribusi workflow"
uploadfolder = APP.config["UPLOAD_FOLDER"] uploadfolder = APP.config["UPLOAD_FOLDER"]
distribusiform = DistribusiForm() distribusiform = DistribusiForm()
themeform = ThemeForm() themeform = ThemeForm()
publicthemeform = PublicThemeForm() publicthemeform = PublicThemeForm()
publicthemeform.publicthemes.choices = DistribusisInfo.publicthemes() publicthemeform.publicthemes.choices = DistribusisInfo.public_themes()
selectorform = SelectorForm() selectorform = SelectorForm()
selectorform.distribusis.choices = DistribusisInfo.userdistribusinames() selectorform.distribusis.choices = DistribusisInfo.user_distribusinames()
selectorvisible = SelectorVisible() selectorvisible = SelectorVisible()
current_distribusi = UserHelper.current_distribusi() current_distribusi = UserHelper.current_distribusi()
if current_distribusi == "new" or UserHelper.has_distribusi() is False: if current_distribusi == "new" or UserHelper.has_distribusi() is False:
uploadform = UploadNewDistribusi(uploadfolder) uploadform = upload_new_distribusi(uploadfolder)
else: else:
uploadform = UploadUpdatedFiles(uploadfolder) uploadform = upload_updates_files(uploadfolder)
files_uploaded = UserHelper.is_zip_uploaded(uploadform.sitename.data) files_uploaded = UserHelper.is_zip_uploaded(uploadform.sitename.data)
distribusi_live = UserHelper.is_distribusi_live(current_distribusi) distribusi_live = UserHelper.is_distribusi_live(current_distribusi)

1
verse/models/distribusi_model.py

@ -11,6 +11,7 @@ class Distribusis(db.Model):
userid = db.Column(db.Integer, db.ForeignKey("users.id")) userid = db.Column(db.Integer, db.ForeignKey("users.id"))
category = db.Column(db.String(500), nullable=True, unique=False) category = db.Column(db.String(500), nullable=True, unique=False)
year = db.Column(db.String(9), 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) tags = db.Column(db.String(500), nullable=True, unique=False)
publictheme = db.Column(db.String(300), unique=True, nullable=True) publictheme = db.Column(db.String(300), unique=True, nullable=True)
visible = db.Column(db.Boolean, default=False) visible = db.Column(db.Boolean, default=False)

6
verse/start.py

@ -18,7 +18,7 @@ from admin_page.admin_page import admin_page
from app import create_app, login_manager, db from app import create_app, login_manager, db
from describer.describe_files import describer from describer.describe_files import describer
from distribusikan.distribusikan import distribusikan from distribusikan.distribusikan import distribusikan
from distribusikan.distribusisinfo import DistribusisInfo from distribusikan.distribusis_info import DistribusisInfo
from distribusikan.forms.uploadform import UploadForm from distribusikan.forms.uploadform import UploadForm
from models.distribusi_model import Distribusis from models.distribusi_model import Distribusis
from models.user_model import User 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(login_section, url_prefix="/login")
APP.register_blueprint(register_user, url_prefix="/register") APP.register_blueprint(register_user, url_prefix="/register")
APP.register_blueprint(forgot_password, url_prefix="/login/forgotpassword") 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) APP.register_blueprint(distribusikan)
@ -48,7 +48,7 @@ def session_handler():
def index(): def index():
UserHelper.reset_user_state() UserHelper.reset_user_state()
uploadform = UploadForm() uploadform = UploadForm()
distribusis = DistribusisInfo.visibledistribusis() distribusis = DistribusisInfo.visible_distribusis()
distribusisindex = {} distribusisindex = {}
for distribusi in distribusis: for distribusi in distribusis:
user = User.query.filter_by(id=distribusi.userid).first() user = User.query.filter_by(id=distribusi.userid).first()

4
verse/statuspengguna/helper.py

@ -10,7 +10,7 @@ from sqlalchemy.exc import (
) )
from app import db from app import db
from distribusikan.distribusisinfo import DistribusisInfo from distribusikan.distribusis_info import DistribusisInfo
from models.distribusi_model import Distribusis from models.distribusi_model import Distribusis
from models.user_model import User from models.user_model import User
@ -76,7 +76,7 @@ class UserHelper:
def distribusi_limit_reached(): def distribusi_limit_reached():
user = User.query.filter_by(email=current_user.email).first() 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: if distribusiamount > 19:
print("user already has 20 distribusis") print("user already has 20 distribusis")
return True return True

Loading…
Cancel
Save