Some initial menu and translation work
This commit is contained in:
@@ -1,16 +1,30 @@
|
|||||||
from applets.software import bp
|
from applets.software import bp
|
||||||
from flask import Flask, request, session, redirect, \
|
from flask import Flask, request, session, redirect, \
|
||||||
url_for, render_template, flash, Blueprint
|
url_for, render_template, flash, Blueprint
|
||||||
|
import gettext
|
||||||
# we use this neat little trick to get config data from the main app
|
# we use this neat little trick to get config data from the main app
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
|
||||||
|
# Set up Gettext
|
||||||
|
def set_language(LANG):
|
||||||
|
"""
|
||||||
|
Sets language for this applet
|
||||||
|
"""
|
||||||
|
translations = gettext.translation("users", './applets/users/locales', fallback=True, languages=[LANG])
|
||||||
|
translations.install()
|
||||||
|
_ = translations.gettext
|
||||||
|
|
||||||
|
set_language('')
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/users')
|
@bp.route('/users')
|
||||||
def users_root():
|
def users_root():
|
||||||
"""
|
"""
|
||||||
Users screen for the webui.
|
Users screen for the webui.
|
||||||
"""
|
"""
|
||||||
|
set_language(current_app.config['CONFIG']['settings']['language'])
|
||||||
string_dict = build_stringlist()
|
string_dict = build_stringlist()
|
||||||
|
build_menu()
|
||||||
return render_template('users.html', string_dict=string_dict)
|
return render_template('users.html', string_dict=string_dict)
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +33,7 @@ def build_stringlist():
|
|||||||
Return all the strings that is used in this applet.
|
Return all the strings that is used in this applet.
|
||||||
"""
|
"""
|
||||||
string_dict = {}
|
string_dict = {}
|
||||||
|
string_dict['menu_item'] = _("Users")
|
||||||
string_dict['initial_user_text'] = _("Let's set up an initial user.")
|
string_dict['initial_user_text'] = _("Let's set up an initial user.")
|
||||||
string_dict['full_name'] = _("Full Name")
|
string_dict['full_name'] = _("Full Name")
|
||||||
string_dict['user_name'] = _("Username")
|
string_dict['user_name'] = _("Username")
|
||||||
@@ -31,3 +46,11 @@ def build_stringlist():
|
|||||||
string_dict['password_nomatch'] = _("These passwords do now match")
|
string_dict['password_nomatch'] = _("These passwords do now match")
|
||||||
string_dict['password_tooshort'] = _("This password is too short")
|
string_dict['password_tooshort'] = _("This password is too short")
|
||||||
return string_dict
|
return string_dict
|
||||||
|
|
||||||
|
def build_menu():
|
||||||
|
"""
|
||||||
|
Define menu items and paths.
|
||||||
|
"""
|
||||||
|
current_app.config['CONFIG']['settings']['menu']['users'] = (build_stringlist()['menu_item'], "/users", 20)
|
||||||
|
print(current_app.config['CONFIG']['settings']['menu'])
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,3 @@ bp = Blueprint('welcome', __name__,
|
|||||||
template_folder='')
|
template_folder='')
|
||||||
|
|
||||||
from applets.welcome import routes
|
from applets.welcome import routes
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ def set_language(LANG):
|
|||||||
translations.install()
|
translations.install()
|
||||||
_ = translations.gettext
|
_ = translations.gettext
|
||||||
|
|
||||||
set_language('en')
|
|
||||||
|
|
||||||
@bp.route('/welcome',methods=['GET', 'POST', 'PUT'])
|
@bp.route('/welcome',methods=['GET', 'POST', 'PUT'])
|
||||||
def welcome_index():
|
def welcome_index():
|
||||||
@@ -23,19 +22,21 @@ def welcome_index():
|
|||||||
The page you'd get if you access the root of
|
The page you'd get if you access the root of
|
||||||
this app in a browser.
|
this app in a browser.
|
||||||
"""
|
"""
|
||||||
|
set_language(current_app.config['CONFIG']['settings']['language'])
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if "lang" in request.form.keys():
|
if "lang" in request.form.keys():
|
||||||
current_app.config['CONFIG']['global_settings']['language'] = request.form["lang"]
|
current_app.config['CONFIG']['settings']['language'] = request.form["lang"]
|
||||||
LANG = current_app.config['CONFIG']['global_settings']['language']
|
LANG = current_app.config['CONFIG']['settings']['language']
|
||||||
set_language(LANG)
|
set_language(LANG)
|
||||||
FORMLANG = request.form["lang"]
|
FORMLANG = request.form["lang"]
|
||||||
if "keyboard" in request.form.keys():
|
if "keyboard" in request.form.keys():
|
||||||
print(request.form["keyboard"])
|
print(request.form["keyboard"])
|
||||||
if "timezone" in request.form.keys():
|
if "timezone" in request.form.keys():
|
||||||
print(request.form["timezone"])
|
print(request.form["timezone"])
|
||||||
lang = current_app.config['CONFIG']['global_settings']['language']
|
lang = current_app.config['CONFIG']['settings']['language']
|
||||||
blkid = lsblk.list_scsi_devices()
|
blkid = lsblk.list_scsi_devices()
|
||||||
string_dict = build_stringlist()
|
string_dict = build_stringlist()
|
||||||
|
build_menu()
|
||||||
return render_template('welcome.html', string_dict=string_dict, selected_lang=lang)
|
return render_template('welcome.html', string_dict=string_dict, selected_lang=lang)
|
||||||
|
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ def build_stringlist():
|
|||||||
Return all the strings that is used in this applet."
|
Return all the strings that is used in this applet."
|
||||||
"""
|
"""
|
||||||
string_dict = {}
|
string_dict = {}
|
||||||
|
string_dict['menu_item'] = _("Welcome")
|
||||||
string_dict['welcome_text'] = _("Welcome! This setup program will install Debian on to your system.")
|
string_dict['welcome_text'] = _("Welcome! This setup program will install Debian on to your system.")
|
||||||
string_dict['confirm_text'] = _("Please confirm the following details:")
|
string_dict['confirm_text'] = _("Please confirm the following details:")
|
||||||
string_dict['language_text'] = _("Language:")
|
string_dict['language_text'] = _("Language:")
|
||||||
@@ -58,3 +60,12 @@ def build_stringlist():
|
|||||||
string_dict['lang_list'] = lang_dict
|
string_dict['lang_list'] = lang_dict
|
||||||
return string_dict
|
return string_dict
|
||||||
|
|
||||||
|
def build_menu():
|
||||||
|
"""
|
||||||
|
Define menu items and paths.
|
||||||
|
"""
|
||||||
|
print(current_app.config['CONFIG']['settings']['menu'])
|
||||||
|
print(build_stringlist()['menu_item'])
|
||||||
|
current_app.config['CONFIG']['settings']['menu']['welcome'] = (build_stringlist()['menu_item'], "/welcome", 10)
|
||||||
|
|
||||||
|
set_language(current_app.config['CONFIG']['settings']['language'])
|
||||||
|
|||||||
@@ -12,29 +12,26 @@ import importlib
|
|||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
# configuration
|
# configuration
|
||||||
VERSION = "0.00"
|
|
||||||
SECRET_KEY = "exampls"
|
|
||||||
DEV_MODE = True
|
|
||||||
APPS = "main welcome users disks software summary"
|
|
||||||
CONFIGFILE="templates/dmm-installer-template.yaml"
|
CONFIGFILE="templates/dmm-installer-template.yaml"
|
||||||
|
|
||||||
if DEV_MODE:
|
|
||||||
print("Note: Starting in devmode!")
|
|
||||||
DEBUG = True
|
|
||||||
tracebacks = True
|
|
||||||
|
|
||||||
# import config
|
# import config
|
||||||
global config
|
global config
|
||||||
config_contents = open(CONFIGFILE, "r")
|
config_contents = open(CONFIGFILE, "r")
|
||||||
config = yaml.safe_load(config_contents)
|
config = yaml.safe_load(config_contents)
|
||||||
|
APPS = config['settings']['apps']
|
||||||
print(type(config))
|
DEV_MODE = config['settings']['devmode']
|
||||||
print(config)
|
|
||||||
|
|
||||||
# create our application in flask
|
# create our application in flask
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(__name__)
|
app.config.from_object(__name__)
|
||||||
app.config['CONFIG'] = config
|
app.config['CONFIG'] = config
|
||||||
|
app.app_context().push()
|
||||||
|
config['settings']['menu'] = {}
|
||||||
|
|
||||||
|
if DEV_MODE:
|
||||||
|
print("Note: Starting in devmode!")
|
||||||
|
DEBUG = True
|
||||||
|
tracebacks = True
|
||||||
|
|
||||||
# Register blueprints here
|
# Register blueprints here
|
||||||
for APP in APPS.split(" "):
|
for APP in APPS.split(" "):
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
module_path:
|
module_path:
|
||||||
- local
|
- local
|
||||||
|
|
||||||
global_settings:
|
settings:
|
||||||
language: en
|
language: en
|
||||||
|
devmode: True
|
||||||
apt_depends: util-linux adduser parted e2fsprogs debootstrap
|
apt_depends: util-linux adduser parted e2fsprogs debootstrap
|
||||||
|
apps: main welcome users disks software summary
|
||||||
|
|
||||||
recipe:
|
recipe:
|
||||||
Install some packages:
|
Install some packages:
|
||||||
|
|||||||
Reference in New Issue
Block a user