[Zope] Two hairy questions

Kevin Dangoor kid@kendermedia.com
Sun, 17 Oct 1999 16:33:20 -0400


Hi, Samu

    Sorry I haven't been more helpful lately, but I've been too busy to
answer in depth questions. I do have some advice for you below... Liz
Pelletier is correct in her other message that KM|Net News would serve as a
better example if it was documented.

-----Original Message-----
From: Samu Mielonen <ex@uiah.fi>
To: Zope Mailing List <zope@zope.org>
Date: Sunday, October 17, 1999 3:11 PM
Subject: [Zope] Two hairy questions


>The hierarchy of my ArticleStore is as follows:
>
>News
>   add.html (submit form)
>   AddArticle (dtml-method to handle form submit and save contents)
>   1999 (year for article's submit date)
>     10 (month for article's submit date)
>       #article1_id (unique_id of article)
>      index.html   (view the article contents)
>           edit (form to edit article, sends results to postit)

Note that "sends results to postit" is key here...

>           postit (dtml-method to APPROVE article for publication)
>       #article2_id
>       ...
>
>The problem is that I do not understand from the code what postit
>does so that the article becomes visible for the publishing methods,
>but I do know that untill I put the article object through postit-method
>it won't be approved and ready for publishing (for those who know
>KM|NetNews, I've usen the property current to denote approval).

Basically, the "edit" and "postit" methods are similar to the standard
"manage" screen for a propertysheet and "manage_changeProperties"
respectively. The "edit" form lets the user set a whole bunch of information
about the article. These responses show up in the REQUEST variable.
(Specifically, in REQUEST.form, since they are the result of form input).

Here is postit (a version that has a bug fixed since the current release
version):
<dtml-call "REQUEST.set('score', 2000000000-(_.int(REQUEST['release']) +
8640*REQUEST['importance']))">
<dtml-if "not REQUEST.form.has_key('top')">
  <dtml-call "REQUEST.set('top', 'off')">
</dtml-if>
<dtml-if "not REQUEST.form.has_key('current')">
  <dtml-call "REQUEST.set('current', 'off')">
</dtml-if>
<dtml-call "propertysheets.artinfo.manage_changeProperties(REQUEST)">
<dtml-call reindex_object>
<dtml-var index.html>

Basically, this sets the "score" value based on the release and importance
values. This is how sorting is done. Then, it checks the form for "top" and
"current", since these are checkboxes and nothing is returned if the
checkbox is not checked. A call to manage_changeProperties does the actual
change, a call to reindex_object applies the changes to the Catalog and then
the article is previewed by calling index.html.

If you want to make a method (let's say "approve") to do nothing but set the
current property, all you need to do is make approve look like this:

<dtml-call "propertysheets.artinfo.manage_changeProperties({'current':
'on'})">
<dtml-call reindex_object>
<dtml-call index.html>

This method will set the current property, reindex the object and preview
the article.

>Anyway, I want the AddArticle method to PREVIEW a submitted article
>(that was sent through the add.html form). This is easy. I can
>call article's own index.html from within Addarticle and it is rendered
>visible.
>
>But here I bumb into my first problem. Even though I go into the
>article's folder with <dtml-with> and am able to display the
>articles text-properties (heading, body text, importance) ok,
>I can't display pictures.
>
><dtml-with "_[_.str(tsyear)]">
> <dtml-with "_[_.str(tsmonth)]">
>  <dtml-with "_[_.str(uniqueID)]">
>
>   <dtml-var index.html>
>
>  </dtml-with>
> </dtml-with>
></dtml-with>
>
>For some reason, the index.html than renders the images just with
><img src="image_name"> does not understand that it should render
>the images in that specific folder from which it is called.

In this instance, Zope knows that you're called index.html in the context of
the KMArticle object. However, the *browser* thinks you're working in the
context of /art (or whatever your KMArticleStore instance is called). So,
when you say <img src="image_name">, the browser is going to look up
/art/image_name. When index.html is referenced from postit, it is being
referenced from /art/1999/10/92831723/postit... so, <img src="image_name">
to the browser seems like: /art/1999/10/92831723/image_name.

Perhaps a better way to preview from AddArticle would be to redirect to the
article page:
within
   <dtml-with "_[uniqueID]">
put
      <dtml-call "RESPONSE.redirect(absolute_url())">

>Also, when I finally try approve an article from the
>AddArticle method by displaying a link that calls
>
> http://mydomain/1999/10/somearticleid/postit
>
>in order "to do the thing" to get article approved, I
>can't somehow pass the current article object to
>postit, so that it would know what article to handle.

It actually does know which article you're dealing with, because you are
specifically calling the "postit" method on the KMArticle instance at
1999/10/somearticleid. But, postit is designed to take input from "edit".
So, it's looking for "release" and "importance" and trying to set a "score"
and such. You could make an approve method like I describe above and call it
like this:
http://mydomain/1999/10/somearticleid/approve


I hope this helps!

Kevin