[Zope-CVS] CVS: Packages/JobBoardEx - edit.pt:1.1 preview.pt:1.1 review.pt:1.1 ApproveJobsView.py:1.6 JobCreateView.py:1.5 JobListView.pt:1.8 Tutorial.html:1.16 configure.zcml:1.2 ApproveJobs.pt:NONE JobCreateView.pt:NONE JobPreviewView.pt:NONE

Guido van Rossum guido@python.org
Mon, 17 Jun 2002 15:53:17 -0400


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

Modified Files:
	ApproveJobsView.py JobCreateView.py JobListView.pt 
	Tutorial.html configure.zcml 
Added Files:
	edit.pt preview.pt review.pt 
Removed Files:
	ApproveJobs.pt JobCreateView.pt JobPreviewView.pt 
Log Message:
Massive renaming of views, attributes, and templates, to be more consistent.
Sorry, Barry. :-(

=== Added File Packages/JobBoardEx/edit.pt ===
<html>
<head>
<title>Enter new job data</title>
</head>
<body>
<h1>Enter new job data</h1>

<p>When you are done, press the Preview button below.</p>

    <form action="preview.html" method="post">
    <table border=0>
    <tr><td>Summary:</td>
	<td><input name="summary" type="text" value="" size="72">
	</td>
    </tr>
    <tr><td colspan="2">
	<input type="submit" value="Preview">
	</td>
    </tr>
    </table>
    </form>

</body>
</html>


=== Added File Packages/JobBoardEx/preview.pt ===
<html>
<head>
<title>Preview new job data</title>
</head>

<body>

<h1>Preview New Job Data</h1>

<p>This is what your job would look like.  To change, use your
browser's Back button.  To submit, click on the Submit button below.

<hr>
  <h3>Job 123</h3>

  <table border=0>
  <tr><td>Summary:</td>
      <td tal:content="request/summary">The best job on the net</td>
  </tr>
  </table>
<hr>

    <form action="create.method" method="post">
	<input name="summary" type="hidden" value=""
               tal:attributes="value request/summary" />
	<input type="submit" value="Submit" />
    </form>

</body>
</html>


=== Added File Packages/JobBoardEx/review.pt ===
<html>
<head>
<title>Approve submitted jobs</title>
</head>
<body>

<h1>Approve Submitted Jobs</h1>

    <form action="approve.method" method="post">
    <table border=0>
    <tr><th colspan=3>Action</th>
        <th rowspan=2>Summary</th>
    </tr>
    <tr><th>Defer</th><th>Approve</th><th>Discard</th>
    </tr>
    <tr tal:repeat="jobid context/getPendingIds"
        style="text-align:center">
        <td><input type="radio" checked
                   tal:attributes="name jobid"></td>
        <td><input type="radio" value="approve"
                   tal:attributes="name jobid"></td>
        <td><input type="radio" value="discard"
                   tal:attributes="name jobid"></td>
        <td><a href="jobid" tal:attributes="href jobid">
	    <span tal:replace="context/?jobid/summary">A job summary
	    </span></a></td>
    </tr>
    <tr><td colspan="3">
        <input type="submit" value="Submit">
        <a href=".">Back to summary</a>
    </td></tr>
    </table>
    </form>

</body>
</html>


=== Packages/JobBoardEx/ApproveJobsView.py 1.5 => 1.6 ===
 class ApproveJobsView(BrowserView):
 
-    form = ViewPageTemplateFile('ApproveJobs.pt')
+    review = ViewPageTemplateFile('review.pt')
 
-    def action(self):
+    def approve(self):
         form = self.request.form
 
         for jobid in form:
@@ -22,4 +22,4 @@
             elif action == 'discard':
                 del self.context[jobid]
 
-        self.request.getResponse().redirect('approveForm.html')
+        self.request.getResponse().redirect('review.html')


=== Packages/JobBoardEx/JobCreateView.py 1.4 => 1.5 ===
 class JobCreateView(BrowserView):
 
-    form = ViewPageTemplateFile('JobCreateView.pt')
+    edit = ViewPageTemplateFile('edit.pt')
 
-    form2 = ViewPageTemplateFile('JobPreviewView.pt')
+    preview = ViewPageTemplateFile('preview.pt')
 
-    def action(self, submitter='', summary='', description='', contact=''):
+    def create(self, submitter='', summary='', description='', contact=''):
         # Validation code should go here
         job = Job(submitter, summary, description, contact)
         self.context.add(job)


=== Packages/JobBoardEx/JobListView.pt 1.7 => 1.8 ===
 <h1>Job Board</h1>
 
-<A href="createForm.html">Submit a new job</A>
+<A href="edit.html">Submit a new job</A>
 
 <H2>Job Listings</H2>
 
@@ -21,7 +21,7 @@
 
 <!-- XXX this should only appear if the user has the proper permissions -->
 <h2>Other operations</h2>
-<a href="approveForm.html">Approve submitted jobs</a>
+<a href="review.html">Approve submitted jobs</a>
 
 </BODY>
 </HTML>


=== Packages/JobBoardEx/Tutorial.html 1.15 => 1.16 ===
 
 <p>Most of the action for submitting and previewing a new job is in
-the page templates <a href="JobCreateView.pt">JobCreateView.pt</a> and
-<a href="JobPreviewView.pt">JobPreviewView.pt</a>, but unlike the
-default view for Job and JobList, there is also Python code involved,
-in the class <a href="JobCreateView.py">JobCreateView.py</a>.
+the page templates <a href="edit.pt">edit.pt</a> and <a
+href="preview.pt">preview.pt</a>, but unlike the default view for Job
+and JobList, there is also Python code involved, in the class <a
+href="JobCreateView.py">JobCreateView.py</a>.
 
 
 <h4>The JobCreateView class</h4>
 
-<p>This class has three attributes: the two forms, named form and
-form2, and a method action().  The argument list of the action()
+<p>This class has three attributes: the two forms, named edit and
+review, and a method create().  The argument list of the create()
 method deserves some attention: the four arguments are named for the
 corresponding fields in the request form.  When form sends its
-contents to the action() method using an HTTP request, Zope magically
+contents to the create() method using an HTTP request, Zope magically
 extracts the form field values from the request and passes them to the
 corresponding arguments.  In our example, all arguments have a default
 value of '', meaning that it's okay for a form field to be missing.
 If no default value is given to a method's argument, that means that
 the corresponding form field must be filled in; if it is not, Zope
 will issue an error and the method will not be called.  (This isn't
-generally sufficient for validation, of course; the action() method
+generally sufficient for validation, of course; the create() method
 would be the place to put your validation code.)
 
 <p>The JobCreateView class is derived from the BrowserView class.
@@ -286,16 +286,16 @@
 structure (an object that answers questions related to the HTTP
 request), and sets self.context to the "context object".  In our case,
 since the JobCreateView is a view on the JobList object, self.context
-is set to the JobList instance.  The essence of the action() method is
+is set to the JobList instance.  The essence of the create() method is
 in the two statements that create a new Job instance from the form
 fields, and calls the JobList's add() method to add it to the job
-list.  (The job id returned by add() is ignored here.)
+list.  The job id returned by add() is ignored here.
 
-<p>Finally, the action() method must send a response to the browser.
+<p>Finally, the create() method must send a response to the browser.
 There are different ways to do that.  The example uses a simple
 redirection that sends the browser back to the job list.
 
-<p>A more realistic action() method should include validation code,
+<p>A more realistic create() method should include validation code,
 e.g. checking that all fields are filled in, and perhaps attempting
 some syntactic checking on the submitter field (which should be a
 valid email address).
@@ -303,19 +303,19 @@
 
 <h4>Page Templates Used by JobCreateView</h4>
 
-<p>The page template <a href="JobCreateView.pt">JobCreateView.pt</a>
-contains the HTML form where employers edit the text for a job.  It's
-a straightforward HTML form that in fact contains no Page Template
-directives.  The action for this form is the next page template:
-
-<p>The page template <a href="JobCreateView.pt">JobCreateView.pt</a>
-shows a preview version of the job, before it is submitted.  You must
-click a button to submit it.  Here's how it works: in the top part of
-the page, the job data from the request form is rendered.  Page
-template directives reference the summary field in the request as
+<p>The page template <a href="edit.pt">edit.pt</a> contains the HTML
+form where employers edit the text for a job.  It's a straightforward
+HTML form that in fact contains no page template directives.  The
+action for this form is the next page template:
+
+<p>The page template <a href="preview.pt">preview.pt</a> shows a
+preview version of the job, before it is submitted.  You must click a
+button to submit it.  Here's how it works: in the top part of the
+page, the job data from the request form is rendered.  Page template
+directives reference the summary field in the request as
 "request/summary", and so on.  Below this, a form with hidden input
 fields and a visible Submit button is used to pass the field values
-from the request to the action() method.
+from the request to the create() method.
 
 
 <h4>Configuration Directives</h4>
@@ -329,9 +329,9 @@
               permission="Zope.ManageContent"
               >
 
-  &lt;browser:page name="createForm.html"  attribute="form" />
-  &lt;browser:page name="previewForm.html" attribute="form2" />
-  &lt;browser:page name="create"           attribute="action" />
+  &lt;browser:page name="edit.html"     attribute="edit" />
+  &lt;browser:page name="preview.html"  attribute="preview" />
+  &lt;browser:page name="create.method" attribute="create" />
 
 &lt;/browser:view>
 </pre>
@@ -341,6 +341,9 @@
 This view defines three different pages.  For each page, a page
 subdirective gives the name of the view (as seen by the browser) and
 the attribute of the JobCreateView class that implements this view.
+The view names are arbitrary; I chose to let them correspond to the
+attribute names, with a suffix ".html" for a page template and
+".method" for a method implemented in Python.
 
 
 <h4>Remarks</h4>
@@ -365,7 +368,7 @@
 controlling for you.  But it's inevitable that you must put
 <i>some</i> control code in your system, and it turns out that control
 code is typically highly coupled with view code; so it's cleaner to
-include the control code, such as the action() method, in the view
+include the control code, such as the create() method, in the view
 class.  Thus we end up with more of a view/controller.  The trick is
 not to give into the temptation to put all your logic in the view
 class, because doing so leads you down the Visual Basic path, which
@@ -385,8 +388,8 @@
               permission="Zope.ManageContent"
               >
 
-  &lt;browser:page name="approveForm.html" attribute="form" />
-  &lt;browser:page name="approve"          attribute="action" />
+  &lt;browser:page name="review.html"    attribute="review" />
+  &lt;browser:page name="approve.method" attribute="approve" />
 
 &lt;/browser:view>
 </pre>
@@ -399,44 +402,45 @@
 Zope.ManageContent).
 
 <p>The view has two attributes representing different pages of the
