Skip to content
Snippets Groups Projects
Commit 0cc2e906 authored by slobinger's avatar slobinger
Browse files

Merge branch '11-write-example-app' into 'master'

Resolve "Example App schreiben"

Closes #11

See merge request !10
parents a8e10463 577d6239
No related branches found
No related tags found
1 merge request!10Resolve "Example App schreiben"
Showing
with 138 additions and 5 deletions
from flask import render_template
def home():
return render_template('extra_home.html')
\ No newline at end of file
hello_message: 'Hello extra page!'
men_index: 'Extra page'
\ No newline at end of file
default_language: 'en'
views:
- url: &index_url ''
function: 'home'
menu:
- url: *index_url
name_string: men_index
\ No newline at end of file
body {
width:100%;
height:300px;
background:#fff;
}
#global_app_menu {
background:#ccc;
}
#content {
background:#eee;
}
#header {
background:#aaa;
}
#footer {
background:#ccc;
}
\ No newline at end of file
{% extends "base-struct.html" %}
{% block title %}Index{% endblock %}
{% block head %} {{ super() }} {% endblock %}
{% block head %} {{ super() }}
<link rel="stylesheet" href="/ExampleApp.Extra/static/extra-style.css" />
{% endblock %}
{% block content %}
<h1> {{ mod_lang['hallo module'] }} - {{ mod_lang['subview_title'] }}</h1>
<p> {{ mod_lang['subview_description'] }}</p>
<h1>Extra</h1>
<p>samsHub Startseite: {{ app_lang['hello_message'] }}</p>
{% endblock %}
{% block header %}samsHUB {{ mod_lang['teststring'] }} {% endblock %}
\ No newline at end of file
{% block header %}samsHUB -{% endblock %}
\ No newline at end of file
from flask import render_template, session, request
def home():
print(session.get('language'))
return render_template('home.html')
def change_lang():
if request.args.get('lang'):
session['language'] = request.args.get('lang')
print('session language: {0}, request lang {1}'.format(
session['language'], request.args.get('lang')) )
return render_template('change_language.html')
\ No newline at end of file
hello_message: 'Hallo Startseite!'
men_index: 'Startseite'
men_index_repo_link: 'Gitlab Repo'
change_lang_german: 'Deutsch'
change_lang_english: 'Englisch'
men_change_lang: 'Sprache ändern'
\ No newline at end of file
hello_message: 'Hello Home!'
men_index: 'Home'
men_index_repo_link: 'Gitlab Repo'
change_lang_german: 'German'
change_lang_english: 'English'
men_change_lang: 'Change language'
\ No newline at end of file
default_language: 'de'
views:
- url: &index_url ''
function: 'home'
- url: &change_lang_url 'change-lang'
function: 'change_lang'
menu:
- url: *change_lang_url
name_string: 'men_change_lang'
- url: *index_url
name_string: men_index
menu:
- url: 'https://git.imp.fu-berlin.de/slobinger/sams-classes'
external: true
name_string: men_index_repo_link
\ No newline at end of file
......@@ -2,7 +2,8 @@
{% block title %}Index{% endblock %}
{% block head %} {{ super() }} {% endblock %}
{% block content %}
<h1>Home</h1>
<p>samsHub Startseite: {{ hub_lang['home_wellcome_message']|safe }}</p>
<h1>{{ app_lang['change_lang_title'] }}</h1>
<a href='/change-lang?lang=en'>{{ app_lang['change_lang_english'] }}</a>
<a href='/change-lang?lang=de'>{{ app_lang['change_lang_german'] }}</a>
{% endblock %}
{% block header %}samsHUB -{% endblock %}
\ No newline at end of file
import yaml, os, glob
from sams_classes import SAMSHub, SAMSApp
from flask import Flask
def create_hub():
with open('ExampleApp/config/config.yaml', 'r') as f:
hubConf = yaml.load(f.read())
hub = SAMSHub(name= __name__, config=hubConf['exampleApp'])
hub.flaskApp.config.update(hubConf.get('flask', {}))
for appName in hubConf['apps']:
with open(appName.replace('.', '/') + '/manifest.yaml') as f:
manifest = yaml.load(f.read())
langDict = {'en': {}}
for yaml_file in search_yaml_files(appName.replace('.', '/') + '/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, exts = ['.yaml', '.yml']):
matchingFiles = []
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
flask:
DEBUG: true
jinja2_strict_undefined: true
exampleApp:
default_language: de
main_app: 'ExampleApp.Main'
apps:
- 'ExampleApp.Main'
- 'ExampleApp.Extra'
\ No newline at end of file
File moved
......@@ -8,7 +8,7 @@ body {
}
#content {
background:#cff;
background:#fcf;
}
#header {
......
......@@ -10,10 +10,10 @@
<div id="header">{% block header %}{% endblock %}</div>
<div id="global_app_menu">
<ul>
{% for entry in menu_list recursive%}
{% for entry in menu recursive%}
<li><a href='{{ entry.url }}'>{{ entry.name }}</a></li>
{% if entry.subentries %}
<ul class="submenu">{{ loop(entry.subentries) }}</ul>
{% if entry.menu %}
<ul class="submenu">{{ loop(entry.menu) }}</ul>
{% endif %}
{% endfor %}
</ul>
......
......@@ -3,6 +3,6 @@
{% block head %} {{ super() }} {% endblock %}
{% block content %}
<h1>Home</h1>
<p>samsHub Startseite: {{ hub_lang['home_wellcome_message']|safe }}</p>
<p>samsHub Startseite: {{ app_lang['hello_message'] }}</p>
{% endblock %}
{% block header %}samsHUB -{% endblock %}
\ 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