[Zope-CVS] CVS: Packages/JobBoardEx - JobCreateView.pt:1.2 add_confirmed.pt:1.2 ApproveJobs.pt:1.7 ApproveJobs.py:1.7 IJob.py:1.7 JobList.zcml:1.14 JobListView.pt:1.5 JobPreviewView.pt:1.5 JobView.py:1.9

Gary Poster garyposter@earthlink.net
Wed, 3 Apr 2002 23:32:02 -0500


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

Modified Files:
	ApproveJobs.pt ApproveJobs.py IJob.py JobList.zcml 
	JobListView.pt JobPreviewView.pt JobView.py 
Added Files:
	JobCreateView.pt add_confirmed.pt 
Log Message:
added pre-create view code, incorporated Stephan's zcml changes



=== Packages/JobBoardEx/JobCreateView.pt 1.1 => 1.2 ===
+<head>
+<title>Enter new job data</title>
+</head>
+<body>
+<h1>Enter new job data</h1>
+    <form action="." method="post" tal:attributes="action request/URL/-1">
+    <table border=0>
+    <tr><td>Submitter:</td>
+	<td><input name="submitter" type="text" value="" size="72" 
+	tal:attributes="value request/submitter|default"
+	            />
+	</td>
+    </tr>
+    <tr><td>Summary:</td>
+	<td><input name="summary" type="text" value="" size="72"
+	tal:attributes="value request/summary|default"
+	            />
+	</td>
+    </tr>
+    <tr><td>Description:</td>
+	<td><textarea cols=72 rows=20 name="description" type="text"
+	tal:content="request/description|default"
+	     ></textarea>
+	</td>
+    </tr>
+    <tr><td>Contact:</td>
+	<td><input name="contact" type="text" value="" size="72"
+	tal:attributes="value request/contact|default"
+	           />
+	</td>
+    </tr>
+    <tr><td colspan="2">
+	<input name="preview:method" type="submit" value="Preview">
+	<input name="action:method" type="submit" value="Create">
+	<input name="reset" type="reset" value="Reset">
+	</td>
+    </tr>
+    </table>
+    </form>    
+
+</body>
+</html>


=== Packages/JobBoardEx/add_confirmed.pt 1.1 => 1.2 ===
+                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<!--
+      metal:use-macro="presentation/standard_macros/html">
+  -->
+<body>
+
+<p> Object added successfully. </p>
+
+</body>
+</html>


=== Packages/JobBoardEx/ApproveJobs.pt 1.6 => 1.7 ===
 <body>
 
-    <form action="." method="post">
+
+    <form action="." method="post" tal:attributes="action request/URL/-1">
     <table border=0>
     <tr><th colspan=3>Action</th>
         <th rowspan=2>Summary</th>


=== Packages/JobBoardEx/ApproveJobs.py 1.6 => 1.7 ===
 
     def back(self, REQUEST):
-        return REQUEST.getResponse().redirect('..')
+        return REQUEST.getResponse().redirect(REQUEST.URL[-2])
 
     def submit(self, REQUEST):
         """Approve a job."""


=== Packages/JobBoardEx/IJob.py 1.6 => 1.7 ===
 from Interface.Attribute import Attribute
 
+class IJobCreator(Interface):
+    """marker for pre-creation view of object"""
 
 class IJob(Interface):
     """Interface for the basic Job"""
@@ -29,7 +31,7 @@
                       "Current state of the job listing.\n"
                       "The possible values are defined in JobState.")
 
-    def approve(self):
+    def approve():
         "Moves the job state to approved"
 
 


=== Packages/JobBoardEx/JobList.zcml 1.13 => 1.14 ===
 
 <!-- JobList -->
-
-<zmi:factoryFromClass
-         name=".JobList."
-         permission_id="Zope.Public"
-         title="JobList"
-/>
+<zmi:factoryFromClass name="JobList"
+                      class=".JobList."
+                      permission_id="Zope.ManageContent"
+                      title="JobList"
+                      description="A Job Board" />
 
 <security:protectClass
          name=".JobList."
@@ -23,8 +22,18 @@
 
 <!-- Job -->
 
-<!-- This doesn't need a factory, since jobs are always created by
-     Python code. -->
+<!-- ideally jobs would be created within a placeful factory, only to
+be within a JobList; that is not an option now, so "Job" will be
+available everywhere at the moment. Note the marker_interface is the
+only new animal here. -->
+
+<zmi:factoryFromClass
+	name="Job"
+	class=".Job."
+	permission_id="Zope.Public"
+	title="A job to be placed within a JobList"
+        marker_interface=".IJob.IJobCreator." 
+/>
 
 <security:protectClass
 	name=".Job."
