[Zope-CVS] CVS: Packages/JobBoardEx - JobList.py:1.7 JobList.zcml:1.3 JobListView.py:1.5
Jeremy Hylton
jeremy@zope.com
Wed, 20 Mar 2002 12:43:07 -0500
Update of /cvs-repository/Packages/JobBoardEx
In directory cvs.zope.org:/tmp/cvs-serv26276
Modified Files:
JobList.py JobList.zcml JobListView.py
Log Message:
Make JobList traversable: Use jobid to get job object.
Add a JobListTraverse to the JobList module.
Register the traverse in the zcml file under the special name _traverse.
Rename the JobListView class to JobListSummary view. The intent is to
keep all views on the JobList in the JobListView module.
Fix reference to JobState.Approved in JobListSummaryView.
=== Packages/JobBoardEx/JobList.py 1.6 => 1.7 ===
+from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
+from Zope.ComponentArchitecture \
+ import getRequestView, getRequestDefaultViewName
from ZopeProducts.JobBoardEx.IJobList import IJobList
@@ -25,5 +28,26 @@
return job
raise KeyError, jobid
+class JobListTraverser:
+ __implements__ = IBrowserPublisher
+ def __init__(self, joblist):
+ self.joblist = joblist
+
+ def browser_traverse(self, request, name):
+ # First check if it's a request for a contained job
+ try:
+ jobid = int(name)
+ except: # not sure what exceptions int() raises!!
+ pass
+ else:
+ job = self.joblist.lookup(jobid)
+ return job
+
+ # It wasn't a jobid. Return a view.
+ return getRequestView(self.joblist, name, request)
+
+ def browser_default(self, request):
+ default_name = getRequestDefaultViewName(self.joblist, request)
+ return self.joblist, [default_name]
=== Packages/JobBoardEx/JobList.zcml 1.2 => 1.3 ===
<browser:defaultView for=".JobBoardEx.IJobList."
name="summary"
- factory=".JobBoardEx.JobListView." />
+ factory=".JobBoardEx.JobListView.JobListSummaryView"
+/>
-<security:protectClass name=".JobBoardEx.JobListView."
+<security:protectClass name=".JobBoardEx.JobListView.JobListSummaryView"
+ permission_id="Zope.Public"
+ methods="index, getApprovedJobs"
+/>
+
+<browser:view for=".JobBoardEx.IJobList."
+ name="_traverse"
+ factory=".JobBoardEx.JobList.JobListTraverser"
+/>
+
+<security:protectClass name=".JobBoardEx.JobListView.JobListSummaryView"
permission_id="Zope.Public"
methods="index, getApprovedJobs"
/>
=== Packages/JobBoardEx/JobListView.py 1.4 => 1.5 ===
from Zope.PageTemplate import PageTemplateFile
-from ZopeProducts.JobBoardEx.IJobList import IJobList, IJob
+from ZopeProducts.JobBoardEx.IJobList import IJobList
+from ZopeProducts.JobBoardEx.IJob import IJob, JobState
-class JobListView(AttributePublisher):
+class JobListSummaryView(AttributePublisher):
def __init__(self, joblist):
self.joblist = joblist
@@ -14,6 +15,6 @@
__used_for__ = IJobList
def getApprovedJobs(self):
- return self.joblist.query(IJob.JobState.Approved)
+ return self.joblist.query(JobState.Approved)
index = PageTemplateFile("summary.pt", globals())