diff --git a/ExampleApp/Wrappers.py b/ExampleApp/Wrappers.py deleted file mode 100644 index b1c3ea57db5e5e607b49dd2c544213e1343bc3e6..0000000000000000000000000000000000000000 --- a/ExampleApp/Wrappers.py +++ /dev/null @@ -1,14 +0,0 @@ -from flask import redirect as _redirect, url_for, render_template, g, session -from functools import wraps -#from samsHUB import app - -def login_required(f): - @wraps(f) - def decorated_function(*args, **kwargs): - #app.secret_key = 'berry' - if not 'name' in session: - return _redirect('/login') - - return f(*args, **kwargs) - - return decorated_function \ No newline at end of file diff --git a/ExampleApp/__init__.py b/ExampleApp/__init__.py index e7acfa05e7a9da864e4b16b385efba4e12e0768f..40b19cf83669d17636603edc46c3bf34729d3bb2 100644 --- a/ExampleApp/__init__.py +++ b/ExampleApp/__init__.py @@ -1,22 +1,34 @@ #from .sams_classes import SAMSHub import yaml, os, glob +from sams_classes import SAMSHub, SAMSApp -# with open('config/config.yaml', 'r') as f: -# hubConf = yaml.load(f.read()) -# hub = SAMSHub(config=hubConf.get( -# 'ExampleApp', -# { 'default_language': 'en', 'main_app': 'Main'} -# )) -# hub.flaskApp.config.update(hubConf.get('flask', {})) -# for appName in hubConf.get('apps', []): -# with open('../' + appName + '/manifest.yaml') as f: -# manifest = yaml.load(f.read()) -# # it is possible for the exampleApp to manipulate the manifest if needed -# # manifest.update({}) <-- or whatever -# hub.addApp(SAMSApp(name = appName, manifest = manifest, langDict = langDict)) +def create_hub(): + with open('ExampleApp/config/config.yaml', 'r') as f: + hubConf = yaml.load(f.read()) + hub = SAMSHub(name='main', config=hubConf.get('ExampleApp', + { 'default_language': 'en', 'main_app': 'Main'})) + hub.flaskApp.config.update(hubConf.get('flask', {})) + for appName in hubConf.get('apps', []): + with open('ExampleApp/' + appName + '/manifest.yaml') as f: + manifest = yaml.load(f.read()) + langDict = {'en': {}} + for yaml_file in search_yaml_files('ExampleApp' + '/' + appName + '/lang/'): + with open(yaml_file) as f: + singleLang = yaml.load(f.read) + langDict.update( + {os.path.splitext(os.path.basename(yaml_file))[0]: singleLang}) + hub.addApp(SAMSApp(name = appName, manifest = manifest, langDict = langDict)) + return hub -def search_yaml_files(path): +def search_yaml_files(path, exts = ['.yaml', '.yml']): matchingFiles = [] - extensions = ['.yaml', '.yml'] - for path in glob.glob(path + '*.yaml'): - print(path + '\n') \ No newline at end of file + for ext in exts: + for path in glob.glob(path + '*' + ext): + if os.path.isfile(path): + matchingFiles.append(path) + return matchingFiles + +if __name__ == '__main__': + create_hub() +else: + hub = create_hub() \ No newline at end of file diff --git a/ExampleApp/config/config.yaml b/ExampleApp/config/config.yaml index cedca4eb7d0b13e3f5162730a7945e288abb1fc6..d23457659c1d690d29423bfdd55311c0b63a1bf4 100644 --- a/ExampleApp/config/config.yaml +++ b/ExampleApp/config/config.yaml @@ -1,4 +1,9 @@ -DEBUG: true -jinja2_strict_undefined: true -#samsHUB: -# module_base_path: /modules/ # default \ No newline at end of file +flask: + DEBUG: true + jinja2_strict_undefined: true +samsHUB: + default_language: de + apps: + - ExampleApp.Main + - ExampleApp.Extra + main_app: ExampleApp.Main \ No newline at end of file diff --git a/ExampleApp/config/modules.yaml b/ExampleApp/config/modules.yaml deleted file mode 100644 index 9026aee8525dd846759bcb3e7153f28b6cda3316..0000000000000000000000000000000000000000 --- a/ExampleApp/config/modules.yaml +++ /dev/null @@ -1 +0,0 @@ -- hallo_module \ No newline at end of file diff --git a/ExampleApp/exceptions.py b/ExampleApp/exceptions.py deleted file mode 100644 index cd79d076fd80efc40b9f2ba45d4e83c698225e33..0000000000000000000000000000000000000000 --- a/ExampleApp/exceptions.py +++ /dev/null @@ -1,7 +0,0 @@ -class NoDefaultLanguage(Exception): - """Raised when the DefaultLanguage of a Module, specified in the manifest.yaml - has no corresponding language file in modules/<modulename>/languages/ - or if hub default language is not correctly configured - """ - def __init__(self, expression = None): - self.expression = expression \ No newline at end of file diff --git a/ExampleApp/languages/de.yaml b/ExampleApp/languages/de.yaml deleted file mode 100644 index 9436996629f6744ca4ab2bf43432786322ffdee4..0000000000000000000000000000000000000000 --- a/ExampleApp/languages/de.yaml +++ /dev/null @@ -1,5 +0,0 @@ -home_title: 'Startseite' -home_wellcome_message: 'Willkommen im samsHUB' -zid_long: '<b>Z</b>IB <b>I</b>nformations <b>D</b>atenbank' -username: Benutzername -password: Kennwort \ No newline at end of file diff --git a/ExampleApp/manifest.yaml b/ExampleApp/manifest.yaml deleted file mode 100644 index 4388a4c70f86b48a2ac3d78f42e09c567bcf107b..0000000000000000000000000000000000000000 --- a/ExampleApp/manifest.yaml +++ /dev/null @@ -1,7 +0,0 @@ -default_language: de -views: - - url: / - name_var: main_name #entspricht nicht dem default module_name -# subviews: -# - url: /subview -# name_var: subview_name \ No newline at end of file diff --git a/ExampleApp/modules/.gitkeep b/ExampleApp/modules/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/ExampleApp/modules/hallo_module/__init__.py b/ExampleApp/modules/hallo_module/__init__.py deleted file mode 100644 index d618f33478627299914fae598f9c1dcd8b13776e..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ -from flask_microservices import Router -from . import urls -from samsHUB.functions import get_enabled_modules - -MODULE_NAME = 'hallo_module' -IMPORT_NAME = __name__ - -# These blueprints are what is collected when you run app.register_urls() -blueprint = Router.create_blueprint(MODULE_NAME, IMPORT_NAME) -#blueprint.register_urls(urls.urlpatterns) diff --git a/ExampleApp/modules/hallo_module/languages/de.yaml b/ExampleApp/modules/hallo_module/languages/de.yaml deleted file mode 100644 index 2bf8e11a289d6696d3721f0b488aa108bea46c40..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/languages/de.yaml +++ /dev/null @@ -1,11 +0,0 @@ -module_title: &module_title Hallo Modul -module_name: *module_title -hallo module: >- - Hallo Modul! -beschreibung: >- - Eine Beshreibung zu was auch immer das 'hallo module' macht. -teststring: Ein Teststring -subview_description: >- - Dies ist ein Subview des Hallo Moduls. Das Modul kann vile weitere Subviews - haben, aber dieses ist bietet die Möglichkeit über ein Menü im SAMShub - erreichbar zu sein. \ No newline at end of file diff --git a/ExampleApp/modules/hallo_module/languages/en.yaml b/ExampleApp/modules/hallo_module/languages/en.yaml deleted file mode 100644 index 183dfa168cf1134c5f8e368e22aafcbcecee77f4..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/languages/en.yaml +++ /dev/null @@ -1,13 +0,0 @@ -module_title: &module_title Hello Module -module_name: *module_title -hallo module: >- - Hello Module! -beschreibung: >- - This is the description of what ever this 'hello module' does. -teststring: A Teststring -subview_title: Subview -subview_name: Subentry -subviews_description: >- - This is a Subview of the 'hello module'. The Module may use much more subviews, - but this one is potentialy reachable in a menu of the SAMAShub. -home_string: Start \ No newline at end of file diff --git a/ExampleApp/modules/hallo_module/manifest.yaml b/ExampleApp/modules/hallo_module/manifest.yaml deleted file mode 100644 index 2c42a28f10d5b0821474378822f67a6b3f779709..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/manifest.yaml +++ /dev/null @@ -1,13 +0,0 @@ -default_language: en -views: - - url: &hallo-module /modules/hallo-module - view_func: views.hallo_module -menu: - - url: *hallo-module - name_string: module_title - submenu: - - url: /modules/hallo-module/subview - name_string: subview_name - subviews: - - url: / - name_string: home_string diff --git a/ExampleApp/modules/hallo_module/templates/hallo_module.html b/ExampleApp/modules/hallo_module/templates/hallo_module.html deleted file mode 100644 index d615d8ae827842f3e30af76ea80a7d78b0c76f55..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/templates/hallo_module.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "base-struct.html" %} -{% block title %}Index{% endblock %} -{% block head %} {{ super() }} {% endblock %} -{% block content %} - <h1> {{ mod_lang['hallo module'] }}</h1> - <p> {{ mod_lang['beschreibung'] }}</p> -{% endblock %} -{% block header %}samsHUB {{ mod_lang['teststring'] }} {% endblock %} \ No newline at end of file diff --git a/ExampleApp/modules/hallo_module/templates/subview.html b/ExampleApp/modules/hallo_module/templates/subview.html deleted file mode 100644 index 5fc6dd156cfea254c265de4f69d8b5d6e6bafef3..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/templates/subview.html +++ /dev/null @@ -1,8 +0,0 @@ -{% extends "base-struct.html" %} -{% block title %}Index{% endblock %} -{% block head %} {{ super() }} {% endblock %} -{% block content %} - <h1> {{ mod_lang['hallo module'] }} - {{ mod_lang['subview_title'] }}</h1> - <p> {{ mod_lang['subview_description'] }}</p> -{% endblock %} -{% block header %}samsHUB {{ mod_lang['teststring'] }} {% endblock %} \ No newline at end of file diff --git a/ExampleApp/modules/hallo_module/urls.py b/ExampleApp/modules/hallo_module/urls.py deleted file mode 100644 index 73a3142234cb47a650b249d4ddbbe6bba014fcd3..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/urls.py +++ /dev/null @@ -1,9 +0,0 @@ -from flask_microservices import url -from . import views - -urlpatterns = [ - url('/modules/hallo-module', view_func=views.hallo_module, name='hallo_module') - , url( - '/modules/hallo-module/subview', view_func=views.subview - , name='hallo_module_subview') -] \ No newline at end of file diff --git a/ExampleApp/modules/hallo_module/views.py b/ExampleApp/modules/hallo_module/views.py deleted file mode 100644 index 0aa456264197e8a13db64712aebaeb1c9b51bb31..0000000000000000000000000000000000000000 --- a/ExampleApp/modules/hallo_module/views.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import render_template - - -def hallo_module(): - return render_template('hallo_module.html') -def subview(): - return render_template('subview.html') \ No newline at end of file diff --git a/ExampleApp/views.py b/ExampleApp/views.py deleted file mode 100644 index 5409b76cfc14cb6e3471e8f2e4ece8bb7abd58f9..0000000000000000000000000000000000000000 --- a/ExampleApp/views.py +++ /dev/null @@ -1,13 +0,0 @@ -from flask import render_template, session, redirect -from samsHUB.Wrappers import login_required - -@login_required -def home(): - return render_template('home.html') - -def login(): - return render_template('login.html') - -def login_post(): - session['name'] = 'Platzhalter Name' - return redirect('/') \ No newline at end of file diff --git a/example_app.py b/example_app.py index e77d90a2ca952a9cb8779694101b831a322f275d..b16b114fa26a8ff340ddea8a3896f3368482d549 100644 --- a/example_app.py +++ b/example_app.py @@ -1,3 +1,3 @@ -from .ExampleApp import hub +from ExampleApp import hub hub.flaskApp.run() \ No newline at end of file diff --git a/old-stuff/app.py b/old-stuff/app.py deleted file mode 100644 index 99f3b5351d38269fe8a64589892800569421068a..0000000000000000000000000000000000000000 --- a/old-stuff/app.py +++ /dev/null @@ -1,4 +0,0 @@ -from ExampleApp import search_yaml_files - -# hub.flaskApp.run() -search_yaml_files('./ExampleApp/config/') \ No newline at end of file