-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.py
42 lines (32 loc) · 1.08 KB
/
status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import grok
from layout import Content
from interfaces import ISiteRoot, IStatus
class StatusData(grok.Model):
''' This data gets stored in the site root. If the
status is not None we will render a popup dialog.
'''
title = u'Status'
message = ''
status = None
def __init__(self, sts, msg, title=u'Status'):
self.status = sts
self.message = msg
self.title = title
app = grok.getApplication()
app.status = self
def read(self): # "one shot" reader
if self.status is not None:
sts = dict(status=self.status,
title=self.title,
message=self.message)
self.status = None
return sts
class Status(grok.GlobalUtility):
''' A small utility to set the status message '''
grok.implements(IStatus)
def __call__(self, sts, msg, title=u'Status'):
StatusData(sts, msg, title)
class StatusContent(grok.Viewlet):
''' Renders the status into the content area '''
grok.context(ISiteRoot)
grok.viewletmanager(Content)