From ff8215a7deaf0a5e41da761c2013d3551fa303ec Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 19 May 2024 11:13:21 +0200 Subject: [PATCH] selector redirects to wip file describer page --- verse/describer/describe_files.py | 22 ++++++++++++ verse/describer/templates/describe.html | 2 -- .../templates/describe_files/describe.html | 34 ++++++++++++++++++ verse/distribusikan/distribusiselector.py | 17 +++++++-- .../distribusiworkflow/selector.html | 7 ++++ verse/file_crawler.py | 2 +- verse/forms/selectorform.py | 2 ++ verse/migrations/versions/8ede45e978d9_.py | 36 ------------------- verse/models/distribusi_file_model.py | 2 +- verse/start.py | 19 ++++------ 10 files changed, 89 insertions(+), 54 deletions(-) create mode 100644 verse/describer/describe_files.py delete mode 100644 verse/describer/templates/describe.html create mode 100644 verse/describer/templates/describe_files/describe.html delete mode 100644 verse/migrations/versions/8ede45e978d9_.py diff --git a/verse/describer/describe_files.py b/verse/describer/describe_files.py new file mode 100644 index 0000000..ac41c4d --- /dev/null +++ b/verse/describer/describe_files.py @@ -0,0 +1,22 @@ +from flask import Blueprint, render_template +from models.distribusi_model import Distribusis +from models.distribusi_file_model import DistribusiFiles + +describer = Blueprint( + "describer", + __name__, + template_folder="templates/describe_files", + static_folder="static", +) + + +@describer.route("/") +def describe_distribusi_files(distribusiname): + distribusi = Distribusis.query.filter_by( + distribusiname=distribusiname + ).first() + distribusi_files = DistribusiFiles.query.filter_by( + distribusi=distribusi.id + ).all() + print(distribusi_files) + return render_template("describe.html", distribusi_files=distribusi_files) diff --git a/verse/describer/templates/describe.html b/verse/describer/templates/describe.html deleted file mode 100644 index fc36ba4..0000000 --- a/verse/describer/templates/describe.html +++ /dev/null @@ -1,2 +0,0 @@ -{% extends "base/base.html" %} -{% block main %} diff --git a/verse/describer/templates/describe_files/describe.html b/verse/describer/templates/describe_files/describe.html new file mode 100644 index 0000000..700d154 --- /dev/null +++ b/verse/describer/templates/describe_files/describe.html @@ -0,0 +1,34 @@ +{% extends "base/base.html" %} +{% block main %} +
+ {% if current_user.is_authenticated %} +
+ + + +
+ {% if adminuser %} +
+ + + +
+ {% endif %} +
+ + + +
+ {% endif %} +
+ + + +
+
+
+ {% for file in distribusi_files %} +

{{file}}

