new distribusi back end

This commit is contained in:
crunk 2024-11-25 21:21:31 +01:00
parent 4c420a7f57
commit 4d0d5bd767
4 changed files with 32 additions and 17 deletions

View File

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

View File

@ -31,7 +31,7 @@
{% for id, describe_form in distribusi_file_forms.items() %}
<div class="distribusi_file">
{% if describe_form.type == "image" %}
<img src="{{ url_for('shortstashurl')}}/{{describe_form.file_paths}}" alt="" data-src="{{ url_for('shortstashurl')}}/{{describe_form.file_path}}" loading="lazy"/>
<img src="{{ url_for('shortstashurl')}}/{{describe_form.file_path}}" alt="" data-src="{{ url_for('shortstashurl')}}/{{describe_form.file_path}}" loading="lazy"/>
{% elif describe_form.type == "video" %}
<video src="{{ url_for('shortstashurl')}}/{{describe_form.file_path}}" preload="auto" alt="" controls loading="lazy"></video>
{% elif describe_form.type == "audio" %}

View File

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

View File

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