settings toml file
This commit is contained in:
parent
963b33f170
commit
9e3bb6605f
27
verse/app.py
27
verse/app.py
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import tomllib
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask_bcrypt import Bcrypt
|
from flask_bcrypt import Bcrypt
|
||||||
@ -7,6 +8,7 @@ from flask_migrate import Migrate
|
|||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from flask_wtf.csrf import CSRFProtect
|
from flask_wtf.csrf import CSRFProtect
|
||||||
|
|
||||||
|
APP = Flask(__name__, static_folder="static")
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
migrate = Migrate()
|
migrate = Migrate()
|
||||||
bcrypt = Bcrypt()
|
bcrypt = Bcrypt()
|
||||||
@ -14,8 +16,6 @@ login_manager = LoginManager()
|
|||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
APP = Flask(__name__, static_folder="static")
|
|
||||||
|
|
||||||
APP.secret_key = "secret-key"
|
APP.secret_key = "secret-key"
|
||||||
APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/distribusiverse.db"
|
APP.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/distribusiverse.db"
|
||||||
APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
|
APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
|
||||||
@ -37,10 +37,33 @@ def create_app():
|
|||||||
APP.config["UPLOAD_FOLDER"] = "tmpupload"
|
APP.config["UPLOAD_FOLDER"] = "tmpupload"
|
||||||
APP.config["PUBLIC_THEMES"] = "themes/publicthemes"
|
APP.config["PUBLIC_THEMES"] = "themes/publicthemes"
|
||||||
|
|
||||||
|
# user settings_file
|
||||||
|
settings()
|
||||||
|
|
||||||
csrf.init_app(APP)
|
csrf.init_app(APP)
|
||||||
login_manager.init_app(APP)
|
login_manager.init_app(APP)
|
||||||
db.init_app(APP)
|
db.init_app(APP)
|
||||||
migrate.init_app(APP, db, render_as_batch=True)
|
migrate.init_app(APP, db, render_as_batch=True)
|
||||||
bcrypt.init_app(APP)
|
bcrypt.init_app(APP)
|
||||||
|
|
||||||
|
@APP.context_processor
|
||||||
|
def inject_title():
|
||||||
|
return dict(title=APP.config["title"])
|
||||||
|
|
||||||
return APP
|
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)
|
||||||
|
@ -5,20 +5,30 @@ from wtforms import (IntegerField, SelectField, StringField, SubmitField,
|
|||||||
from wtforms.validators import (DataRequired, Length, NumberRange,
|
from wtforms.validators import (DataRequired, Length, NumberRange,
|
||||||
ValidationError)
|
ValidationError)
|
||||||
|
|
||||||
|
from app import settings
|
||||||
|
|
||||||
|
|
||||||
class UploadForm(FlaskForm):
|
class UploadForm(FlaskForm):
|
||||||
"""File upload class for a new site in distribusi-verse"""
|
"""File upload class for a new site in distribusi-verse"""
|
||||||
|
|
||||||
def _distribusiname(form, field):
|
def distribusiname(form, field):
|
||||||
if field.data.lower() == "new":
|
if field.data.lower() == "new":
|
||||||
raise ValidationError("Name has to be unique and not just 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(
|
sitename = StringField(
|
||||||
"Name of your archive section:",
|
"Name of your archive section:",
|
||||||
validators=[
|
validators=[
|
||||||
validators.InputRequired(),
|
validators.InputRequired(),
|
||||||
Length(2, 100),
|
Length(2, 100),
|
||||||
_distribusiname,
|
distribusiname,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
year = SelectField(
|
year = SelectField(
|
||||||
@ -43,14 +53,7 @@ class UploadForm(FlaskForm):
|
|||||||
"Category:",
|
"Category:",
|
||||||
validate_choice=True,
|
validate_choice=True,
|
||||||
coerce=str,
|
coerce=str,
|
||||||
choices=[
|
choices=category_choices,
|
||||||
("event", "event"),
|
|
||||||
("gathering", "gathering"),
|
|
||||||
("work session", "work session"),
|
|
||||||
("workgroup", "workgroup"),
|
|
||||||
("performance", "performance"),
|
|
||||||
("music event", "music event"),
|
|
||||||
],
|
|
||||||
option_widget=None,
|
option_widget=None,
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()],
|
||||||
)
|
)
|
||||||
|
4
verse/settings.toml
Normal file
4
verse/settings.toml
Normal 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
|
@ -84,8 +84,7 @@ def distribusi():
|
|||||||
@APP.route("/upload", methods=["POST"])
|
@APP.route("/upload", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def upload():
|
def upload():
|
||||||
uploadfolder = APP.config["UPLOAD_FOLDER"]
|
return UploadPage()
|
||||||
return UploadPage(uploadfolder)
|
|
||||||
|
|
||||||
|
|
||||||
@APP.route("/theme", methods=["GET", "POST"])
|
@APP.route("/theme", methods=["GET", "POST"])
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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/style.css')}}">
|
||||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/selector.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') }}">
|
<link rel="shortcut icon" href="{{ url_for('static', filename='icons/favicon.ico') }}">
|
||||||
|
@ -8,11 +8,13 @@ from forms.selectorform import SelectorForm
|
|||||||
from forms.themeform import ThemeForm
|
from forms.themeform import ThemeForm
|
||||||
# UserPengguna
|
# UserPengguna
|
||||||
from statuspengguna.helper import UserHelper
|
from statuspengguna.helper import UserHelper
|
||||||
|
from app import APP
|
||||||
from upload import UploadNewDistribusi, UploadUpdatedFiles
|
from upload import UploadNewDistribusi, UploadUpdatedFiles
|
||||||
|
|
||||||
|
|
||||||
def UploadPage(uploadfolder):
|
def UploadPage():
|
||||||
"render upload page section of distribusi workflow"
|
"render upload page section of distribusi workflow"
|
||||||
|
uploadfolder = APP.config["UPLOAD_FOLDER"]
|
||||||
distribusiform = DistribusiForm()
|
distribusiform = DistribusiForm()
|
||||||
themeform = ThemeForm()
|
themeform = ThemeForm()
|
||||||
publicthemeform = PublicThemeForm()
|
publicthemeform = PublicThemeForm()
|
||||||
|
Loading…
Reference in New Issue
Block a user