Browse Source

new distribusi back end

main
crunk 5 days ago
parent
commit
4d0d5bd767
  1. 2
      requirements.txt
  2. 2
      verse/describer/templates/describe_files/describe.html
  3. 43
      verse/distribusikan/distribusi_selector.py
  4. 2
      verse/distribusikan/upload.py

2
requirements.txt

@ -8,7 +8,7 @@ bleach-allowlist==1.0.3
blinker==1.7.0 blinker==1.7.0
cffi cffi
click==8.1.7 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 dnspython==2.1.0
email-validator==1.1.3 email-validator==1.1.3
Flask==3.0.3 Flask==3.0.3

2
verse/describer/templates/describe_files/describe.html

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

43
verse/distribusikan/distribusi_selector.py

@ -18,6 +18,7 @@ from distribusikan.forms.selectorform import SelectorForm
from distribusikan.forms.themeform import ThemeForm from distribusikan.forms.themeform import ThemeForm
from distribusikan.forms.uploadform import UploadForm from distribusikan.forms.uploadform import UploadForm
from models.distribusi_model import Distribusis from models.distribusi_model import Distribusis
from models.distribusi_file_model import DistribusiFiles
from models.user_model import User from models.user_model import User
# UserPengguna # UserPengguna
@ -94,29 +95,43 @@ def delete_distribusi(distribusiname):
if distribusi.userid is user.id: if distribusi.userid is user.id:
db.session.delete(distribusi) db.session.delete(distribusi)
db.session.commit() 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?? # SelectField error is list is a tuple?? why??
# selectorform.distribusis.errors.append("Distribusi deleted!") # selectorform.distribusis.errors.append("Distribusi deleted!")
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
db.session.rollback() db.session.rollback()
# selectorform.distribusis.errors.append("Unknown error occured!") # selectorform.distribusis.errors.append("Unknown error occured!")
flash("An error occured !", "danger") flash("An error occured !", "danger")
_delete_distribusi_files(distribusi.distribusiname)
return selectorform 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): def select_current_distribusi(distribusiname):
if not current_user.is_authenticated: if not current_user.is_authenticated:
return return

2
verse/distribusikan/upload.py

@ -79,7 +79,7 @@ def upload_updates_files(uploadfolder):
db.session.commit() db.session.commit()
except (InvalidRequestError, DataError, InterfaceError, DatabaseError): except (InvalidRequestError, DataError, InterfaceError, DatabaseError):
db.session.rollback() 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) zipfilename = "{}.zip".format(distribusi.distribusiname)
zipfile = uploadform.zipfile.data zipfile = uploadform.zipfile.data

Loading…
Cancel
Save