+ {% endfor%} +
+{% endblock %} diff --git a/verse/distribusikan/distribusiselector.py b/verse/distribusikan/distribusiselector.py index ccc5770..2ceb8fc 100644 --- a/verse/distribusikan/distribusiselector.py +++ b/verse/distribusikan/distribusiselector.py @@ -1,7 +1,7 @@ import os import shutil -from flask import flash, render_template +from flask import flash, render_template, redirect, url_for from flask_login import current_user from sqlalchemy.exc import ( DatabaseError, @@ -10,8 +10,9 @@ from sqlalchemy.exc import ( InvalidRequestError, ) -from app import db +from app import db, get_app from distribusikan.distribusisinfo import DistribusisInfo +from describer.describe_files import describe_distribusi_files from forms.distribusiform import DistribusiForm from forms.publicthemeform import PublicThemeForm from forms.selectorform import SelectorForm @@ -32,6 +33,8 @@ def DistribusiSelector(): if selectorform.validate_on_submit(): if selectorform.new.data: SelectNewDistribusi() + if selectorform.describe.data: + return SelectDescribeDistribusi(selectorform.distribusis.data) if selectorform.delete.data: selectorform = DeleteDistribusi(selectorform.distribusis.data) selectorform.distribusis.choices = ( @@ -64,6 +67,16 @@ def SelectNewDistribusi(): SelectCurrentDistribusi("new") +def SelectDescribeDistribusi(distribusiname): + app = get_app + return redirect( + url_for( + "describer.describe_distribusi_files", + distribusiname=distribusiname, + ) + ) + + def SelectUpdateDistribusi(distribusiname): print(f"Update this distribusi {distribusiname}") SelectCurrentDistribusi(distribusiname) diff --git a/verse/distribusikan/templates/distribusikan/distribusiworkflow/selector.html b/verse/distribusikan/templates/distribusikan/distribusiworkflow/selector.html index 88dac97..6c95a0b 100644 --- a/verse/distribusikan/templates/distribusikan/distribusiworkflow/selector.html +++ b/verse/distribusikan/templates/distribusikan/distribusiworkflow/selector.html @@ -18,6 +18,13 @@ {{ selectorform.update }}
+

+ Describe your distribusi files. Add description texts, tags for search + or add alt-text for images

+
+ {{ selectorform.describe }} +
+

This will delete your distribusi site. This action cannot be undone! diff --git a/verse/file_crawler.py b/verse/file_crawler.py index 4ff054b..0a38280 100644 --- a/verse/file_crawler.py +++ b/verse/file_crawler.py @@ -43,7 +43,7 @@ def _add_distribusi_file_to_db(distribusi, full_path, type): app.logger.error("Something went wrong!") except IntegrityError: db.session.rollback() - app.logger.error("file %s already exists!", full_path) + app.logger.error("File %s already exists!", full_path) except DataError: db.session.rollback() app.logger.error("%s Invalid Entry", full_path) diff --git a/verse/forms/selectorform.py b/verse/forms/selectorform.py index d726971..f2f9530 100644 --- a/verse/forms/selectorform.py +++ b/verse/forms/selectorform.py @@ -9,4 +9,6 @@ class SelectorForm(FlaskForm): update = SubmitField("update") + describe = SubmitField("describe") + delete = SubmitField("delete") diff --git a/verse/migrations/versions/8ede45e978d9_.py b/verse/migrations/versions/8ede45e978d9_.py deleted file mode 100644 index 2bdb676..0000000 --- a/verse/migrations/versions/8ede45e978d9_.py +++ /dev/null @@ -1,36 +0,0 @@ -"""empty message - -Revision ID: 8ede45e978d9 -Revises: -Create Date: 2024-04-30 22:15:48.023060 - -""" -from alembic import op -import sqlalchemy as sa - - -# revision identifiers, used by Alembic. -revision = '8ede45e978d9' -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('distribusi_files', schema=None) as batch_op: - batch_op.alter_column('type', - existing_type=sa.VARCHAR(length=300), - nullable=True) - - # ### end Alembic commands ### - - -def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - with op.batch_alter_table('distribusi_files', schema=None) as batch_op: - batch_op.alter_column('type', - existing_type=sa.VARCHAR(length=300), - nullable=False) - - # ### end Alembic commands ### diff --git a/verse/models/distribusi_file_model.py b/verse/models/distribusi_file_model.py index 5e3f5ac..23003b1 100644 --- a/verse/models/distribusi_file_model.py +++ b/verse/models/distribusi_file_model.py @@ -15,4 +15,4 @@ class DistribusiFiles(db.Model): description = db.Column(db.String(4096), nullable=True, unique=False) def __repr__(self): - return "" % self.distribusiname + return "" % self.path diff --git a/verse/start.py b/verse/start.py index 5cbe8c5..33be140 100644 --- a/verse/start.py +++ b/verse/start.py @@ -2,25 +2,17 @@ from datetime import timedelta -from flask import ( - Blueprint, - redirect, - render_template, - send_from_directory, - session, - url_for, -) +from flask import (Blueprint, redirect, render_template, send_from_directory, + session, url_for) from flask_login import current_user, login_required, logout_user from flask_mail import Mail from flask_wtf.csrf import CSRFError -# Interface! these are seperate files in main folder from adminpage import AdminPage from app import create_app, login_manager +from describer.describe_files import describer from distribusikan.distribusikan import distribusikan from distribusikan.distribusisinfo import DistribusisInfo - -# Use upload form to populate filters from forms.uploadform import UploadForm from models.distribusi_model import Distribusis from models.user_model import User @@ -31,11 +23,14 @@ from statuspengguna.registeruser import register_user APP = create_app() stash_page = Blueprint("stash_page", __name__, static_folder="stash") +APP.register_blueprint(stash_page) + +APP.register_blueprint(describer, url_prefix="/describe") APP.register_blueprint(login_section, url_prefix="/login") APP.register_blueprint(register_user, url_prefix="/register") APP.register_blueprint(forgot_password, url_prefix="/login/forgotpassword") APP.register_blueprint(distribusikan) -APP.register_blueprint(stash_page) + @APP.before_request