settings toml file

This commit is contained in:
crunk 2024-04-22 20:34:33 +02:00
parent 963b33f170
commit 9e3bb6605f
6 changed files with 47 additions and 16 deletions

View File

@ -1,4 +1,5 @@
import os
import tomllib
from flask import Flask
from flask_bcrypt import Bcrypt
@ -7,6 +8,7 @@ from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy
from flask_wtf.csrf import CSRFProtect
APP = Flask(__name__, static_folder="static")
db = SQLAlchemy()
migrate = Migrate()
bcrypt = Bcrypt()
@ -14,8 +16,6 @@ login_manager = LoginManager()
def create_app():
APP = Flask(__name__, static_folder="static")
APP.secret_key = "secret-key"
APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/distribusiverse.db"
APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
@ -37,10 +37,33 @@ def create_app():
APP.config["UPLOAD_FOLDER"] = "tmpupload"
APP.config["PUBLIC_THEMES"] = "themes/publicthemes"
# user settings_file
settings()
csrf.init_app(APP)
login_manager.init_app(APP)
db.init_app(APP)
migrate.init_app(APP, db, render_as_batch=True)
bcrypt.init_app(APP)
@APP.context_processor
def inject_title():
return dict(title=APP.config["title"])
return APP
def settings():
settings = settings_from_file()
APP.config.update(settings)
return APP
def settings_from_file():
settings = {}
if os.path.isfile("settings_development.toml"):
with open("settings_development.toml", "rb") as settings_file:
return tomllib.load(settings_file)
with open("settings.toml", "rb") as settings_file:
return tomllib.load(settings_file)

View File

@ -5,20 +5,30 @@ from wtforms import (IntegerField, SelectField, StringField, SubmitField,
from wtforms.validators import (DataRequired, Length, NumberRange,
ValidationError)
from app import settings
class UploadForm(FlaskForm):
"""File upload class for a new site in distribusi-verse"""
def _distribusiname(form, field):
def distribusiname(form, field):
if field.data.lower() == "new":
raise ValidationError("Name has to be unique and not just new.")
def category_choices():
APP = settings()
config_categories = APP.config["categories"]
categories = []
for config_category in config_categories:
categories.append((config_category, config_category))
return categories
sitename = StringField(
"Name of your archive section:",
validators=[
validators.InputRequired(),
Length(2, 100),
_distribusiname,
distribusiname,
],
)
year = SelectField(
@ -43,14 +53,7 @@ class UploadForm(FlaskForm):
"Category:",
validate_choice=True,
coerce=str,
choices=[
("event", "event"),
("gathering", "gathering"),
("work session", "work session"),
("workgroup", "workgroup"),
("performance", "performance"),
("music event", "music event"),
],
choices=category_choices,
option_widget=None,
validators=[DataRequired()],
)

4
verse/settings.toml Normal file
View File

@ -0,0 +1,4 @@
title = "Varia Archive X Distribusi-Verse"
categories = ["event","gathering","work session","workgroup","performance","music event"]
start_time = 2017-11-03
end_time = 2024-12-31

View File

@ -84,8 +84,7 @@ def distribusi():
@APP.route("/upload", methods=["POST"])
@login_required
def upload():
uploadfolder = APP.config["UPLOAD_FOLDER"]
return UploadPage(uploadfolder)
return UploadPage()
@APP.route("/theme", methods=["GET", "POST"])

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Varia Archive X Distribusi-Verse</title>
<title>{{title}}</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css')}}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/selector.css')}}">
<link rel="shortcut icon" href="{{ url_for('static', filename='icons/favicon.ico') }}">

View File

@ -8,11 +8,13 @@ from forms.selectorform import SelectorForm
from forms.themeform import ThemeForm
# UserPengguna
from statuspengguna.helper import UserHelper
from app import APP
from upload import UploadNewDistribusi, UploadUpdatedFiles
def UploadPage(uploadfolder):
def UploadPage():
"render upload page section of distribusi workflow"
uploadfolder = APP.config["UPLOAD_FOLDER"]
distribusiform = DistribusiForm()
themeform = ThemeForm()
publicthemeform = PublicThemeForm()