Various tweaks to support "late login" idea when uploading new batch.
This commit is contained in:
parent
1a929f8dd1
commit
3e37ac909e
3 changed files with 39 additions and 21 deletions
|
@ -530,15 +530,18 @@ class BatchCrud(BaseCrud):
|
|||
}
|
||||
return render_to_response('/progress.mako', kwargs, request=self.request)
|
||||
|
||||
def refresh_data(self, session, batch, progress=None):
|
||||
def refresh_data(self, session, batch, cognizer=None, progress=None):
|
||||
"""
|
||||
Instruct the batch handler to refresh all data for the batch.
|
||||
"""
|
||||
self.handler.refresh_data(session, batch, progress=progress)
|
||||
batch.cognized = datetime.datetime.utcnow()
|
||||
batch.cognized_by = self.request.user
|
||||
if cognizer is not None:
|
||||
batch.cognized_by = cognizer
|
||||
else:
|
||||
batch.cognized_by = self.request.user
|
||||
|
||||
def refresh_thread(self, batch_uuid, progress):
|
||||
def refresh_thread(self, batch_uuid, cognizer_uuid=None, success_url=None, progress=None):
|
||||
"""
|
||||
Thread target for refreshing batch data with progress indicator.
|
||||
"""
|
||||
|
@ -547,16 +550,18 @@ class BatchCrud(BaseCrud):
|
|||
# transaction binding etc.
|
||||
session = RatSession()
|
||||
batch = session.query(self.batch_class).get(batch_uuid)
|
||||
cognizer = session.query(model.User).get(cognizer_uuid) if cognizer_uuid else None
|
||||
try:
|
||||
self.refresh_data(session, batch, progress=progress)
|
||||
self.refresh_data(session, batch, cognizer=cognizer, progress=progress)
|
||||
except Exception as error:
|
||||
session.rollback()
|
||||
log.warning("refreshing data for batch failed: {0}".format(batch), exc_info=True)
|
||||
session.close()
|
||||
progress.session.load()
|
||||
progress.session['error'] = True
|
||||
progress.session['error_msg'] = "Data refresh failed: {0}".format(error)
|
||||
progress.session.save()
|
||||
if progress:
|
||||
progress.session.load()
|
||||
progress.session['error'] = True
|
||||
progress.session['error_msg'] = "Data refresh failed: {0}".format(error)
|
||||
progress.session.save()
|
||||
return
|
||||
|
||||
session.commit()
|
||||
|
@ -564,10 +569,11 @@ class BatchCrud(BaseCrud):
|
|||
session.close()
|
||||
|
||||
# Finalize progress indicator.
|
||||
progress.session.load()
|
||||
progress.session['complete'] = True
|
||||
progress.session['success_url'] = self.view_url(batch.uuid)
|
||||
progress.session.save()
|
||||
if progress:
|
||||
progress.session.load()
|
||||
progress.session['complete'] = True
|
||||
progress.session['success_url'] = success_url or self.view_url(batch.uuid)
|
||||
progress.session.save()
|
||||
|
||||
def view_url(self, uuid=None):
|
||||
"""
|
||||
|
@ -692,7 +698,8 @@ class FileBatchCrud(BatchCrud):
|
|||
|
||||
# For new batches, assign current user as creator, save file etc.
|
||||
if self.creating:
|
||||
batch.created_by = self.request.user
|
||||
with Session.no_autoflush:
|
||||
batch.created_by = self.request.user or self.latelogin_user()
|
||||
|
||||
# Expunge batch from session to prevent it from being flushed
|
||||
# during init. This is done as a convenience to views which
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue