Various tweaks to support "late login" idea when uploading new batch.
This commit is contained in:
parent
1a929f8dd1
commit
3e37ac909e
|
@ -25,7 +25,7 @@
|
||||||
Pyramid Views
|
Pyramid Views
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from tailbone.views.core import View
|
from .core import View
|
||||||
from tailbone.views.grids import (
|
from tailbone.views.grids import (
|
||||||
GridView, AlchemyGridView, SortableAlchemyGridView,
|
GridView, AlchemyGridView, SortableAlchemyGridView,
|
||||||
PagedAlchemyGridView, SearchableAlchemyGridView)
|
PagedAlchemyGridView, SearchableAlchemyGridView)
|
||||||
|
|
|
@ -530,15 +530,18 @@ class BatchCrud(BaseCrud):
|
||||||
}
|
}
|
||||||
return render_to_response('/progress.mako', kwargs, request=self.request)
|
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.
|
Instruct the batch handler to refresh all data for the batch.
|
||||||
"""
|
"""
|
||||||
self.handler.refresh_data(session, batch, progress=progress)
|
self.handler.refresh_data(session, batch, progress=progress)
|
||||||
batch.cognized = datetime.datetime.utcnow()
|
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.
|
Thread target for refreshing batch data with progress indicator.
|
||||||
"""
|
"""
|
||||||
|
@ -547,16 +550,18 @@ class BatchCrud(BaseCrud):
|
||||||
# transaction binding etc.
|
# transaction binding etc.
|
||||||
session = RatSession()
|
session = RatSession()
|
||||||
batch = session.query(self.batch_class).get(batch_uuid)
|
batch = session.query(self.batch_class).get(batch_uuid)
|
||||||
|
cognizer = session.query(model.User).get(cognizer_uuid) if cognizer_uuid else None
|
||||||
try:
|
try:
|
||||||
self.refresh_data(session, batch, progress=progress)
|
self.refresh_data(session, batch, cognizer=cognizer, progress=progress)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
log.warning("refreshing data for batch failed: {0}".format(batch), exc_info=True)
|
log.warning("refreshing data for batch failed: {0}".format(batch), exc_info=True)
|
||||||
session.close()
|
session.close()
|
||||||
progress.session.load()
|
if progress:
|
||||||
progress.session['error'] = True
|
progress.session.load()
|
||||||
progress.session['error_msg'] = "Data refresh failed: {0}".format(error)
|
progress.session['error'] = True
|
||||||
progress.session.save()
|
progress.session['error_msg'] = "Data refresh failed: {0}".format(error)
|
||||||
|
progress.session.save()
|
||||||
return
|
return
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
@ -564,10 +569,11 @@ class BatchCrud(BaseCrud):
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
# Finalize progress indicator.
|
# Finalize progress indicator.
|
||||||
progress.session.load()
|
if progress:
|
||||||
progress.session['complete'] = True
|
progress.session.load()
|
||||||
progress.session['success_url'] = self.view_url(batch.uuid)
|
progress.session['complete'] = True
|
||||||
progress.session.save()
|
progress.session['success_url'] = success_url or self.view_url(batch.uuid)
|
||||||
|
progress.session.save()
|
||||||
|
|
||||||
def view_url(self, uuid=None):
|
def view_url(self, uuid=None):
|
||||||
"""
|
"""
|
||||||
|
@ -692,7 +698,8 @@ class FileBatchCrud(BatchCrud):
|
||||||
|
|
||||||
# For new batches, assign current user as creator, save file etc.
|
# For new batches, assign current user as creator, save file etc.
|
||||||
if self.creating:
|
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
|
# Expunge batch from session to prevent it from being flushed
|
||||||
# during init. This is done as a convenience to views which
|
# during init. This is done as a convenience to views which
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
#!/usr/bin/env python
|
# -*- coding: utf-8 -*-
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2012 Lance Edgar
|
# Copyright © 2010-2015 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -21,18 +20,20 @@
|
||||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
# 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):
|
class View(object):
|
||||||
"""
|
"""
|
||||||
Base for all class-based views.
|
Base class for all class-based views.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
|
@ -45,6 +46,16 @@ class View(object):
|
||||||
"""
|
"""
|
||||||
return self.request.rattail_config
|
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):
|
def fake_error(request):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue