[Zope-CVS] CVS: Packages/JobBoardEx - JobCreateView.pt:1.1.2.1 add_confirmed.pt:1.1.2.1 ApproveJobs.pt:1.5.2.1 IJob.py:1.6.2.1 JobEditView.pt:1.3.2.1 JobList.zcml:1.13.2.1 JobListView.pt:1.4.2.1 JobView.pt:1.6.2.1 JobView.py:1.8.2.1

Gary Poster garyposter@earthlink.net
Tue, 2 Apr 2002 11:50:34 -0500


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

Modified Files:
      Tag: gary-pre_create_views_example-branch
	ApproveJobs.pt IJob.py JobEditView.pt JobList.zcml 
	JobListView.pt JobView.pt JobView.py 
Added Files:
      Tag: gary-pre_create_views_example-branch
	JobCreateView.pt add_confirmed.pt 
Log Message:
changes to illustrate (somewhat poorly) the pre-create views functionality


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

</body>
</html>


=== Added File Packages/JobBoardEx/add_confirmed.pt ===
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "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.5 => 1.5.2.1 ===
     <tr><th>Defer</th><th>Approve</th><th>Discard</th>
     </tr>
-    <tr tal:repeat="job view/getPendingJobs"
+    <tr tal:repeat="job container/getPendingJobs"
 	style="text-align:center">
 	<td><input name="job_N" type="radio" value="defer" checked
 		   tal:attributes="name string:job_${job/id}"></td>


=== Packages/JobBoardEx/IJob.py 1.6 => 1.6.2.1 ===
 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/JobEditView.pt 1.3 => 1.3.2.1 ===
     <tr><td>Submitter:</td>
 	<td><input name="submitter" type="text" value="" size="72"
-	           tal:attributes="value view/getSubmitter|default" />
+	           tal:attributes="value container/getSubmitter|default" />
 	</td>
     </tr>
     <tr><td>Summary:</td>
 	<td><input name="summary" type="text" value="" size="72"
-	           tal:attributes="value view/getSummary|default" />
+	           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="view/getDescription|nothing"
+	     ><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 view/getContact|default" />
+	           tal:attributes="value container/getContact|default" />
 	</td>
     </tr>
     <tr><td colspan="2">


=== Packages/JobBoardEx/JobList.zcml 1.13 => 1.13.2.1 ===
 <!-- Job -->
 
-<!-- This doesn't need a factory, since jobs are always created by
+<!-- NO LONGER TRUE: This doesn't need a factory, since jobs are always
+created by
      Python code. -->
+<!-- ideally this would be 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."
+	permission_id="Zope.Public"
+	title="Job"
+        marker_interface=".IJob.IJobCreator." 
+/>
 
 <security:protectClass
 	name=".Job."
@@ -33,6 +45,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"
+/>
 
 <!-- JobListTraverser -->
 


=== Packages/JobBoardEx/JobListView.pt 1.4 => 1.4.2.1 ===
 <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>
 
 <table>
 
-<tr tal:repeat="job view/getApprovedJobs">
+<tr tal:repeat="job container/getApprovedJobs">
     <td>
     <a href="jobid" tal:attributes="href string:../${job/id}">
     <span tal:replace="job/summary">A job summary</span></A>


=== Packages/JobBoardEx/JobView.pt 1.6 => 1.6.2.1 ===
 	<table border=0>
 	<tr><td>Submitter:</td>
-	    <td tal:content="view/getSubmitter">aperson@dom.ain</td>
+	    <td tal:content="container/getSubmitter">aperson@dom.ain</td>
 	</tr>
 	<tr><td>Summary:</td>
-	    <td tal:content="view/getSummary">The best job on the net</td>
+	    <td tal:content="container/getSummary">The best job on the net</td>
 	</tr>
 	<tr><td>Description:</td>
-	    <td tal:content="view/getDescription">This is really really
+	    <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="view/getContact">bperson@dom.ain</td>
+	    <td tal:content="container/getContact">bperson@dom.ain</td>
 	</tr>
 	</table>
 


=== Packages/JobBoardEx/JobView.py 1.8 => 1.8.2.1 ===
 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,42 @@
         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')
+    
\ No newline at end of file