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