[Zope-CVS] CVS: Packages/JobBoardEx - ApproveJobs.pt:1.10 IJob.py:1.9 IJobList.py:1.7 Job.py:1.8 JobList.py:1.14 JobListView.pt:1.7 JobView.pt:1.9

Steve Alexander steve@cat-box.net
Thu, 13 Jun 2002 16:09:47 -0400


Update of /cvs-repository/Packages/JobBoardEx
In directory cvs.zope.org:/tmp/cvs-serv30241

Modified Files:
	ApproveJobs.pt IJob.py IJobList.py Job.py JobList.py 
	JobListView.pt JobView.pt 
Log Message:
The JobList is now responsible for the ids of the Jobs it contains.
Jobs no longer know their own ids, but their views use
context/@@object_name as necessary to present the id.

Methods that formerly returned lists of jobs now return lists of jobids.
This avoids the issue of whether jobs returned in lists should be
individually context-wrapped.


=== Packages/JobBoardEx/ApproveJobs.pt 1.9 => 1.10 ===
     <tr><th>Defer</th><th>Approve</th><th>Discard</th>
     </tr>
-    <tr tal:repeat="job context/getPendingJobs"
+    <tr tal:repeat="jobid context/getPendingIds"
         style="text-align:center">
         <td><input type="radio" checked
-                   tal:attributes="name job/id"></td>
+                   tal:attributes="name jobid"></td>
         <td><input type="radio" value="approve"
-                   tal:attributes="name job/id"></td>
+                   tal:attributes="name jobid"></td>
         <td><input type="radio" value="discard"
-                   tal:attributes="name job/id"></td>
-        <td tal:content="job/summary">The best job on the Internet</td>
+                   tal:attributes="name jobid"></td>
+        <td tal:content="context/?jobid/summary">The best job on the Internet</td>
     </tr>
     <tr><td colspan="3">
         <input type="submit" value="Submit">


=== Packages/JobBoardEx/IJob.py 1.8 => 1.9 ===
     """Interface for the basic Job"""
 
-    id = Attribute("id",
-                   "Unique ID relative to the containing job list.\n"
-                   "This can be set at most once.")
-
     summary = Attribute("summary",
                         "One-line summary of the job")
 


=== Packages/JobBoardEx/IJobList.py 1.6 => 1.7 ===
 class IJobList(Interface):
 
-    def __getitem__(id):
-        """Returns the job with the given id"""
+    def __getitem__(jobid):
+        """Returns the job with the given jobid"""
 
     def query(state):
-        """Returns a list of Job objects"""
+        """Returns a list of Job ids"""
 
-    def getApprovedJobs():
-        """Returns a sequence of the jobs that are in the approved state
+    def getApprovedIds():
+        """Returns a sequence of ids for job that are in the approved state
         """
 
-    def getPendingJobs():
-        """Returns a sequence of the jobs that are in the pending state
+    def getPendingIds():
+        """Returns a sequence of ids for jobs that are in the pending state
         """
 
     def add(job):
-        """Add a Job object to the list."""
+        """Add a Job object to the list.
         
-    def remove(job):
-        """Removes the Job object job from the list.
+        Returns the id assigned to the job.
+        """
+        
+    def __delitem__(jobid):
+        """Removes the Job object with the given id from the list.
 
-        Raises ValueError if job is not in the list.
+        Raises KeyError if the jobid is not in the list.
         """


=== Packages/JobBoardEx/Job.py 1.7 => 1.8 ===
         self.description = description
         self.contact = contact
-        self.id = None
         self.state = JobState.PendingApproval
 
     def approve(self):


=== Packages/JobBoardEx/JobList.py 1.13 => 1.14 ===
-
+from Persistence import Persistent, PersistentMapping
 
 from IJobList import IJobList
 from IJob import JobState
@@ -10,39 +9,44 @@
 
     def __init__(self):
         self.id = 0
-        self.jobs = PersistentList()
+        self.jobs = PersistentMapping()
 
     def add(self, job):
-        job.id = self.id
+        jobid = self.id
         self.id += 1
-        self.jobs.append(job)
+        self.jobs[jobid] = job
+        # stringified for parity with query
+        # this can return an int when query can also return an int
+        return str(jobid)
 
-    def remove(self, job):
-        self.jobs.remove(job)
+    def __delitem__(self, jobid):
+        try:
+            jobid = int(jobid)
+        except ValueError:
+            raise KeyError, jobid
+
+        del self.jobs[jobid]
 
     def query(self, state):
-        return [job for job in self.jobs
-                if job.state == state]
+        # this should work returning a list of ints,
+        # but it exposes a bug in PageTemplates
+        
+        ids = [str(jobid)
+               for jobid,job in self.jobs.items()
+               if job.state == state]
+        ids.sort()
+        return ids
 
     def __getitem__(self, jobid):
         try:
             jobid = int(jobid)
-        except:
+        except ValueError:
             raise KeyError, jobid
-        
-        for job in self.jobs:
-            if job.id == jobid:
-                return job
-        raise KeyError, jobid
+            
+        return self.jobs[jobid]
 
-    def getPendingJobs(self):
+    def getPendingIds(self):
         return self.query(JobState.PendingApproval)
 
-    def getApprovedJobs(self):
+    def getApprovedIds(self):
         return self.query(JobState.Approved)
-
-
-
-
-
-


=== Packages/JobBoardEx/JobListView.pt 1.6 => 1.7 ===
 <table>
 
-<tr tal:repeat="job context/getApprovedJobs">
+<tr tal:repeat="jobid context/getApprovedIds">
     <td>
-    <a href="jobid" tal:attributes="href job/id">
-    <span tal:replace="job/summary">A job summary</span></A>
+    <a href="jobid" tal:attributes="href jobid">
+    <span tal:replace="context/?jobid/summary">A job summary</span></A>
     </td>
 </tr>
 </table>


=== Packages/JobBoardEx/JobView.pt 1.8 => 1.9 ===
 <head></head>
 <body>
+  <h3>Job #<span tal:replace="context/object_name">NN</span></h3>
 
-        <table border=0>
-        <tr><td>Summary:</td>
-            <td tal:content="context/summary">The best job on the net</td>
-        </tr>
-        </table>
+  <table border=0>
+  <tr><td>Summary:</td>
+      <td tal:content="context/summary">The best job on the net</td>
+  </tr>
+  </table>
 
-    <table border=0>
-        <tr><td>
-        <a href="..">Back to jobs</a>
-        </td></tr>
-    </table>
+  <table border=0>
+      <tr><td>
+      <a href="..">Back to jobs</a>
+      </td></tr>
+  </table>
 
 </body>
 </html>