|
|
@ -18,6 +18,7 @@ from distribusikan.forms.selectorform import SelectorForm |
|
|
|
from distribusikan.forms.themeform import ThemeForm |
|
|
|
from distribusikan.forms.uploadform import UploadForm |
|
|
|
from models.distribusi_model import Distribusis |
|
|
|
from models.distribusi_file_model import DistribusiFiles |
|
|
|
from models.user_model import User |
|
|
|
|
|
|
|
# UserPengguna |
|
|
@ -94,29 +95,43 @@ def delete_distribusi(distribusiname): |
|
|
|
if distribusi.userid is user.id: |
|
|
|
db.session.delete(distribusi) |
|
|
|
db.session.commit() |
|
|
|
userfolder = os.path.join("stash", distribusi.distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
shutil.rmtree(userfolder) |
|
|
|
cssfolder = os.path.join( |
|
|
|
"themes/userthemes", distribusi.distribusiname |
|
|
|
) |
|
|
|
if os.path.exists(cssfolder): |
|
|
|
shutil.rmtree(cssfolder) |
|
|
|
if distribusi.publictheme is not None: |
|
|
|
publicthemefolder = os.path.join( |
|
|
|
"themes/publicthemes", distribusi.distribusiname |
|
|
|
) |
|
|
|
if os.path.exists(publicthemefolder): |
|
|
|
shutil.rmtree(publicthemefolder) |
|
|
|
# SelectField error is list is a tuple?? why?? |
|
|
|
# selectorform.distribusis.errors.append("Distribusi deleted!") |
|
|
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): |
|
|
|
db.session.rollback() |
|
|
|
# selectorform.distribusis.errors.append("Unknown error occured!") |
|
|
|
flash("An error occured !", "danger") |
|
|
|
_delete_distribusi_files(distribusi.distribusiname) |
|
|
|
return selectorform |
|
|
|
|
|
|
|
|
|
|
|
def _delete_distribusi_files(distribusiname): |
|
|
|
userfolder = os.path.join("stash", distribusiname) |
|
|
|
if os.path.exists(userfolder): |
|
|
|
shutil.rmtree(userfolder) |
|
|
|
cssfolder = os.path.join("themes/userthemes", distribusiname) |
|
|
|
if os.path.exists(cssfolder): |
|
|
|
shutil.rmtree(cssfolder) |
|
|
|
if distribusi.publictheme is not None: |
|
|
|
publicthemefolder = os.path.join("themes/publicthemes", distribusiname) |
|
|
|
if os.path.exists(publicthemefolder): |
|
|
|
shutil.rmtree(publicthemefolder) |
|
|
|
|
|
|
|
|
|
|
|
def _delete_distribusi_database_files(distribusiname): |
|
|
|
try: |
|
|
|
distribusi = Distribusis.query.filter_by( |
|
|
|
distribusiname=distribusiname |
|
|
|
).first() |
|
|
|
distribusi_db_files = DistribusiFiles.query.filter_by( |
|
|
|
distribusi=distribusi |
|
|
|
) |
|
|
|
db.session.delete(distribusi_db_files) |
|
|
|
db.session.commit() |
|
|
|
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): |
|
|
|
db.session.rollback() |
|
|
|
|
|
|
|
|
|
|
|
def select_current_distribusi(distribusiname): |
|
|
|
if not current_user.is_authenticated: |
|
|
|
return |
|
|
|