-view: one named form which the browser accesses as approveForm.html,
-and one named action which the browser accesses as approve.  Looking
-at the code, we see the same pattern as for JobCreateView: the form is
-a page template named <a href="ApproveJobs.pt">ApproveJobs.pt</a>, and
-action is a method.
+view: one named review which the browser accesses as review.html, and
+one named approve which the browser accesses as approve.method.  We
+use the same naming convention as for JobCreateView: the form is a
+page template named <a href="review.pt">review.pt</a>, and approve()
+is a method implemented in Python.
 
 <p>The page template used here contains a loop over all the job ids
-returned by the JobList method getPendingIds; this returns the ids of
-all jobs that are pending approval (let's hope there aren't thousands
-of these :-).  For each job id, a group of three radio buttons is
-rendered, followed by the job summary.  Page template substitutions
-are used to set the name attribute of the radio buttons to the job id.
-The value of the first radio button in each group is not specified;
-the HTML specification defines that if this button is checked (which
-it is by default) the value defaults to "on".  The other two radio
-buttons in the group specify "approve" and "discard" as their values,
-and this is what is sent to Zope when they are checked.  (Being radio
-buttons, at most one button in each group can be selected at any time;
-different groups are independent from each other.)
+returned by the JobList method getPendingIds(); this returns the ids
+of all jobs that are pending approval (let's hope there aren't
+thousands of these :-).  For each job id, a group of three radio
+buttons is rendered, followed by the job summary.  Page template
+substitutions are used to set the name attribute of the radio buttons
+to the job id.  The value of the first radio button in each group is
+not specified; the HTML specification defines that if this button is
+checked (which it is by default) the value defaults to "on".  The
+other two radio buttons in the group specify "approve" and "discard"
+as their values, and this is what is sent to Zope when they are
+checked.  (Being radio buttons, at most one button in each group can
+be selected at any time; different groups are independent from each
+other.)
 
 <p>When the Submit button at the bottom of the page is pressed, the
 selected value for each group of radio buttons is sent to to the
