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