aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--famille.py16
-rw-r--r--templates/user/edit.html6
2 files changed, 17 insertions, 5 deletions
diff --git a/famille.py b/famille.py
index 203bc23..47e98ea 100644
--- a/famille.py
+++ b/famille.py
@@ -5,6 +5,8 @@ from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash, _app_ctx_stack
from functools import wraps
import hashlib
+from pytz import timezone
+import pytz
from docutils import core
from docutils.writers.html4css1 import Writer
from datetime import datetime
@@ -36,7 +38,7 @@ def format_date(date_object, format=u"%a %d %b %Y à %Hh%M"):
if not date_object:
return ""
format = format.encode("utf8")
- return date_object.strftime(format).decode("utf8")
+ return date_object.replace(tzinfo=timezone('utc')).astimezone(timezone(session['timezone'])).strftime(format).decode("utf8")
@app.template_filter('pluralize')
def pluralize(word, count, plural=None):
@@ -61,6 +63,7 @@ def before_request():
detect_types=sqlite3.PARSE_DECLTYPES)
conn.row_factory = sqlite3.Row
g.db = conn
+ g.timezone = pytz.common_timezones
@app.teardown_appcontext
def close_db_connection(exception):
@@ -118,7 +121,8 @@ def add_news():
@app.route('/news/<int:news_id>/', methods=['GET', 'POST'])
@login_required
def show_news(news_id):
- news = query_db("SELECT * FROM news LEFT JOIN users ON news.user_id = users.id "
+ news = query_db("SELECT * FROM news LEFT JOIN users "
+ "ON news.user_id = users.id "
"WHERE news.id = ?", (news_id,), True)
if request.method == 'GET':
comments = query_db("SELECT * FROM comments LEFT JOIN users "
@@ -132,7 +136,8 @@ def show_news(news_id):
content_cache = rstify(content)
g.db.execute("INSERT INTO comments "
"('user_id', 'content', 'news_id', 'content_cache') "
- "VALUES (?, ?, ?, ?)", (user_id, content, news_id, content_cache))
+ "VALUES (?, ?, ?, ?)",
+ (user_id, content, news_id, content_cache))
g.db.commit()
return redirect(url_for('show_news', news_id=news_id))
@@ -180,7 +185,7 @@ def edit_user():
pass
args = tuple(request.form[key].encode("utf8") for key in \
['email', 'phone', 'birthday', 'nameday', 'address_line1', \
- 'address_line2', 'address_city_line'])
+ 'address_line2', 'address_city_line', 'timezone'])
args += ("notify" in request.form, session['user_id'])
sqlstr = "UPDATE users SET email= ?, phone=?, birthday=?, nameday=?," \
"address_line1=?, address_line2=?, address_city_line=?, notify=? " \
@@ -203,8 +208,9 @@ def login():
if user['password'] == password:
session['user_name'] = user['user_name']
session['user_id'] = user['id']
+ session['timezone'] = user['timezone']
g.db.execute("UPDATE users SET last_seen=? WHERE id=?",
- (datetime.utcnow(),session['user_id']))
+ (datetime.utcnow(),session['user_id']))
g.db.commit()
return redirect(url_for('list_news'))
else:
diff --git a/templates/user/edit.html b/templates/user/edit.html
index b85f7b2..9f51c2a 100644
--- a/templates/user/edit.html
+++ b/templates/user/edit.html
@@ -41,6 +41,12 @@
<label for="city_line">Ville, CP <span class="info">(dernière ligne)</span> :</label>
<input type="text" id="city_line" size="30" name="address_city_line" value="{{user.address_city_line}}"/><br />
+<label for="timezone">Timezone:</label>
+<select>
+{% for timezone in g.timezone %}
+<option {%if timezone==session.timezone %}select {% endif %}>{{timezone}}</option>
+{% endfor %}
+</select>
</p>
</fieldset>