Skip to content
Snippets Groups Projects
Commit 5d198536 authored by Joe Schneider's avatar Joe Schneider Committed by Gunnar Schaefer
Browse files

Provide timestamps with timezone in ISO format

parent 9a7099d2
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@ class Acquisitions(containers.ContainerList):
if not self.app.db.sessions.find_one({'_id': _id}):
self.abort(404, 'no such Session')
query = {'session': _id}
projection = {'label': 1, 'description': 1, 'types': 1, 'notes': 1}
projection = {'label': 1, 'description': 1, 'types': 1, 'notes': 1, 'timestamp': 1, 'timezone': 1}
acquisitions = self._get(query, projection, self.request.get('admin').lower() in ('1', 'true'))
if self.debug:
for acquisition in acquisitions:
......
......@@ -6,9 +6,9 @@ log = logging.getLogger('scitran.api')
import os
import json
import hashlib
import datetime
import jsonschema
import bson.json_util
import pytz
import tempdir as tempfile
......@@ -16,7 +16,6 @@ import base
import util
import users
import tempdir as tempfile
FILE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
......@@ -112,6 +111,19 @@ FILE_DOWNLOAD_SCHEMA = {
}
def fixup_timestamps(item):
if 'timestamp' in item:
if 'timezone' in item:
item_timezone = pytz.timezone(item['timezone'])
else:
item_timezone = pytz.timezone('UTC')
timestamp = item_timezone.localize(item['timestamp'])
item['timestamp'] = timestamp.isoformat()
item['timezone'] = item_timezone.zone
class ContainerList(base.RequestHandler):
def _get(self, query, projection, admin_only=False):
......@@ -127,6 +139,7 @@ class ContainerList(base.RequestHandler):
containers = list(self.dbc.find(query, projection))
for container in containers:
container['_id'] = str(container['_id'])
fixup_timestamps(container)
return containers
......@@ -154,6 +167,7 @@ class Container(base.RequestHandler):
for file_info in container['files']:
file_info['path'] = str(_id)[-3:] + '/' + str(_id) + '/' + file_info['name'] + file_info['ext']
container['_id'] = str(container['_id'])
fixup_timestamps(container)
return container, user_perm
def put(self, _id):
......
......@@ -64,7 +64,7 @@ class Sessions(containers.ContainerList):
query = {'project': _id}
else:
query = {}
projection = {'label': 1, 'subject.code': 1, 'notes': 1, 'project': 1}
projection = {'label': 1, 'subject.code': 1, 'notes': 1, 'project': 1, 'timestamp': 1, 'timezone': 1}
sessions = self._get(query, projection, self.request.get('admin').lower() in ('1', 'true'))
for sess in sessions:
sess['project'] = str(sess['project'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment