[Zope-CVS] CVS: Packages/JobBoardEx - JobEditView.pt:1.1 JobPreviewView.pt:1.1 JobList.py:1.10 JobList.zcml:1.9 JobListView.pt:1.2 JobListView.py:1.11 JobView.pt:1.3 JobView.py:1.5 EndUserJobDisplay.pt:NONE NewJob.pt:NONE NewJob.py:NONE Preview.pt:NONE Waiting.pt:NONE

Guido van Rossum guido@python.org
Thu, 21 Mar 2002 16:42:53 -0500


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

Modified Files:
	JobList.py JobList.zcml JobListView.pt JobListView.py 
	JobView.pt JobView.py 
Added Files:
	JobEditView.pt JobPreviewView.pt 
Removed Files:
	EndUserJobDisplay.pt NewJob.pt NewJob.py Preview.pt Waiting.pt 
Log Message:
Major refactoring.  Lots of files removed and added.

Creating a new job now goes through a non-persistent pseudo job object
with job id "new", which is initialized from the request.

The editing process is a view on the job object (class JobEditView in
module JobView) and the different editing screens (edit form and
preview form) are represented by methods on this view.  The cancel and
submit actions are also methods on this view; cancel does a simple
redirect to the joblist summary page, while submit of course inserts
the job into the job list and *then* redirects to the joblist summary
page.

XXX The redirect upon the submit action is questionable.  Later.



=== Added File Packages/JobBoardEx/JobEditView.pt ===
<html>
<head>
<title>Enter new job data</title>
</head>
<body>
<h1>Enter new job data</h1>
    <form action="." method="post">
    <table border=0>
    <tr><td>Submitter:</td>
	<td><input name="submitter" type="text" value="" size="72"
	           tal:attributes="value container/getSubmitter|default" />
	</td>
    </tr>
    <tr><td>Summary:</td>
	<td><input name="summary" type="text" value="" size="72"
	           tal:attributes="value container/getSummary|default" />
	</td>
    </tr>
    <tr><td>Description:</td>
	<td><textarea cols=72 rows=20 name="description" type="text"
	     ><span tal:replace="container/getDescription|nothing"
                   /></textarea>
	</td>
    </tr>
    <tr><td>Contact:</td>
	<td><input name="contact" type="text" value="" size="72"
	           tal:attributes="value container/getContact|default" />
	</td>
    </tr>
    <tr><td colspan="2">
	<input name="preview:method" type="submit" value="Preview">
	<input name="cancel:method" type="submit" value="Cancel">
	<input name="reset" type="reset" value="Reset">
	</td>
    </tr>
    </table>
    </form>    

</body>
</html>


=== Added File Packages/JobBoardEx/JobPreviewView.pt ===
<html>
<head></head>
<body>

    <form action="." method="post">

	<table border=0>
	<tr><td>Submitter:</td>
	    <td tal:content="container/getSubmitter">aperson@dom.ain</td>
	</tr>
	<tr><td>Summary:</td>
	    <td tal:content="container/getSummary">The best job on the net</td>
	</tr>
	<tr><td>Description:</td>
	    <td tal:content="container/getDescription">This is really really
		    really the best job on the Internet</td>
	</tr>
	<tr><td>Contact:</td>
	    <td tal:content="container/getContact">bperson@dom.ain</td>
	</tr>
	</table>

    <table border=0>
	<tr><td>
	<input name="submit:method" type="submit" value="Submit">
	<input name="edit:method" type="submit" value="Edit">
	<input name="cancel:method" type="submit" value="Cancel">
	</td></tr>
    </table>
	<input name="submitter" type="hidden" value="Submitter" size="72"
	           tal:attributes="value container/getSubmitter" />
	<input name="summary" type="hidden" value="Summary" size="72"
	           tal:attributes="value container/getSummary" />
	<input name="description" type="hidden" value=""
	           tal:attributes="value container/getDescription" />
	<input name="contact" type="hidden" value="" size="72"
	           tal:attributes="value container/getContact" />
    </form>    

</body>
</html>


=== Packages/JobBoardEx/JobList.py 1.9 => 1.10 ===
-from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
-from Zope.ComponentArchitecture \
-     import getRequestView, getRequestDefaultViewName
 
 from IJobList import IJobList
 
@@ -34,27 +31,3 @@
             if job.id == jobid:
                 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.8 => 1.9 ===
 <!-- JobList -->
 
-<zmi:factoryFromClass 
-         name=".JobBoardEx.JobList." 
+<zmi:factoryFromClass
+         name=".JobBoardEx.JobList."
          permission_id="Zope.Public"
          title="JobList"
 />
 
-<security:protectClass 
+<security:protectClass
          name=".JobBoardEx.JobList."
          permission_id="Zope.Public"
 	 methods="query"
@@ -37,21 +37,23 @@
 
 <!-- JobListTraverser -->
 
+<!-- Declaring the custom traverser as a view is a bit of a hack -->
+
 <browser:view
 	for=".JobBoardEx.IJobList."
         name="_traverse"
-        factory=".JobBoardEx.JobList.JobListTraverser" 
+        factory=".JobBoardEx.JobListView.JobListTraverser"
 />
 
 <!-- JobListSummaryView -->
 
-<browser:defaultView 
+<browser:defaultView
         for=".JobBoardEx.IJobList."
         name="summary"
         factory=".JobBoardEx.JobListView.JobListSummaryView"
 />
 
-<security:protectClass 
+<security:protectClass
         name=".JobBoardEx.JobListView.JobListSummaryView"
         permission_id="Zope.Public"
         methods="index, getApprovedJobs"
@@ -59,34 +61,40 @@
 
 <!-- JobView -->
 
-<browser:view for=".JobBoardEx.IJob."
-              name="JobView"
-              factory=".JobBoardEx.JobView."
+<browser:view
+	for=".JobBoardEx.IJob."
+	name="JobView"
+	factory=".JobBoardEx.JobView."
+/>
+
+<browser:defaultView
+        for=".JobBoardEx.IJob."
+        name="display"
+        factory=".JobBoardEx.JobView.JobView"
 />
 
 <security:protectClass
 	name=".JobBoardEx.JobView."
 	permission_id="Zope.View"
-	methods="index, simpleView, getSubmitter, getSummary,
-	         getDescription, getContact"
+	methods="index, getSubmitter, getSummary, getDescription, getContact"
 />
 
-
-<!-- *** Actions *** -->
-
-<!-- NewJob -->
+<!-- JobEditView -->
 
 <browser:view
-	for=".JobBoardEx.IJobList."
-	name="NewJob"
-	factory=".JobBoardEx.NewJob."
+        for=".JobBoardEx.IJob."
+        name="edit"
+        factory=".JobBoardEx.JobView.JobEditView"
 />
 
 <security:protectClass
-	name=".JobBoardEx.NewJob."
-	permission_id="Zope.View"
-	methods="index, preview, waiting, getJobView, cancel, home, submit"
+        name=".JobBoardEx.JobView.JobEditView"
+        permission_id="Zope.Public"
+        methods="index, preview, cancel, edit, submit"
 />
+
+
+<!-- *** Actions *** -->
 
 <!-- ApproveJobs -->
 


=== Packages/JobBoardEx/JobListView.pt 1.1 => 1.2 ===
 <h1>Job Board</h1>
 
-<A href="../NewJob">Submit a new job</A>
+<A href="../new/edit;view/edit">Submit a new job</A>
 
 <H2>Job Listings</H2>
 


=== Packages/JobBoardEx/JobListView.py 1.10 => 1.11 ===
 from Zope.PageTemplate import PageTemplateFile
+from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
+from Zope.ComponentArchitecture \
+     import getRequestView, getRequestDefaultViewName
 
 from IJobList import IJobList
 from IJob import JobState
