2022-01-05 13:42:24 +01:00
|
|
|
"""This is the main flask distribusi page"""
|
2024-04-21 20:44:08 +02:00
|
|
|
|
2022-01-05 18:14:45 +01:00
|
|
|
from datetime import timedelta
|
2024-04-21 20:44:08 +02:00
|
|
|
|
2024-05-27 13:29:30 +02:00
|
|
|
from flask import (
|
2024-05-28 23:02:17 +02:00
|
|
|
Blueprint,
|
|
|
|
redirect,
|
|
|
|
render_template,
|
|
|
|
send_from_directory,
|
|
|
|
session,
|
|
|
|
url_for,
|
2024-05-27 13:29:30 +02:00
|
|
|
)
|
2024-11-25 15:00:09 +01:00
|
|
|
from flask_login import login_required, logout_user
|
2024-04-24 23:05:36 +02:00
|
|
|
from flask_wtf.csrf import CSRFError
|
2024-04-28 13:04:07 +02:00
|
|
|
|
2024-06-02 22:37:55 +02:00
|
|
|
from admin import is_adminuser
|
|
|
|
from admin_page.admin_page import admin_page
|
2024-05-28 23:02:17 +02:00
|
|
|
from app import create_app, login_manager, db
|
2024-05-19 11:13:21 +02:00
|
|
|
from describer.describe_files import describer
|
2024-04-28 13:04:07 +02:00
|
|
|
from distribusikan.distribusikan import distribusikan
|
2024-06-17 22:36:23 +02:00
|
|
|
from distribusikan.distribusis_info import DistribusisInfo
|
2024-06-02 22:14:13 +02:00
|
|
|
from distribusikan.forms.uploadform import UploadForm
|
2024-04-28 15:34:29 +02:00
|
|
|
from models.distribusi_model import Distribusis
|
|
|
|
from models.user_model import User
|
2024-04-28 13:04:07 +02:00
|
|
|
from statuspengguna.forgotpassword import forgot_password
|
2022-03-28 20:16:34 +02:00
|
|
|
from statuspengguna.helper import UserHelper
|
2024-04-28 13:04:07 +02:00
|
|
|
from statuspengguna.loginuser import login_section
|
|
|
|
from statuspengguna.registeruser import register_user
|
2024-06-29 15:21:47 +02:00
|
|
|
from search.search import searchpages
|
|
|
|
from search.search_index import init_search_index
|
2022-02-12 19:44:44 +01:00
|
|
|
|
2022-01-05 13:42:24 +01:00
|
|
|
APP = create_app()
|
2022-03-25 11:24:49 +01:00
|
|
|
stash_page = Blueprint("stash_page", __name__, static_folder="stash")
|
2024-05-19 11:13:21 +02:00
|
|
|
APP.register_blueprint(stash_page)
|
2024-05-27 14:25:25 +02:00
|
|
|
APP.register_blueprint(describer, url_prefix="/describer")
|
2024-04-28 13:04:07 +02:00
|
|
|
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")
|
2024-06-17 22:36:23 +02:00
|
|
|
APP.register_blueprint(admin_page, url_prefix="/admin")
|
2024-06-23 16:59:51 +02:00
|
|
|
APP.register_blueprint(distribusikan, url_prefix="/distribusikan")
|
2024-06-29 15:21:47 +02:00
|
|
|
APP.register_blueprint(searchpages, url_prefix="/search")
|
|
|
|
init_search_index(APP)
|
2022-01-05 13:42:24 +01:00
|
|
|
|
2024-06-29 15:25:28 +02:00
|
|
|
|
2022-01-05 13:42:24 +01:00
|
|
|
@APP.before_request
|
|
|
|
def session_handler():
|
2024-05-28 23:02:17 +02:00
|
|
|
session.permanent = True
|
|
|
|
APP.permanent_session_lifetime = timedelta(minutes=30)
|
2022-01-05 13:42:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
@APP.route("/")
|
|
|
|
def index():
|
2024-05-28 23:02:17 +02:00
|
|
|
UserHelper.reset_user_state()
|
|
|
|
uploadform = UploadForm()
|
2024-06-17 22:36:23 +02:00
|
|
|
distribusis = DistribusisInfo.visible_distribusis()
|
2024-05-28 23:02:17 +02:00
|
|
|
distribusisindex = {}
|
|
|
|
for distribusi in distribusis:
|
|
|
|
user = User.query.filter_by(id=distribusi.userid).first()
|
|
|
|
singledistribusi = {
|
|
|
|
"username": user.username,
|
|
|
|
"publictheme": distribusi.publictheme,
|
|
|
|
"category": distribusi.category,
|
|
|
|
"year": distribusi.year,
|
|
|
|
"tags": distribusi.tags.split(","),
|
|
|
|
}
|
|
|
|
distribusisindex[distribusi.distribusiname] = singledistribusi
|
|
|
|
|
|
|
|
years = uploadform.year.choices
|
|
|
|
categories = uploadform.category.choices
|
|
|
|
adminuser = is_adminuser()
|
|
|
|
template = render_template(
|
|
|
|
"base/index.html",
|
|
|
|
distribusisindex=distribusisindex,
|
|
|
|
years=years,
|
|
|
|
categories=categories,
|
|
|
|
adminuser=adminuser,
|
|
|
|
)
|
|
|
|
return template
|
2022-01-05 13:42:24 +01:00
|
|
|
|
|
|
|
|
2022-03-27 12:46:08 +02:00
|
|
|
@APP.route("/help")
|
|
|
|
def help():
|
2024-05-28 23:02:17 +02:00
|
|
|
return render_template("base/help.html")
|
2022-01-05 13:42:24 +01:00
|
|
|
|
|
|
|
|
2022-03-28 18:33:48 +02:00
|
|
|
@APP.route("/publicthemes/<path>")
|
|
|
|
def publicthemes(path):
|
2024-05-28 23:02:17 +02:00
|
|
|
distribusi = Distribusis.query.filter_by(distribusiname=path).first()
|
|
|
|
publicthemefolder = f"publicthemes/{distribusi.distribusiname}/"
|
|
|
|
cssfile = f"{publicthemefolder}/{distribusi.publictheme}.css"
|
|
|
|
return send_from_directory("themes", cssfile, as_attachment=True)
|
2022-03-28 18:33:48 +02:00
|
|
|
|
|
|
|
|
2022-03-25 11:24:49 +01:00
|
|
|
@APP.route("/stash")
|
|
|
|
def shortstashurl():
|
2024-05-28 23:02:17 +02:00
|
|
|
return redirect(url_for("index"))
|
2022-01-07 18:09:29 +01:00
|
|
|
|
|
|
|
|
2022-01-05 13:42:24 +01:00
|
|
|
@APP.route("/logout")
|
|
|
|
@login_required
|
|
|
|
def logout():
|
2024-05-28 23:02:17 +02:00
|
|
|
logout_user()
|
|
|
|
return redirect(url_for("index"))
|
2022-01-05 13:42:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
@APP.errorhandler(CSRFError)
|
|
|
|
def handle_csrf_error(e):
|
2024-05-28 23:02:17 +02:00
|
|
|
return render_template("csrf_error.html", reason=e.description), 400
|
2022-01-05 13:42:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
@login_manager.user_loader
|
|
|
|
def load_user(user_id):
|
2024-05-28 23:02:17 +02:00
|
|
|
return db.session.get(User, int(user_id))
|
2022-01-05 13:42:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-05-28 23:02:17 +02:00
|
|
|
APP.debug = True
|
|
|
|
APP.run(port=5000)
|