From 4d0d5bd767e31ff767ca79e2ca814d7b5e978781 Mon Sep 17 00:00:00 2001 From: crunk Date: Mon, 25 Nov 2024 21:21:31 +0100 Subject: [PATCH] new distribusi back end --- requirements.txt | 2 +- .../templates/describe_files/describe.html | 2 +- verse/distribusikan/distribusi_selector.py | 43 +++++++++++++------ verse/distribusikan/upload.py | 2 +- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/requirements.txt b/requirements.txt index 374fc78..fcfbe55 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ bleach-allowlist==1.0.3 blinker==1.7.0 cffi click==8.1.7 -distribusi @ git+https://git.vvvvvvaria.org/crunk/distribusi@3eefd6e5ca7048555d441df8c6fbf4f2e255acac +distribusi @ git+https://git.vvvvvvaria.org/crunk/distribusi@4654ced5e8dfe803b62bc6163fa3d88a73a9010a dnspython==2.1.0 email-validator==1.1.3 Flask==3.0.3 diff --git a/verse/describer/templates/describe_files/describe.html b/verse/describer/templates/describe_files/describe.html index 473400d..599ce3d 100644 --- a/verse/describer/templates/describe_files/describe.html +++ b/verse/describer/templates/describe_files/describe.html @@ -31,7 +31,7 @@ {% for id, describe_form in distribusi_file_forms.items() %}
{% if describe_form.type == "image" %} - + {% elif describe_form.type == "video" %} {% elif describe_form.type == "audio" %} diff --git a/verse/distribusikan/distribusi_selector.py b/verse/distribusikan/distribusi_selector.py index b47b227..2021ba2 100644 --- a/verse/distribusikan/distribusi_selector.py +++ b/verse/distribusikan/distribusi_selector.py @@ -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 diff --git a/verse/distribusikan/upload.py b/verse/distribusikan/upload.py index b81e3e6..0bc63fe 100644 --- a/verse/distribusikan/upload.py +++ b/verse/distribusikan/upload.py @@ -79,7 +79,7 @@ def upload_updates_files(uploadfolder): db.session.commit() except (InvalidRequestError, DataError, InterfaceError, DatabaseError): db.session.rollback() - uploadform.sitename.errors.append("Something went wrong!") + uploadform.sitename.errors.append("Something went wrong with the database!") zipfilename = "{}.zip".format(distribusi.distribusiname) zipfile = uploadform.zipfile.data