+
+from Job import Job
+
+class JobListTraverser:
+
+    __implements__ = IBrowserPublisher
+
+    def __init__(self, joblist):
+        self.joblist = joblist
+
+    def browser_traverse(self, request, name):
+        if name == "new":
+            return self.jobFromRequest(request)
+        # First check if it's a request for a contained job
+        try:
+            jobid = int(name)
+        except: # not sure what exceptions int() raises!!
+            pass
+        else:
+            return self.joblist.lookup(jobid)
+
+        # It wasn't a jobid.  Return a view.
+        return getRequestView(self.joblist, name, request)
+
+    def jobFromRequest(self, request):
+        submitter = request.get('submitter')
+        summary = request.get('summary')
+        description = request.get('description')
+        contact = request.get('contact')
+        return Job(submitter, summary, description, contact)
+        
+    def browser_default(self, request):
+        default_name = getRequestDefaultViewName(self.joblist, request)
+        return self.joblist, [default_name]
 
 class JobListSummaryView(AttributePublisher):
 


=== Packages/JobBoardEx/JobView.pt 1.2 => 1.3 ===
-<tr><td>Submitter:</td>
-    <td tal:content="container/getSubmitter">aperson@dom.ain</td>
-</tr>
-<tr><td>Summary:</td>
-    <td tal:content="container/getSummary">The best job on the Internet</td>
-</tr>
-<tr><td>Description:</td>
-    <td tal:content="container/getDescription">This is really really
-	    really the best job on the Internet</td>
-</tr>
-<tr><td>Contact:</td>
-    <td tal:content="container/getContact">bperson@dom.ain</td>
-</tr>
-</table>
+<html>
+<head></head>
+<body>
+
+    <form action="../../" method="post">
+
+	<table border=0>
+	<tr><td>Submitter:</td>
+	    <td tal:content="container/getSubmitter">aperson@dom.ain</td>
+	</tr>
+	<tr><td>Summary:</td>
+	    <td tal:content="container/getSummary">The best job on the net</td>
+	</tr>
+	<tr><td>Description:</td>
+	    <td tal:content="container/getDescription">This is really really
+		    really the best job on the Internet</td>
+	</tr>
+	<tr><td>Contact:</td>
+	    <td tal:content="container/getContact">bperson@dom.ain</td>
+	</tr>
+	</table>
+
+    <table border=0>
+	<tr><td>
+	<input type="submit" value="Back to summary">
+	</td></tr>
+    </table>
+    </form>    
+
+</body>
+</html>


=== Packages/JobBoardEx/JobView.py 1.4 => 1.5 ===
 from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
+from Zope.ComponentArchitecture import getRequestView
+from Zope.ContextWrapper import getcontext, getbaseobject
 
 from IJob import IJob, JobState
 
@@ -14,9 +16,7 @@
     def getContext(self):
         return self.job
 
-    index = PageTemplateFile('EndUserJobDisplay.pt')
-
-    simpleView = PageTemplateFile('JobView.pt')
+    index = PageTemplateFile('JobView.pt')
 
     # Add accessor methods so the security framework can do assertion.  The
     # page template can't use the attributes on the Job object directly. :(
@@ -31,3 +31,21 @@
 
     def getContact(self):
         return self.job.contact
+
+class JobEditView(JobView):
+
+    edit = PageTemplateFile('JobEditView.pt')
+
+    index = edit
+
+    preview = PageTemplateFile('JobPreviewView.pt')
+
+    def cancel(self, REQUEST):
+        return REQUEST.response.redirect('../../')
+
+    def submit(self, REQUEST):
+        job = self.job
+        joblist = getcontext(job)
+        job = getbaseobject(job)
+        joblist.add(job)
+        return REQUEST.response.redirect('../../')

=== Removed File Packages/JobBoardEx/EndUserJobDisplay.pt ===

=== Removed File Packages/JobBoardEx/NewJob.pt ===

=== Removed File Packages/JobBoardEx/NewJob.py ===

=== Removed File Packages/JobBoardEx/Preview.pt ===

=== Removed File Packages/JobBoardEx/Waiting.pt ===