Skip to content
Snippets Groups Projects
Commit 002b8736 authored by Gunnar Schaefer's avatar Gunnar Schaefer
Browse files

update all projections and do some cleanup

parent 5d198536
No related branches found
No related tags found
No related merge requests found
......@@ -198,7 +198,7 @@ class Collections(containers.ContainerList):
def get(self):
"""Return the list of Collections."""
query = {'curator_id': self.request.get('curator')} if self.request.get('curator') else {}
projection = {'curator_id': 1, 'name': 1, 'notes': 1}
projection = {'curator_id': 1, 'name': 1, 'notes': 1, 'timestamp': 1, 'timezone': 1}
collections = self._get(query, projection, self.request.get('admin').lower() in ('1', 'true'))
for coll in collections:
coll['_id'] = str(coll['_id'])
......@@ -296,7 +296,7 @@ class CollectionSessions(sessions.Sessions):
{'$group': {'_id': '$session'}},
])
query = {'_id': {'$in': [ar['_id'] for ar in agg_res]}}
projection = {'label': 1, 'subject.code': 1, 'notes': 1}
projection = {'label': 1, 'subject.code': 1, 'notes': 1, 'timestamp': 1, 'timezone': 1}
projection['permissions'] = {'$elemMatch': {'_id': self.uid, 'site': self.source_site}}
sessions = list(self.dbc.find(query, projection))
for sess in sessions:
......@@ -333,7 +333,7 @@ class CollectionAcquisitions(acquisitions.Acquisitions):
query['session'] = bson.ObjectId(sid)
elif sid != '':
self.abort(400, sid + ' is not a valid ObjectId')
projection = {'label': 1, 'description': 1, 'types': 1, 'notes': 1}
projection = {'label': 1, 'description': 1, 'types': 1, 'notes': 1, 'timestamp': 1, 'timezone': 1}
projection['permissions'] = {'$elemMatch': {'_id': self.uid, 'site': self.source_site}}
acquisitions = list(self.dbc.find(query, projection))
for acq in acquisitions:
......
......@@ -5,10 +5,10 @@ log = logging.getLogger('scitran.api')
import os
import json
import pytz
import hashlib
import jsonschema
import bson.json_util
import pytz
import tempdir as tempfile
......@@ -111,17 +111,11 @@ 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
def fixup_timestamps(container):
if 'timestamp' in container:
container_timezone = pytz.timezone(container.get('timezone', None) or 'UTC')
container['timestamp'] = container_timezone.localize(container['timestamp']).isoformat()
container['timezone'] = container_timezone.zone
class ContainerList(base.RequestHandler):
......
......@@ -113,7 +113,7 @@ class Projects(containers.ContainerList):
def get(self):
"""Return the User's list of Projects."""
query = {'group_id': self.request.get('group')} if self.request.get('group') else {}
projection = {'group_id': 1, 'name': 1, 'notes': 1}
projection = {'group_id': 1, 'name': 1, 'notes': 1, 'timestamp': 1, 'timezone': 1}
projects = self._get(query, projection, self.request.get('admin').lower() in ('1', 'true'))
if self.debug:
for proj in projects:
......
......@@ -146,11 +146,12 @@ def _update_db(db, dataset):
fields=[],
)
if dataset.nims_timestamp:
db.projects.update({'_id': project['_id']}, {'$max': dict(timestamp=dataset.nims_timestamp)})
db.projects.update({'_id': project['_id']}, {'$max': dict(timestamp=dataset.nims_timestamp), '$set': dict(timezone=dataset.nims_timezone)})
db.sessions.update({'_id': session['_id']}, {'$min': dict(timestamp=dataset.nims_timestamp), '$set': dict(timezone=dataset.nims_timezone)})
# create a job, if necessary
return acquisition['_id']
# TODO: create job should be use-able from bootstrap.py with only database information
def create_job(dbc, dataset):
db = dbc.database
......
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