|
@ -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 |