Skip to content
Snippets Groups Projects
Commit 3f2c8014 authored by Sebastian Lobinger's avatar Sebastian Lobinger
Browse files

file structiure cleanup , implementing base structure for Exampleapp

parent 38254939
Branches
Tags
1 merge request!10Resolve "Example App schreiben"
Showing
with 39 additions and 152 deletions
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
#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
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
- hallo_module
\ No newline at end of file
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
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
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
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)
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
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
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
{% 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
{% 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
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
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
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
from .ExampleApp import hub
from ExampleApp import hub
hub.flaskApp.run()
\ No newline at end of file
from ExampleApp import search_yaml_files
# hub.flaskApp.run()
search_yaml_files('./ExampleApp/config/')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment