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
)
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??
# selectorform.distribusis.errors.append("Distribusi deleted!")
except (InvalidRequestError, DataError, InterfaceError, DatabaseError):

22
verse/editor.py

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

2
verse/statuspengguna/resetpassword.py

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

Loading…
Cancel
Save