Author: tmckay
Date: 2012-02-09 19:53:24 +0000 (Thu, 09 Feb 2012)
New Revision: 5210
Modified:
trunk/cumin/python/cumin/account/widgets.py
trunk/cumin/python/cumin/grid/job.py
trunk/cumin/python/cumin/model.py
trunk/cumin/python/cumin/objecttask.py
trunk/cumin/python/cumin/task.py
trunk/wooly/python/wooly/__init__.py
Log:
Extend the "task_invocations" mechanism to allow general notices.
This provides the ability to send a "Notice:" to the user from anywhere
in the application where the "session" object is available.
Changes involved some refactoring of existing methods/objects.
Add a notice on redirect for missing submissions.
Modified: trunk/cumin/python/cumin/account/widgets.py
===================================================================
--- trunk/cumin/python/cumin/account/widgets.py 2012-02-09 16:30:40 UTC (rev 5209)
+++ trunk/cumin/python/cumin/account/widgets.py 2012-02-09 19:53:24 UTC (rev 5210)
@@ -214,11 +214,10 @@
error = FormError("Password change error. Please contact your site
administrator.")
self.errors.add(session,error)
- if not self.errors.get(session):
- task = ObjectTask(self.app)
- invoc = task.start(session, None)
- invoc.description = "Password changed"
- invoc.end()
+ if not self.errors.get(session):
+ # Just use a notice here to spoof a task completion.
+ session.add_notice(preamble="Password changed",
message="OK",
+ capitalize=False)
url = self.return_url.get(session)
self.page.redirect.set(session, url)
Modified: trunk/cumin/python/cumin/grid/job.py
===================================================================
--- trunk/cumin/python/cumin/grid/job.py 2012-02-09 16:30:40 UTC (rev 5209)
+++ trunk/cumin/python/cumin/grid/job.py 2012-02-09 19:53:24 UTC (rev 5210)
@@ -304,6 +304,7 @@
frame.view.show(nsession)
submission_list_url = nsession.marshal()
self.page.redirect.set(session, submission_list_url)
+ session.add_notice("The submission being displayed became
unavailable")
else:
return super(JobSelectorTable, self).do_render(session)
@@ -646,6 +647,7 @@
frame.view.show(nsession)
submission_list_url = nsession.marshal()
self.page.redirect.set(session, submission_list_url)
+ session.add_notice("The submission being displayed became
unavailable")
else:
return super(JobAdsViewer, self).do_render(session)
Modified: trunk/cumin/python/cumin/model.py
===================================================================
--- trunk/cumin/python/cumin/model.py 2012-02-09 16:30:40 UTC (rev 5209)
+++ trunk/cumin/python/cumin/model.py 2012-02-09 19:53:24 UTC (rev 5210)
@@ -25,7 +25,6 @@
self.model_dir = model_dir
self.tasks = list()
- self.task_invocations = list()
self.limits_by_negotiator = dict()
self.job_summaries_by_submission = dict()
Modified: trunk/cumin/python/cumin/objecttask.py
===================================================================
--- trunk/cumin/python/cumin/objecttask.py 2012-02-09 16:30:40 UTC (rev 5209)
+++ trunk/cumin/python/cumin/objecttask.py 2012-02-09 19:53:24 UTC (rev 5210)
@@ -65,10 +65,8 @@
def start(self, session, obj):
log.debug("Starting %s", self)
- login = session.client_session.attributes["login_session"]
+ invoc = TaskInvocation(self, session)
- invoc = TaskInvocation(self, login)
-
now = datetime.now()
invoc.start_time = now
Modified: trunk/cumin/python/cumin/task.py
===================================================================
--- trunk/cumin/python/cumin/task.py 2012-02-09 16:30:40 UTC (rev 5209)
+++ trunk/cumin/python/cumin/task.py 2012-02-09 19:53:24 UTC (rev 5210)
@@ -74,10 +74,8 @@
def start(self, session, obj):
log.debug("Starting %s", self)
- login = session.client_session.attributes["login_session"]
+ invoc = TaskInvocation(self, session)
- invoc = TaskInvocation(self, login)
-
now = datetime.now()
invoc.start_time = now
@@ -120,13 +118,12 @@
FAILED = "Failed"
OK = "OK"
- def __init__(self, task, login_session):
+ def __init__(self, task, session):
self.task = task
- login_session = login_session
- login_session.task_invocations.append(self)
+ session.add_task(self)
- self.user = login_session.user
+ self.user = session.get_user()
self.start_time = None
self.end_time = None
@@ -158,6 +155,13 @@
return self.status
+ def get_message(self, session):
+ description = xml_escape(self.get_description(session))
+ if not description:
+ description = ""
+ status = xml_escape(str(self.get_status(session)))
+ return "%s: %s" % (description, status)
+
def end(self):
log.debug("Ending %s", self.task)
@@ -238,10 +242,7 @@
self.add_child(self.item_widget)
def get_items(self, session):
- items = []
- if("login_session" in session.client_session.attributes.keys() ):
- login = session.client_session.attributes["login_session"]
- items = [x for x in login.task_invocations if not x.dismissed]
+ items = [x for x in session.get_task_invocations() if not x.dismissed]
return items
def do_process(self, session):
@@ -250,9 +251,12 @@
dismiss = self.dismiss.get(session)
dismiss_all = self.dismiss_all.get(session)
- if(dismiss_all):
+ if dismiss_all:
for invoc in self.get_items(session):
invoc.dismissed = True
+# We're leaking task invocations during the login session.
+# Replace the loop with the following at a later date
+# items[:] = []
self.dismiss_all.set(session, self.dismiss_all.default)
if dismiss:
@@ -260,6 +264,9 @@
if id(invoc) == dismiss:
invoc.dismissed = True
break
+# We're leaking task invocations during the login session.
+# Replace the loop with the following at a later date
+# items[:] = [x for x in items if id(x) != dismiss]
self.dismiss.set(session, self.dismiss.default)
@@ -287,16 +294,8 @@
return "resource?name=add-20.png"
def render_message(self, session, item):
- description = item.get_description(session)
- description = xml_escape(description)
+ return item.get_message(session)
- if not description:
- description = ""
-
- status = xml_escape(str(item.get_status(session)))
-
- return "%s: %s" % (description, status)
-
def render_dismiss_href(self, session, item):
branch = session.branch()
self.parent.dismiss.set(branch, id(item))
Modified: trunk/wooly/python/wooly/__init__.py
===================================================================
--- trunk/wooly/python/wooly/__init__.py 2012-02-09 16:30:40 UTC (rev 5209)
+++ trunk/wooly/python/wooly/__init__.py 2012-02-09 19:53:24 UTC (rev 5210)
@@ -822,10 +822,44 @@
name, value = crumb.split("=", 1)
self.cookies_by_name[name.strip()] = (False, value.strip(), None)
+ def add_notice(self, message, preamble="Notice", capitalize=True):
+ try:
+ t =
self.client_session.attributes["login_session"].task_invocations
+ t.append(Notice(preamble, message, capitalize))
+ except:
+ pass
+
+ def add_task(self, task):
+ try:
+ t =
self.client_session.attributes["login_session"].task_invocations
+ t.append(task)
+ except:
+ pass
+
+ def get_task_invocations(self):
+ try:
+ return
self.client_session.attributes["login_session"].task_invocations
+ except:
+ return []
+
+ def get_user(self):
+ return self.client_session.attributes["login_session"].user
+
def __repr__(self):
return "%s(trunk=%s,app=%s,id=%i)" % \
(self.__class__.__name__, self.trunk, self.app, id(self))
+class Notice(object):
+ def __init__(self, preamble, message, capitalize):
+ self.dismissed = False
+ if capitalize:
+ message = message.capitalize()
+ self.message = message
+ self.preamble = preamble
+
+ def get_message(self, session):
+ return "%s: %s" % (self.preamble, self.message)
+
class SessionAttribute(object):
def __init__(self, widget, name):
assert hasattr(widget, "app"), widget