From b9cc82b8f2a9d6b4ebd2eef39a5fb097c714109c Mon Sep 17 00:00:00 2001 From: crunk Date: Thu, 27 Jun 2024 11:03:35 +0200 Subject: [PATCH] descriptions added --- requirements.txt | 2 +- verse/describer/describe_files.py | 14 ++++++++++++- verse/distribusikan/add_files_to_describer.py | 8 ++++++++ verse/distribusikan/distribusi_selector.py | 4 +++- verse/migrations/env.py | 20 ++++++++++--------- verse/statuspengguna/helper.py | 4 +++- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4ce5362..374fc78 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@5934122c6ec1452d975b7cfe6582f9417fd5fdd0 +distribusi @ git+https://git.vvvvvvaria.org/crunk/distribusi@3eefd6e5ca7048555d441df8c6fbf4f2e255acac dnspython==2.1.0 email-validator==1.1.3 Flask==3.0.3 diff --git a/verse/describer/describe_files.py b/verse/describer/describe_files.py index 32ee77b..f53c329 100644 --- a/verse/describer/describe_files.py +++ b/verse/describer/describe_files.py @@ -78,6 +78,7 @@ def describe_file(file_id): ) save_described_file_to_db(describe_form, distribusi_file) add_alttext_to_file(describe_form, distribusi_file) + add_description_to_file(describe_form, distribusi_file) distribusi = Distribusis.query.filter_by( id=distribusi_file.distribusi ).first() @@ -143,6 +144,17 @@ def add_alttext_to_file(describe_form, distribusi_file): if not describe_form.alttext.data: return filename_no_ext = os.path.splitext(distribusi_file.path)[0] - with open(f'{filename_no_ext}_alttext.txt', 'w') as alttext_file: + with open(f"{filename_no_ext}_alttext.txt", "w") as alttext_file: alttext_file.write(describe_form.alttext.data) return + + +def add_description_to_file(describe_form, distribusi_file): + if not describe_form.description.data: + return + filename_no_ext = os.path.splitext(distribusi_file.path)[0] + with open( + f"{filename_no_ext}_dv_description.txt", "w" + ) as description_file: + description_file.write(describe_form.description.data) + return diff --git a/verse/distribusikan/add_files_to_describer.py b/verse/distribusikan/add_files_to_describer.py index 5310e90..6773279 100644 --- a/verse/distribusikan/add_files_to_describer.py +++ b/verse/distribusikan/add_files_to_describer.py @@ -31,6 +31,10 @@ def _get_distribusi_from_path(path): def _add_distribusi_file_to_db(distribusi, full_path, type): app = get_app() app.logger.info(f"adding file to database: {full_path} type: {type}") + distribusi_file = DistribusiFiles.query.filter_by(path=full_path).first() + if distribusi_file is not None: + app.logger.error(f"File already in database: {full_path}") + return try: new_distribusi_file = DistribusiFiles( path=full_path, @@ -63,6 +67,10 @@ def add_distribusi_files_to_db(path): for root, dirs, files in os.walk(path, topdown=True): files = list(filter(lambda f: not f.startswith("."), files)) files = list(filter(lambda f: not f.endswith(".html"), files)) + files = list(filter(lambda f: not f.endswith("_thumbnail.jpg"), files)) + files = list(filter(lambda f: not f.endswith("_alttext.txt"), files)) + files = list(filter(lambda f: not f.endswith("_dv_description.txt"), files)) + for file in files: full_path = os.path.join(root, file) distribusi_file = DistribusiFiles.query.filter_by( diff --git a/verse/distribusikan/distribusi_selector.py b/verse/distribusikan/distribusi_selector.py index f42bd2e..b47b227 100644 --- a/verse/distribusikan/distribusi_selector.py +++ b/verse/distribusikan/distribusi_selector.py @@ -42,7 +42,9 @@ def distribusi_selector(): if selectorform.update.data: select_update_distribusi(selectorform.distribusis.data) current_distribusi = UserHelper.current_distribusi() - uploadform = auto_fill_in_upload_form(uploadform, current_distribusi) + uploadform = auto_fill_in_upload_form( + uploadform, current_distribusi + ) return render_distribusi_template( selectorform, uploadform, current_distribusi diff --git a/verse/migrations/env.py b/verse/migrations/env.py index 68feded..68a0091 100644 --- a/verse/migrations/env.py +++ b/verse/migrations/env.py @@ -14,17 +14,19 @@ config = context.config # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) -logger = logging.getLogger('alembic.env') +logger = logging.getLogger("alembic.env") # add your model's MetaData object here # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata config.set_main_option( - 'sqlalchemy.url', - str(current_app.extensions['migrate'].db.get_engine().url).replace( - '%', '%%')) -target_metadata = current_app.extensions['migrate'].db.metadata + "sqlalchemy.url", + str(current_app.extensions["migrate"].db.get_engine().url).replace( + "%", "%%" + ), +) +target_metadata = current_app.extensions["migrate"].db.metadata # other values from the config, defined by the needs of env.py, # can be acquired: @@ -65,20 +67,20 @@ def run_migrations_online(): # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): - if getattr(config.cmd_opts, 'autogenerate', False): + if getattr(config.cmd_opts, "autogenerate", False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] - logger.info('No changes in schema detected.') + logger.info("No changes in schema detected.") - connectable = current_app.extensions['migrate'].db.get_engine() + connectable = current_app.extensions["migrate"].db.get_engine() with connectable.connect() as connection: context.configure( connection=connection, target_metadata=target_metadata, process_revision_directives=process_revision_directives, - **current_app.extensions['migrate'].configure_args + **current_app.extensions["migrate"].configure_args, ) with context.begin_transaction(): diff --git a/verse/statuspengguna/helper.py b/verse/statuspengguna/helper.py index 5605bd9..c227155 100644 --- a/verse/statuspengguna/helper.py +++ b/verse/statuspengguna/helper.py @@ -76,7 +76,9 @@ class UserHelper: def distribusi_limit_reached(): user = User.query.filter_by(email=current_user.email).first() - distribusiamount = len(DistribusisInfo.get_user_distribusis(user.email)) + distribusiamount = len( + DistribusisInfo.get_user_distribusis(user.email) + ) if distribusiamount > 19: print("user already has 20 distribusis") return True