aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2012-11-09 21:55:15 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2012-11-09 21:57:23 -0500
commit1ae302ff76adcb188dad5383e73c5ade158ffd8a (patch)
treee0b9c5f532c94efff272cfd3fafde81d494d0b91
parent735bcbe949faea7818fc6f90fcdf47f485715b5a (diff)
downloadfamille-flask-1ae302ff76adcb188dad5383e73c5ade158ffd8a.tar.gz
Stop insanity with timestamps
still need to check the function which imports the old database
-rw-r--r--createdb.py8
-rw-r--r--famille.py10
-rw-r--r--schema.sql7
3 files changed, 11 insertions, 14 deletions
diff --git a/createdb.py b/createdb.py
index 7f50807..7ec9cd0 100644
--- a/createdb.py
+++ b/createdb.py
@@ -9,9 +9,7 @@ if __name__ == "__main__":
required=True)
args = arg_parser.parse_args()
- conn = sqlite3.connect(args.database)
- c = conn.cursor()
+ conn = sqlite3.connect(args.database, detect_types=sqlite3.PARSE_DECLTYPES)
schema = open(args.schema)
- c.executescript( schema.read() )
- conn.commit()
- c.close()
+ conn.executescript( schema.read() )
+ conn.close()
diff --git a/famille.py b/famille.py
index f289508..efb30f7 100644
--- a/famille.py
+++ b/famille.py
@@ -28,11 +28,10 @@ def shortify(string):
return string
@app.template_filter('format_date')
-def format_date(datetime_string, format=u"%a %d %b %Y à %Hh%M".encode("utf8")):
- if not datetime_string:
+def format_date(date_object, format=u"%a %d %b %Y à %Hh%M".encode("utf8")):
+ if not date_object:
return ""
- return datetime.strptime(datetime_string[:-1],
- "%Y-%m-%dT%H:%M:%S").strftime(format).decode("utf8")
+ return date_object.strftime(format).decode("utf8")
@app.template_filter('pluralize')
def pluralize(word, count, plural=None):
@@ -190,8 +189,7 @@ def login():
session['user_name'] = user['user_name']
session['user_id'] = user['id']
g.db.execute("UPDATE users SET last_seen=? WHERE id=?",
- (datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
- session['user_id']))
+ (datetime.utcnow(),session['user_id']))
g.db.commit()
return redirect(url_for('list_news'))
else:
diff --git a/schema.sql b/schema.sql
index 0248ce7..0ce6e19 100644
--- a/schema.sql
+++ b/schema.sql
@@ -3,7 +3,7 @@ create table users (
id integer primary key autoincrement,
user_name string not null,
password string not null,
- last_seen string default (strftime('%Y-%m-%dT%H:%M:%SZ','now')),
+ last_seen timestamp default CURRENT_TIMESTAMP,
birthday string,
nameday string,
notify boolean default 1,
@@ -12,6 +12,7 @@ create table users (
address_line1,
address_line2,
address_city_line,
+ timezone string,
kado string
);
@@ -19,7 +20,7 @@ drop table if exists news;
create table news (
id integer primary key autoincrement,
title string not null,
- date string default (strftime('%Y-%m-%dT%H:%M:%SZ','now')),
+ date timestamp default CURRENT_TIMESTAMP,
content string not null,
content_cache string not null,
user_id integer,
@@ -29,7 +30,7 @@ create table news (
drop table if exists comments;
create table comments (
id integer primary key autoincrement,
- date string default (strftime('%Y-%m-%dT%H:%M:%SZ','now')),
+ date timestamp default CURRENT_TIMESTAMP,
content string,
content_cache string not null,
user_id integer,