|
|
@ -1,5 +1,11 @@ |
|
|
|
import os |
|
|
|
from flask import render_template |
|
|
|
from sqlalchemy.exc import ( |
|
|
|
DataError, |
|
|
|
DatabaseError, |
|
|
|
InterfaceError, |
|
|
|
InvalidRequestError, |
|
|
|
) |
|
|
|
|
|
|
|
from statuspengguna.helper import ( |
|
|
|
IsZipUploaded, |
|
|
@ -14,7 +20,7 @@ from forms.editorform import EditorForm |
|
|
|
from forms.selectorform import SelectorForm |
|
|
|
|
|
|
|
|
|
|
|
def EditCss(): |
|
|
|
def Editor(): |
|
|
|
editorform = EditorForm() |
|
|
|
current_distribusi = CurrentDistribusi() |
|
|
|
if editorform.validate_on_submit(): |
|
|
@ -25,15 +31,68 @@ def EditCss(): |
|
|
|
|
|
|
|
|
|
|
|
def ValidateEditCssForm(editorform, current_distribusi): |
|
|
|
newcssfolder = os.path.join("themes/userstyles", current_distribusi) |
|
|
|
newcssfolder = os.path.join("themes/userthemes", current_distribusi) |
|
|
|
if editorform.public.data: |
|
|
|
MakePublicTheme(editorform, current_distribusi) |
|
|
|
publicfolder = os.path.join("themes/publicthemes", current_distribusi) |
|
|
|
if editorform.cssfile.data: |
|
|
|
SaveUploadCssFile(editorform, publicfolder) |
|
|
|
else: |
|
|
|
WriteCssToFile(editorform, publicfolder) |
|
|
|
if editorform.cssfile.data: |
|
|
|
SaveUploadCssFile(editorform, newcssfolder) |
|
|
|
return |
|
|
|
if editorform.cssname.data: |
|
|
|
WriteCssToFile(editorform, newcssfolder) |
|
|
|
|
|
|
|
|
|
|
|
def SaveUploadCssFile(editorform, newcssfolder): |
|
|
|
if not os.path.exists(newcssfolder): |
|
|
|
os.mkdir(newcssfolder) |
|
|
|
cssfile = editorform.cssfile.data |
|
|
|
cssfile.save(os.path.join(newcssfolder, editorform.cssfile.data.filename)) |
|
|
|
|
|
|
|
|
|
|
|
def WriteCssToFile(editorform, newcssfolder): |
|
|
|
if not os.path.exists(newcssfolder): |
|
|
|
os.mkdir(newcssfolder) |
|
|
|
|
|
|
|
cssfilename = "{}.css".format(editorform.cssname.data) |
|
|
|
with open(os.path.join(newcssfolder, cssfilename), "w") as cssfile: |
|
|
|
cssfile.write(editorform.css.data) |
|
|
|
cssfile.close |
|
|
|
|
|
|
|
|
|
|
|
def MakePublicTheme(editorform, current_distribusi): |
|
|
|
try: |
|
|
|
distribusi = Distribusis.query.filter_by( |
|
|
|
distribusiname=current_distribusi |
|
|
|
).first() |
|
|
|
distribusi.publictheme = editorform.public.data |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
except InvalidRequestError: |
|
|
|
db.session.rollback() |
|
|
|
editorform.public.errors.append("Something went wrong!") |
|
|
|
flash("Something went wrong!", "danger") |
|
|
|
except DataError: |
|
|
|
db.session.rollback() |
|
|
|
editorform.public.errors.append("Invalid Entry") |
|
|
|
flash("Invalid Entry", "warning") |
|
|
|
except InterfaceError: |
|
|
|
db.session.rollback() |
|
|
|
editorform.public.errors.append( |
|
|
|
"Error connecting to the database" |
|
|
|
) |
|
|
|
flash("Error connecting to the database", "danger") |
|
|
|
except DatabaseError: |
|
|
|
db.session.rollback() |
|
|
|
editorform.public.errors.append( |
|
|
|
"Error connecting to the database" |
|
|
|
) |
|
|
|
flash("Error connecting to the database", "danger") |
|
|
|
|
|
|
|
|
|
|
|
def RenderDistribusiTemplate(current_distribusi): |
|
|
|
uploadform = UploadForm() |
|
|
|
distribusiform = DistribusiForm() |
|
|
|