Compare commits

...

2 Commits

Author SHA1 Message Date
Ruben van de Ven 45616df16d Secret key generation on the device instead of storing it in git 5 years ago
Ruben van de Ven 2a8903905e Add button to clear current score 5 years ago
  1. 2
      .gitignore
  2. 38
      contextualise.py
  3. 4
      static/css/main.css
  4. 1
      templates/layout.html

2
.gitignore

@ -0,0 +1,2 @@
secret.key

38
contextualise.py

@ -10,6 +10,8 @@ from PIL import Image, ImageDraw, ImageFont
import numpy as np import numpy as np
from itertools import zip_longest from itertools import zip_longest
import collections import collections
import random
import string
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
@ -41,22 +43,33 @@ pathofwords = []
pathofnumbers = [] pathofnumbers = []
#VARS FOR THE SESSIONS #VARS FOR THE SESSIONS
app.secret_key = 'your secret' # We don't want to store the secret key in git, but also don't really care what it is
app.config['SESSION_TYPE'] = 'filesystem' # so generate it and store it to a file that's not in git:
current_dir = os.path.dirname(os.path.realpath(__file__))
secret_key_file = os.path.join(current_dir, 'secret.key')
if os.path.exists(secret_key_file):
with open(secret_key_file, 'r') as fp:
secret_key = fp.read()
else:
secret_key = ''.join(random.choice(string.ascii_lowercase) for i in range(100))
with open(secret_key_file, 'w') as fp:
fp.write(secret_key)
app.secret_key = secret_key
#app.config['SESSION_TYPE'] = 'filesystem' # works only for flask-session (we use native flask cookie-sessions)
def setupSession(): def clearSession():
# session should be configured from within request context
# so this function should be called on each request
if 'wordpath' not in session:
# Flask sessions are serialised into a cookie, so we cannot use the deque here # Flask sessions are serialised into a cookie, so we cannot use the deque here
session['wordpath'] = [] session['wordpath'] = []
if 'clicktime' not in session:
session['clicktime'] = [] session['clicktime'] = []
if 'id' not in session:
session['id'] = [] session['id'] = []
if 'veryfirstnow' not in session:
session['veryfirstnow'] = datetime.now().isoformat() session['veryfirstnow'] = datetime.now().isoformat()
def setupSession():
# session should be configured from within request context
# so this function should be called on each request
if 'veryfirstnow' not in session:
clearSession()
# preparing the index.json file for the navbar # preparing the index.json file for the navbar
index_dict = {} index_dict = {}
@ -125,6 +138,13 @@ def about():
return render_template('about.html') return render_template('about.html')
@app.route('/clear')
def clear():
# return to a refer if its set, default to root
return_url = request.environ.get("HTTP_REFERER", '/')
clearSession()
return redirect(return_url)
# @app.route('/all/') # @app.route('/all/')
# def all(): # def all():
# thefile = listingfiles[positioninarray] # thefile = listingfiles[positioninarray]

4
static/css/main.css

@ -151,9 +151,9 @@ div.explanation{
header{ header{
/* border: lime 1px solid; */ /* border: lime 1px solid; */
padding-top: -1em; padding-top: -1em;
padding-right: 10em; margin-right: 10em;
position: absolute; position: absolute;
top:12em; top:17em;
width: 29em; width: 29em;
-webkit-transform-origin: 0 50%; -webkit-transform-origin: 0 50%;
-moz-transform-origin: 0 50%; -moz-transform-origin: 0 50%;

1
templates/layout.html

@ -13,6 +13,7 @@
<div id="top"> <div id="top">
<!-- WORDPATH --> <!-- WORDPATH -->
<div id="thewordpath"> <div id="thewordpath">
{% if functionsession %}[<a href='/clear' title='Clear current score'>x</a>]{% endif %}
{% for item in functionsession %} {% for item in functionsession %}
<span class="word">{{ item }} ▶ </span> <span class="word">{{ item }} ▶ </span>
{% endfor %} {% endfor %}

Loading…
Cancel
Save