Browse Source

use UTC in the database

master
Fr3deric 7 years ago
parent
commit
45a160e1be
  1. 11
      journalmarks/journalmarks.py
  2. 4
      journalmarks/templates/overview.html

11
journalmarks/journalmarks.py

@ -1,6 +1,7 @@
import re import re
import json import json
import pytz
import random import random
import string import string
import hashlib import hashlib
@ -32,7 +33,7 @@ class AccessToken(db_wrapper.Model):
class Journalmark(db_wrapper.Model): class Journalmark(db_wrapper.Model):
user = ForeignKeyField(User, backref='journalmarks') user = ForeignKeyField(User, backref='journalmarks')
created = DateTimeField(default=datetime.datetime.now()) created = DateTimeField(default=datetime.datetime.utcnow)
tag = CharField(unique=True) tag = CharField(unique=True)
content = CharField() content = CharField()
@ -87,7 +88,7 @@ def process_registration():
with db_wrapper.database.atomic(): with db_wrapper.database.atomic():
u = User(username=username, password=password_hash) u = User(username=username, password=password_hash)
at.redeemed = datetime.datetime.now() at.redeemed = datetime.datetime.utcnow()
u.save() u.save()
at.save() at.save()
return json.dumps('ok') return json.dumps('ok')
@ -194,7 +195,11 @@ def overview_get_journalmarks():
content = json.loads(j.content) content = json.loads(j.content)
except ValueError: except ValueError:
content = None content = None
ret.append({'created': j.created.isoformat(), 'tag': j.tag, 'content': content}) ret.append({
'created': pytz.utc.localize(j.created).isoformat(),
'tag': j.tag,
'content': content
})
return json.dumps(ret) return json.dumps(ret)

4
journalmarks/templates/overview.html

@ -18,7 +18,9 @@ function run() {
var p = document.getElementById('prototype'); var p = document.getElementById('prototype');
var n = p.cloneNode(true); var n = p.cloneNode(true);
n.id = 'journalmark_' + j.tag; n.id = 'journalmark_' + j.tag;
n.getElementsByClassName('date')[0].innerText = j.created; var created = new Date(j.created);
console.log(created);
n.getElementsByClassName('date')[0].innerText = created.getDate().toString() + '.' + (created.getMonth()+1).toString() + '.' + created.getFullYear().toString();
n.getElementsByClassName('tag')[0].innerText = j.tag; n.getElementsByClassName('tag')[0].innerText = j.tag;
n.getElementsByClassName('tag')[0].href = '/' + j.tag; n.getElementsByClassName('tag')[0].href = '/' + j.tag;
n.getElementsByClassName('url')[0].innerText = 'decrypting...'; n.getElementsByClassName('url')[0].innerText = 'decrypting...';

Loading…
Cancel
Save