Change session progress API.
Breaks compatibility, but worth it I think..
This commit is contained in:
parent
4909188ee3
commit
5b173dd9bc
|
@ -1,9 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 Lance Edgar
|
||||
# Copyright © 2010-2014 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -26,14 +25,17 @@
|
|||
Progress Indicator
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from beaker.session import Session
|
||||
|
||||
|
||||
def get_progress_session(session, key):
|
||||
request = session.request
|
||||
id = '%s.progress.%s' % (session.id, key)
|
||||
session = Session(request, id)
|
||||
return session
|
||||
def get_progress_session(request, key):
|
||||
"""
|
||||
Create/get a Beaker session object, to be used for progress.
|
||||
"""
|
||||
id = '{0}.progress.{1}'.format(request.session.id, key)
|
||||
return Session(request, id, use_cookies=False)
|
||||
|
||||
|
||||
class SessionProgress(object):
|
||||
|
@ -45,8 +47,8 @@ class SessionProgress(object):
|
|||
for display to the user.
|
||||
"""
|
||||
|
||||
def __init__(self, session, key):
|
||||
self.session = get_progress_session(session, key)
|
||||
def __init__(self, request, key):
|
||||
self.session = get_progress_session(request, key)
|
||||
self.canceled = False
|
||||
self.clear()
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ class ExecuteBatch(View):
|
|||
if not batch:
|
||||
return HTTPFound(location=self.request.route_url('batches'))
|
||||
|
||||
progress = SessionProgress(self.request.session, 'batch.execute')
|
||||
progress = SessionProgress(self.request, 'batch.execute')
|
||||
thread = Thread(target=self.execute_batch, args=(batch, progress))
|
||||
thread.start()
|
||||
kwargs = {
|
||||
|
|
|
@ -386,7 +386,7 @@ class CreateProductsBatch(ProductsGrid):
|
|||
self.request.session['referer'] = self.request.current_route_url()
|
||||
return HTTPFound(location=url)
|
||||
|
||||
progress = SessionProgress(self.request.session, 'products.batch')
|
||||
progress = SessionProgress(self.request, 'products.batch')
|
||||
thread = Thread(target=self.make_batch, args=(provider, progress))
|
||||
thread.start()
|
||||
kwargs = {
|
||||
|
|
|
@ -31,7 +31,7 @@ from ..progress import get_progress_session
|
|||
|
||||
def progress(request):
|
||||
key = request.matchdict['key']
|
||||
session = get_progress_session(request.session, key)
|
||||
session = get_progress_session(request, key)
|
||||
if session.get('complete'):
|
||||
request.session.flash(session.get('success_msg', "The process has completed successfully."))
|
||||
elif session.get('error'):
|
||||
|
@ -41,7 +41,7 @@ def progress(request):
|
|||
|
||||
def cancel(request):
|
||||
key = request.matchdict['key']
|
||||
session = get_progress_session(request.session, key)
|
||||
session = get_progress_session(request, key)
|
||||
session.clear()
|
||||
session['canceled'] = True
|
||||
session.save()
|
||||
|
|
Loading…
Reference in a new issue