@@ -33,6 +42,20 @@
 
 
 <!-- *** Views *** -->
+
+<!-- pre-creation job view -->
+
+<browser:defaultView
+    for=".IJob.IJobCreator"
+    name="create"
+    factory=".JobView.CreateJobView"
+/>
+
+<security:protectClass
+        name=".JobView.CreateJobView"
+        permission_id="Zope.Public"
+        methods="index, action, preview, cancel"
+/>
 
 <!-- JobListTraverser -->
 


=== Packages/JobBoardEx/JobListView.pt 1.4 => 1.5 ===
 <h1>Job Board</h1>
 
-<A href="../new">Submit a new job</A>
+<A href="../Job;create">Submit a new job</A>
 
 <H2>Job Listings</H2>
 


=== Packages/JobBoardEx/JobPreviewView.pt 1.4 => 1.5 ===
-<head></head>
+<head>
+<title>Preview job data</title></head>
 <body>
 
-    <form action="." method="post">
+    <form action="." method="post" tal:attributes="action
+    request/URL/-1">
+
 
         <table border=0>
         <tr><td>Submitter:</td>
-            <td tal:content="view/getSubmitter">aperson@dom.ain</td>
+            <td tal:content="request/submitter">aperson@dom.ain</td>
         </tr>
         <tr><td>Summary:</td>
-            <td tal:content="view/getSummary">The best job on the net</td>
+            <td tal:content="request/summary">The best job on the net</td>
         </tr>
         <tr><td>Description:</td>
-            <td tal:content="view/getDescription">This is really really
+            <td tal:content="request/description">This is really really
                     really the best job on the Internet</td>
         </tr>
         <tr><td>Contact:</td>
-            <td tal:content="view/getContact">bperson@dom.ain</td>
+            <td tal:content="request/contact">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="action:method" type="submit" value="Submit">
+        <input name="index: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 view/getSubmitter" />
+                   tal:attributes="value request/submitter" />
         <input name="summary" type="hidden" value="Summary" size="72"
-                   tal:attributes="value view/getSummary" />
+                   tal:attributes="value request/summary" />
         <input name="description" type="hidden" value=""
-                   tal:attributes="value view/getDescription" />
+                   tal:attributes="value request/description" />
         <input name="contact" type="hidden" value="" size="72"
-                   tal:attributes="value view/getContact" />
+                   tal:attributes="value request/contact" />
     </form>    
 
 </body>


=== Packages/JobBoardEx/JobView.py 1.8 => 1.9 ===
 from Zope.Publisher.Browser.AttributePublisher import AttributePublisher
+from Zope.ContextWrapper import getcontext
+from Zope.App.OFS.Container.Exceptions import DuplicateIDError
+from Zope.ComponentArchitecture import createObject
+from IJobList import IJobList
 
-from IJob import IJob, JobState
+from IJob import IJob, JobState, IJobCreator
 
 
 class JobView(AttributePublisher):
@@ -47,3 +51,49 @@
         job = self.job
         joblist.add(job)
         return REQUEST.getResponse().redirect('..')
+
+class CreateJobView(AttributePublisher):
+    """Provide an interface for adding a job
+    """
+
+    def __init__(self, context):
+        self._context=context
+        if not IJobList.isImplementedBy(getcontext(context)):
+            raise StandardError, "Job objects can only be created within a JobList"
+        # StandardError is not a good choice but I don't even know
+        # if this solution will be approved yet so I am not worrying
+        # about it
+
+    def getContext(self):
+        return self._context
+
+    # Assert that we can only be applied to IJobCreator
+    __used_for__=IJobCreator
+
+    # Input form
+    index = PageTemplateFile('JobCreateView.pt', globals())
+
+    # action method
+    def action(self, submitter, summary, description, contact, REQUEST=None):
+        """Create an item of the class identified by the Addable (held in
+        _context) within the container that is the parent of the Addable"""
+        addable=self.getContext()
+        container=getcontext(addable)
+
+        container.add(createObject(container, addable.id(), submitter, summary, description, contact ))
+
+        if REQUEST is not None:
+            # for unit tests
+            REQUEST.getResponse().redirect(REQUEST.URL[-3])
+
+        return self.confirmed( type_name=addable.id(), id=id )
+
+    confirmed = PageTemplateFile('add_confirmed.pt')
+    preview = PageTemplateFile('JobPreviewView.pt')
+    def cancel(self, REQUEST=None):
+        """Cancel the job creation (would be more easily done with a link,
+	but I'm trying to accomodate the current design)"""
+	if REQUEST is not None:
+            REQUEST.getResponse().redirect(REQUEST.URL[-3])
+
+