delete old uploaded files

This commit is contained in:
crunk 2022-03-19 20:16:00 +01:00
parent a11a263878
commit a877dcd617
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import os import os
from flask import render_template
import bleach import bleach
import shutil
from flask import render_template
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from sqlalchemy.exc import ( from sqlalchemy.exc import (
DataError, DataError,
@ -38,9 +40,11 @@ def Editor():
def ValidateEditCssForm(editorform, current_distribusi): def ValidateEditCssForm(editorform, current_distribusi):
newcssfolder = os.path.join("themes/userthemes", current_distribusi) newcssfolder = os.path.join("themes/userthemes", current_distribusi)
shutil.rmtree(newcssfolder)
publicfolder = os.path.join("themes/publicthemes", current_distribusi)
shutil.rmtree(publicfolder)
if editorform.public.data: if editorform.public.data:
MakePublicTheme(editorform, current_distribusi) MakePublicTheme(editorform, current_distribusi)
publicfolder = os.path.join("themes/publicthemes", current_distribusi)
if editorform.cssfile.data: if editorform.cssfile.data:
SaveUploadCssFile(editorform, publicfolder) SaveUploadCssFile(editorform, publicfolder)
else: else:

View File

@ -146,7 +146,8 @@ def distribusi():
distribusify(args, userfolder) distribusify(args, userfolder)
distribusi.visible = True distribusi.visible = True
user.currentdistribusi = None user.currentdistribusi = None
os.remove(cssfile) if os.path.exists(cssfile):
os.remove(cssfile)
db.session.commit() db.session.commit()
return redirect(url_for("index")) return redirect(url_for("index"))
template = render_template( template = render_template(