Browse Source

settings toml file

pull/11/head
crunk 7 months ago
parent
commit
9e3bb6605f
  1. 27
      verse/app.py
  2. 23
      verse/forms/uploadform.py
  3. 4
      verse/settings.toml
  4. 3
      verse/start.py
  5. 2
      verse/templates/base.html
  6. 4
      verse/uploadpage.py

27
verse/app.py

@ -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)

23
verse/forms/uploadform.py

@ -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

@ -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

3
verse/start.py

@ -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"])

2
verse/templates/base.html

@ -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') }}">

4
verse/uploadpage.py

@ -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()

Loading…
Cancel
Save