Browse Source

2 custome theme bugfixes

current_wdka_release
crunk 3 years ago
parent
commit
1b9cc35cbe
  1. 5
      verse/distribusiselector.py
  2. 22
      verse/editor.py
  3. 2
      verse/statuspengguna/resetpassword.py

5
verse/distribusiselector.py

@ -94,6 +94,11 @@ def DeleteDistribusi(distribusiname):
"themes/userthemes", distribusi.distribusiname "themes/userthemes", distribusi.distribusiname
) )
shutil.rmtree(cssfolder) shutil.rmtree(cssfolder)
if distribusi.publictheme is not None:
publicthemefolder = os.path.join(
"themes/publicthemes", distribusi.distribusiname
)
shutil.rmtree(publicthemefolder)
# SelectField error is list is a tuple?? why?? # SelectField error is list is a tuple?? why??
# selectorform.distribusis.errors.append("Distribusi deleted!") # selectorform.distribusis.errors.append("Distribusi deleted!")
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): except (InvalidRequestError, DataError, InterfaceError, DatabaseError):

22
verse/editor.py

@ -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(

2
verse/statuspengguna/resetpassword.py

@ -20,7 +20,7 @@ from flask_bcrypt import generate_password_hash
from app import db from app import db
def ResetPassword(path): def ResetPassword(path):
linkvalid = False linkvalid = False
user = User.query.filter_by(resethash=path).first() user = User.query.filter_by(resethash=path).first()
if user is None: if user is None:

Loading…
Cancel
Save