|
|
@ -1,5 +1,6 @@ |
|
|
|
import os |
|
|
|
import bleach |
|
|
|
from bleach_allowlist import all_styles |
|
|
|
import shutil |
|
|
|
from flask import render_template |
|
|
|
|
|
|
@ -52,8 +53,11 @@ def ValidateEditCssForm(editorform, current_distribusi): |
|
|
|
MakePublicTheme(editorform, current_distribusi) |
|
|
|
if editorform.cssfile.data: |
|
|
|
SaveUploadCssFile(editorform, publicfolder) |
|
|
|
CopyPublicToUserFolder(editorform, publicfolder, newcssfolder) |
|
|
|
return |
|
|
|
else: |
|
|
|
WriteCssToFile(editorform, publicfolder) |
|
|
|
|
|
|
|
if editorform.cssfile.data: |
|
|
|
SaveUploadCssFile(editorform, newcssfolder) |
|
|
|
return |
|
|
@ -68,7 +72,8 @@ def SaveUploadCssFile(editorform, newcssfolder): |
|
|
|
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()) |
|
|
|
cleancss = bleach.clean(openfile.read(), all_styles) |
|
|
|
cleancss = cleancss.replace('>', '>') |
|
|
|
openfile.close() |
|
|
|
cleanfile = open(os.path.join(newcssfolder, cssfilename), "w") |
|
|
|
cleanfile.write(cleancss) |
|
|
@ -80,12 +85,25 @@ def WriteCssToFile(editorform, newcssfolder): |
|
|
|
os.mkdir(newcssfolder) |
|
|
|
|
|
|
|
cssfilename = f"{secure_filename(editorform.cssname.data)}.css" |
|
|
|
cleancss = bleach.clean(editorform.css.data) |
|
|
|
cleancss = bleach.clean(editorform.css.data, all_styles) |
|
|
|
cleancss = cleancss.replace('>', '>') |
|
|
|
with open(os.path.join(newcssfolder, cssfilename), "w") as cssfile: |
|
|
|
cssfile.write(cleancss) |
|
|
|
cssfile.close |
|
|
|
|
|
|
|
|
|
|
|
def CopyPublicToUserFolder(editorform, publicfolder, newcssfolder): |
|
|
|
if not os.path.exists(newcssfolder): |
|
|
|
os.mkdir(newcssfolder) |
|
|
|
copycssfile = os.path.join( |
|
|
|
publicfolder, |
|
|
|
f"{secure_filename(editorform.cssname.data)}.css" |
|
|
|
) |
|
|
|
print(f"copying file: {copycssfile}") |
|
|
|
print(f"to folder: {newcssfolder}") |
|
|
|
shutil.copy(copycssfile, newcssfolder) |
|
|
|
|
|
|
|
|
|
|
|
def MakePublicTheme(editorform, current_distribusi): |
|
|
|
try: |
|
|
|
distribusi = Distribusis.query.filter_by( |
|
|
|