|
|
@ -1,5 +1,7 @@ |
|
|
|
import os |
|
|
|
from flask import render_template |
|
|
|
import bleach |
|
|
|
from werkzeug.utils import secure_filename |
|
|
|
from sqlalchemy.exc import ( |
|
|
|
DataError, |
|
|
|
DatabaseError, |
|
|
@ -54,16 +56,22 @@ def SaveUploadCssFile(editorform, newcssfolder): |
|
|
|
if not os.path.exists(newcssfolder): |
|
|
|
os.mkdir(newcssfolder) |
|
|
|
cssfile = editorform.cssfile.data |
|
|
|
cssfile.save(os.path.join(newcssfolder, editorform.cssname.data)) |
|
|
|
cssfilename = f"{secure_filename(editorform.cssname.data)}.css" |
|
|
|
cssfile.save(os.path.join(newcssfolder, cssfilename)) |
|
|
|
openfile = open(os.path.join(newcssfolder, cssfilename), 'r+') |
|
|
|
cleancss = bleach.clean(openfile.read()) |
|
|
|
openfile.write(cleancss) |
|
|
|
openfile.close |
|
|
|
|
|
|
|
|
|
|
|
def WriteCssToFile(editorform, newcssfolder): |
|
|
|
if not os.path.exists(newcssfolder): |
|
|
|
os.mkdir(newcssfolder) |
|
|
|
|
|
|
|
cssfilename = "{}.css".format(editorform.cssname.data) |
|
|
|
cssfilename = f"{secure_filename(editorform.cssname.data)}.css" |
|
|
|
cleancss = bleach.clean(editorform.css.data) |
|
|
|
with open(os.path.join(newcssfolder, cssfilename), "w") as cssfile: |
|
|
|
cssfile.write(editorform.css.data) |
|
|
|
cssfile.write(cleancss) |
|
|
|
cssfile.close |
|
|
|
|
|
|
|
|
|
|
@ -72,7 +80,7 @@ def MakePublicTheme(editorform, current_distribusi): |
|
|
|
distribusi = Distribusis.query.filter_by( |
|
|
|
distribusiname=current_distribusi |
|
|
|
).first() |
|
|
|
distribusi.publictheme = editorform.cssname.data |
|
|
|
distribusi.publictheme = secure_filename(editorform.cssname.data) |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
except InvalidRequestError: |
|
|
|