Skip to content
Browse files

Redirect from /setup-first to / with flash message. Add support for a…

…pp.secret_key
  • Loading branch information...
1 parent b57d079 commit 3d656b719a80ebe0d896e43edcb14f3aefdbeb60 @jonasb jonasb committed Oct 24, 2011
Showing with 39 additions and 2 deletions.
  1. +2 −0 .gitignore
  2. +18 −0 README.md
  3. +9 −2 mugshots.py
  4. +10 −0 templates/index.html
View
2 .gitignore
@@ -0,0 +1,2 @@
+dump.rdb
+secret_key.txt
View
18 README.md
@@ -13,6 +13,24 @@ Python, Flask, Redis
Now using a template and a CSS and a favicon, and Jinja template language.
+Start by e.g.
+
+ python mugshots.py
+
+## Setup
+
+Initialize the secret key
+
+ head -c 24 /dev/random | base64 > secret_key.txt
+
+Open the page `/setup-first` to populate the database.
+
+## Redis
+
+Run this command in `redis-cli` to reset the database:
+
+ flushdb
+
## Reporting
The primary feature is the /report.
View
11 mugshots.py
@@ -1,15 +1,18 @@
import flask
-from flask import Flask, g, abort, redirect, url_for, request, render_template
+from flask import Flask, g, abort, flash, redirect, url_for, request, render_template
import flaskext.redis
import datetime
app = Flask(__name__)
+with open('secret_key.txt') as f:
+ app.secret_key = f.read()
+
db = flaskext.redis.init_redis(app)
@app.route("/setup-first")
-def hello():
+def setup_first():
"""Set up a starting dataset.
"""
circles = [
@@ -38,6 +41,10 @@ def hello():
db.save()
+ flash('First! Database is go \'enna!')
+
+ return redirect(url_for('index'))
+
@app.route('/')
def index():
"""GUI to state which people are in attendance tonight.
View
10 templates/index.html
@@ -8,6 +8,16 @@
<script type=text/javascript src={{ url_for('static', filename='forsk.js') }}></script>
</head>
<body>
+ {% with messages = get_flashed_messages() %}
+ {% if messages %}
+ <div id=flash>
+ {% for message in messages %}
+ <p>{{ message }}</p>
+ {% endfor %}
+ </div>
+ {% endif %}
+ {% endwith %}
+
<h1 id="heading">Forskningsavdelningen: Studiecirklar</h1>
<h2>Vad gör personen i afton?</h2>

0 comments on commit 3d656b7

Please sign in to comment.
Something went wrong with that request. Please try again.