-action() method of the AppriveJobsView class.  (The browser sends it
-to the "approve" view, which is mapped to the "action" button by the
-configuration directives above.)  The action() method iterates over
-the keys of the form (which are of course the field names), ignoring
-keys that aren't the job id for an existing job.  Then for each valid
-job id, the value from the form is inspected, and the appropriate
-action is taken: to approve a job, its approve() method is called; to
-discard a job, it is deleted from the job list.  If the action code
-isn't either 'approve' or 'discard', nothing is done to the job, and
-it remains in the PendingApproval state.
-
-<p>Finally, the action() method directs the browser back to the view
-named approveForm.html.  As an aside, note that this means we can't
-just change the name of that form in the configuration directives and
-the page templates; we'd have to change it in the Python code for the
-action() method too.
+approve() method of the AppriveJobsView class.  (The browser sends it
+to the "approve.method" view, which is mapped to the "approve" button
+by the configuration directives shown above.)  The approve() method
+iterates over the keys of the form (which are of course the field
+names), ignoring keys that aren't the job id for an existing job.
+Then for each valid job id, the value from the form is inspected, and
+the appropriate action is taken: to approve a job, its approve()
+method is called; to discard a job, it is deleted from the job list.
+If the action code isn't 'approve' or 'discard', nothing is done to
+the job, and it remains in the PendingApproval state.
+
+<p>Finally, the approve() method directs the browser back to the view
+named review.html.  As an aside, note that this means we can't just
+change the name of that form in the configuration directives and the
+page templates; we'd have to change it in the Python code for the
+approve() method too.
 
 
 <h2>Page Templates</h2>


=== Packages/JobBoardEx/configure.zcml 1.1 => 1.2 ===
 <browser:view for=".IJobList."
               factory=".JobCreateView."
-              permission="Zope.ManageContent"
+              permission="Zope.Public"
               >
 
-  <browser:page name="createForm.html"  attribute="form" />
-  <browser:page name="previewForm.html" attribute="form2" />
-  <browser:page name="create"           attribute="action" />
+  <browser:page name="edit.html"     attribute="edit" />
+  <browser:page name="preview.html"  attribute="preview" />
+  <browser:page name="create.method" attribute="create" />
 
 </browser:view>
 
@@ -53,8 +53,8 @@
               permission="Zope.ManageContent"
               >
 
-  <browser:page name="approveForm.html" attribute="form" />
-  <browser:page name="approve"          attribute="action" />
+  <browser:page name="review.html"    attribute="review" />
+  <browser:page name="approve.method" attribute="approve" />
 
 </browser:view>
 

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

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

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