"Basic menu management"

This commit is contained in:
Doug Le Tough 2017-11-25 21:06:17 +01:00
parent 9d723deb3a
commit d9ecf3bb5a
2 changed files with 46 additions and 49 deletions

View File

@ -3,7 +3,7 @@
<article class='right'> <article class='right'>
<h3>TODO list</h3> <h3>TODO list</h3>
<ul> <ul>
<li>Menu management</li> <li><strike>Basic menu management</strike></li>
<li>Installation wizard</li> <li>Installation wizard</li>
<li>Back office for basic content management</li> <li>Back office for basic content management</li>
<li>Basic Ajax support</li> <li>Basic Ajax support</li>

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 # -*- coding: utf-8
# Required modules # Required modules
import inspect
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
from functools import wraps from functools import wraps
@ -24,6 +25,32 @@ app.secret_key = 'ce1d1c9ff0ff388a838b3a1e3207dd27'
# Feel free to use SQLAlchemy (or not) # Feel free to use SQLAlchemy (or not)
db = SQLAlchemy(app) 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 # Routes
######################################################################## ########################################################################
@ -35,70 +62,40 @@ def page_not_found(e):
@app.route("/", methods=['GET', 'POST']) @app.route("/", methods=['GET', 'POST'])
def index(): def index():
app.menu = [('Accueil', '/', 1), page = inspect.currentframe().f_code.co_name
('Articles', '/articles', 0), menu = get_menu(page)
('Basics', '/basics', 0), return render_template('index.html', menu=menu)
('Inputs', '/inputs', 0),
('Database', '/database', 0),
('Todo', '/todo', 0),
]
return render_template('index.html', menu=app.menu)
@app.route("/articles", methods=['GET', 'POST']) @app.route("/articles", methods=['GET', 'POST'])
def articles(): def articles():
app.menu = [('Accueil', '/', 0), page = inspect.currentframe().f_code.co_name
('Articles', '/articles', 1), menu = get_menu(page)
('Basics', '/basics', 0), return render_template('articles.html', menu=menu)
('Inputs', '/inputs', 0),
('Database', '/database', 0),
('Todo', '/todo', 0),
]
return render_template('articles.html', menu=app.menu)
@app.route("/basics", methods=['GET', 'POST']) @app.route("/basics", methods=['GET', 'POST'])
def basics(): def basics():
app.menu = [('Accueil', '/', 0), page = inspect.currentframe().f_code.co_name
('Articles', '/articles', 0), menu = get_menu(page)
('Basics', '/basics', 1), return render_template('basics.html', menu=menu)
('Inputs', '/inputs', 0),
('Database', '/database', 0),
('Todo', '/todo', 0),
]
return render_template('basics.html', menu=app.menu)
@app.route("/inputs", methods=['GET', 'POST']) @app.route("/inputs", methods=['GET', 'POST'])
def inputs(): def inputs():
app.menu = [('Accueil', '/', 0), page = inspect.currentframe().f_code.co_name
('Articles', '/articles', 0), menu = get_menu(page)
('Basics', '/basics', 0), return render_template('inputs.html', menu=menu)
('Inputs', '/inputs', 1),
('Database', '/database', 0),
('Todo', '/todo', 0),
]
return render_template('inputs.html', menu=app.menu)
@app.route("/database", methods=['GET', 'POST']) @app.route("/database", methods=['GET', 'POST'])
def database(): def database():
app.menu = [('Accueil', '/', 0), page = inspect.currentframe().f_code.co_name
('Articles', '/articles', 0), menu = get_menu(page)
('Basics', '/basics', 0), return render_template('database.html', menu=menu)
('Inputs', '/inputs', 0),
('Database', '/database', 1),
('Todo', '/todo', 0),
]
return render_template('database.html', menu=app.menu)
@app.route("/todo", methods=['GET', 'POST']) @app.route("/todo", methods=['GET', 'POST'])
def todo(): def todo():
app.menu = [('Accueil', '/', 0), page = inspect.currentframe().f_code.co_name
('Articles', '/articles', 0), menu = get_menu(page)
('Basics', '/basics', 0), return render_template('todo.html', menu=menu)
('Inputs', '/inputs', 0),
('Database', '/database', 0),
('Todo', '/todo', 1),
]
return render_template('todo.html', menu=app.menu)