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