refactor after hours: added description with md file to distribusi
This commit is contained in:
parent
10b56e7479
commit
62428e84ae
@ -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
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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
|
@ -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)
|
||||
|
@ -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)
|
@ -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()
|
||||
|
@ -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()
|
@ -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,
|
||||
|
@ -20,23 +20,23 @@
|
||||
<div id="mainworkflow">
|
||||
{% 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%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_1.svg')}}" />
|
||||
{% block theme %}
|
||||
{% include "distribusiworkflow/theme.html" %}
|
||||
{% include "distribusi_workflow/theme.html" %}
|
||||
{% endblock theme%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_2.svg')}}" />
|
||||
{% block editcss %}
|
||||
{% include "distribusiworkflow/editcss.html" %}
|
||||
{% include "distribusi_workflow/editcss.html" %}
|
||||
{% endblock editcss%}
|
||||
<img src="{{ url_for('static', filename='svg/arrow_3.svg')}}" />
|
||||
{% block launch %}
|
||||
{% include "distribusiworkflow/launch.html" %}
|
||||
{% include "distribusi_workflow/launch.html" %}
|
||||
{% endblock launch%}
|
||||
{%endif%}
|
||||
</div>
|
||||
|
@ -17,13 +17,6 @@
|
||||
<div class="error">{{ message }}</div>
|
||||
{% endfor %}
|
||||
</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">
|
||||
{{ uploadform.year.label }}
|
||||
<div class="selector-style">
|
@ -5,7 +5,7 @@
|
||||
<div class="editarea editor">
|
||||
<fieldset class="required">
|
||||
<textarea id="html" placeholder="Write some test HTML here" readonly>
|
||||
{{htmlplaceholder}}
|
||||
{{html_placeholder}}
|
||||
</textarea>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
@ -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()
|
@ -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
|
||||
|
@ -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)
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user