diff --git a/tetawebapp/templates/todo.html b/tetawebapp/templates/todo.html
index 5c1629b..b432021 100644
--- a/tetawebapp/templates/todo.html
+++ b/tetawebapp/templates/todo.html
@@ -3,7 +3,7 @@
TODO list
- - Menu management
+ Basic menu management
- Installation wizard
- Back office for basic content management
- Basic Ajax support
diff --git a/tetawebapp/tetawebapp.py b/tetawebapp/tetawebapp.py
index 15a650a..8394307 100755
--- a/tetawebapp/tetawebapp.py
+++ b/tetawebapp/tetawebapp.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8
# Required modules
+import inspect
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
from functools import wraps
@@ -24,6 +25,32 @@ app.secret_key = 'ce1d1c9ff0ff388a838b3a1e3207dd27'
# Feel free to use SQLAlchemy (or not)
db = SQLAlchemy(app)
+########################################################################
+# Menu management
+########################################################################
+
+def get_menu(page):
+ menu = [['Accueil', '/', 0],
+ ['Articles', '/articles', 0],
+ ['Basics', '/basics', 0],
+ ['Inputs', '/inputs', 0],
+ ['Database', '/database', 0],
+ ['Todo', '/todo', 0],
+ ]
+ # This is index page
+ if page == 'index':
+ menu[0][2] = 1
+ return menu
+
+ # Let's look for the actual page
+ page = '/%s' % page
+ for item in menu:
+ if item[1] == page:
+ item[2] = 1
+ return menu
+ # This should never happen
+ return menu
+
########################################################################
# Routes
########################################################################
@@ -35,70 +62,40 @@ def page_not_found(e):
@app.route("/", methods=['GET', 'POST'])
def index():
- app.menu = [('Accueil', '/', 1),
- ('Articles', '/articles', 0),
- ('Basics', '/basics', 0),
- ('Inputs', '/inputs', 0),
- ('Database', '/database', 0),
- ('Todo', '/todo', 0),
- ]
- return render_template('index.html', menu=app.menu)
+ page = inspect.currentframe().f_code.co_name
+ menu = get_menu(page)
+ return render_template('index.html', menu=menu)
@app.route("/articles", methods=['GET', 'POST'])
def articles():
- app.menu = [('Accueil', '/', 0),
- ('Articles', '/articles', 1),
- ('Basics', '/basics', 0),
- ('Inputs', '/inputs', 0),
- ('Database', '/database', 0),
- ('Todo', '/todo', 0),
- ]
- return render_template('articles.html', menu=app.menu)
+ page = inspect.currentframe().f_code.co_name
+ menu = get_menu(page)
+ return render_template('articles.html', menu=menu)
@app.route("/basics", methods=['GET', 'POST'])
def basics():
- app.menu = [('Accueil', '/', 0),
- ('Articles', '/articles', 0),
- ('Basics', '/basics', 1),
- ('Inputs', '/inputs', 0),
- ('Database', '/database', 0),
- ('Todo', '/todo', 0),
- ]
- return render_template('basics.html', menu=app.menu)
+ page = inspect.currentframe().f_code.co_name
+ menu = get_menu(page)
+ return render_template('basics.html', menu=menu)
@app.route("/inputs", methods=['GET', 'POST'])
def inputs():
- app.menu = [('Accueil', '/', 0),
- ('Articles', '/articles', 0),
- ('Basics', '/basics', 0),
- ('Inputs', '/inputs', 1),
- ('Database', '/database', 0),
- ('Todo', '/todo', 0),
- ]
- return render_template('inputs.html', menu=app.menu)
+ page = inspect.currentframe().f_code.co_name
+ menu = get_menu(page)
+ return render_template('inputs.html', menu=menu)
@app.route("/database", methods=['GET', 'POST'])
def database():
- app.menu = [('Accueil', '/', 0),
- ('Articles', '/articles', 0),
- ('Basics', '/basics', 0),
- ('Inputs', '/inputs', 0),
- ('Database', '/database', 1),
- ('Todo', '/todo', 0),
- ]
- return render_template('database.html', menu=app.menu)
+ page = inspect.currentframe().f_code.co_name
+ menu = get_menu(page)
+ return render_template('database.html', menu=menu)
@app.route("/todo", methods=['GET', 'POST'])
def todo():
- app.menu = [('Accueil', '/', 0),
- ('Articles', '/articles', 0),
- ('Basics', '/basics', 0),
- ('Inputs', '/inputs', 0),
- ('Database', '/database', 0),
- ('Todo', '/todo', 1),
- ]
- return render_template('todo.html', menu=app.menu)
+ page = inspect.currentframe().f_code.co_name
+ menu = get_menu(page)
+ return render_template('todo.html', menu=menu)