Change session progress API.

Breaks compatibility, but worth it I think..
This commit is contained in:
Lance Edgar 2014-11-02 20:48:22 -06:00
parent 4909188ee3
commit 5b173dd9bc
4 changed files with 16 additions and 14 deletions

View file

@ -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-2014 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -26,14 +25,17 @@
Progress Indicator Progress Indicator
""" """
from __future__ import unicode_literals
from beaker.session import Session from beaker.session import Session
def get_progress_session(session, key): def get_progress_session(request, key):
request = session.request """
id = '%s.progress.%s' % (session.id, key) Create/get a Beaker session object, to be used for progress.
session = Session(request, id) """
return session id = '{0}.progress.{1}'.format(request.session.id, key)
return Session(request, id, use_cookies=False)
class SessionProgress(object): class SessionProgress(object):
@ -45,8 +47,8 @@ class SessionProgress(object):
for display to the user. for display to the user.
""" """
def __init__(self, session, key): def __init__(self, request, key):
self.session = get_progress_session(session, key) self.session = get_progress_session(request, key)
self.canceled = False self.canceled = False
self.clear() self.clear()

View file

@ -167,7 +167,7 @@ class ExecuteBatch(View):
if not batch: if not batch:
return HTTPFound(location=self.request.route_url('batches')) 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 = Thread(target=self.execute_batch, args=(batch, progress))
thread.start() thread.start()
kwargs = { kwargs = {

View file

@ -386,7 +386,7 @@ class CreateProductsBatch(ProductsGrid):
self.request.session['referer'] = self.request.current_route_url() self.request.session['referer'] = self.request.current_route_url()
return HTTPFound(location=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 = Thread(target=self.make_batch, args=(provider, progress))
thread.start() thread.start()
kwargs = { kwargs = {

View file

@ -31,7 +31,7 @@ from ..progress import get_progress_session
def progress(request): def progress(request):
key = request.matchdict['key'] key = request.matchdict['key']
session = get_progress_session(request.session, key) session = get_progress_session(request, key)
if session.get('complete'): if session.get('complete'):
request.session.flash(session.get('success_msg', "The process has completed successfully.")) request.session.flash(session.get('success_msg', "The process has completed successfully."))
elif session.get('error'): elif session.get('error'):
@ -41,7 +41,7 @@ def progress(request):
def cancel(request): def cancel(request):
key = request.matchdict['key'] key = request.matchdict['key']
session = get_progress_session(request.session, key) session = get_progress_session(request, key)
session.clear() session.clear()
session['canceled'] = True session['canceled'] = True
session.save() session.save()