Various tweaks to support "late login" idea when uploading new batch.

This commit is contained in:
Lance Edgar 2015-08-15 17:00:01 -05:00
parent 1a929f8dd1
commit 3e37ac909e
3 changed files with 39 additions and 21 deletions

View file

@ -25,7 +25,7 @@
Pyramid Views
"""
from tailbone.views.core import View
from .core import View
from tailbone.views.grids import (
GridView, AlchemyGridView, SortableAlchemyGridView,
PagedAlchemyGridView, SearchableAlchemyGridView)

View file

@ -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()
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,12 +550,14 @@ 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()
if progress:
progress.session.load()
progress.session['error'] = True
progress.session['error_msg'] = "Data refresh failed: {0}".format(error)
@ -564,9 +569,10 @@ class BatchCrud(BaseCrud):
session.close()
# Finalize progress indicator.
if progress:
progress.session.load()
progress.session['complete'] = True
progress.session['success_url'] = self.view_url(batch.uuid)
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

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
# Copyright © 2010-2015 Lance Edgar
#
# This file is part of Rattail.
#
@ -21,18 +20,20 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Core View
Base View Class
"""
from __future__ import unicode_literals
__all__ = ['View']
from rattail.db import model
from tailbone.db import Session
class View(object):
"""
Base for all class-based views.
Base class for all class-based views.
"""
def __init__(self, request):
@ -45,6 +46,16 @@ class View(object):
"""
return self.request.rattail_config
def late_login_user(self):
"""
Returns the :class:`rattail:rattail.db.model.User` instance
corresponding to the "late login" form data (if any), or ``None``.
"""
if self.request.method == 'POST':
uuid = self.request.POST.get('late-login-user')
if uuid:
return Session.query(model.User).get(uuid)
def fake_error(request):
"""