[Zope] Accessing DOM nodes from python: how?
Passin, Tom
tpassin@mitretek.org
Mon, 23 Dec 2002 09:39:19 -0500
[Catonano]=20
> We have a folder with a bunch of html files in it.
>=20
> What I want to do is to make a drop down menu filled with some values.
>=20
> Each one of these values individuates one of the files in the folder.
>=20
> If I, as user, choose a code from the drop down menu, it=20
> should take me=20
> to the associated file (web page, that is).
>=20
> The files are not dinamically produced by Zope, they are simple=20
> statical html files made by some collagues of mine with=20
> DreamWeaver and=20
> uploaded via ftp into my folder.
>=20
So the files are located in the file system and not in the Zope
database. I would search the archives for the "localFS" product, and
see how to get it to give you a list of the file names it controls.
Then you can refer to them by title.
> I could ask my collagues to include the code in every page=20
> (file) in a=20
> html-compliant shape, so Zope could acces that code and=20
> CATALOGUE those=20
> pages indexing that code, so I could try with a multiple choiche menu.
>=20
> Is it clearer?
>=20
Do you mean that each file is supposed to be tagged with some code, and
that the file name is not adequate for listing in a menu?
Seems like you have three types of things you can do to discover the
code value:
1) Put the code into the filename and use string processing to extract
it. This requires the the people producing the file name the file
correctly.
2) Put the code into the html file itself. The best place for this
would be a <meta> element. This requires you to extract the code value
from the HTML file as you started out asking about. It also requires
the people generating the file to insert the code value correctly.
This approach is the most markup-language like approach.
If you put it into a META element, you ought to be able to retrieve it
using a regular expression. That would probably be the simplest thing
to do. You would probably do that using a python external method.
3) Compute the right code value usng some algorithm. I have no idea if
that would be possible for your files or not. If it is possible, you
would not depend on the file creator to handle the code properly.
Once you know what the code value is, you want to use it somehow. That
is the subject of your next questions, I take it -
> My idea is that I have 2 alternative ways:
>=20
> 1) add a field property to each file and fill it with the code, then=20
> adding an index to my ZCatalog. Boring, error prone and time=20
> consuming.
>=20
> 2) ask my collagues to inclue the codes in the html files and=20
> get Zope=20
> access and index that values.
>=20
Another approach would be to create a DTML method that returns a
dictionary of code file identifiers keyed by the codes. You would use
that dictionary when you build the menu. I have never done this
programatically but it ought to be possible. Otherwise, you could write
an external method to do the same thing by reading a file that contains
the dictionary in text form (you create the dictionary by using eval()).
When you receive a new file (or periodically using a scheduled task) you
would look through the directory and build a new version of the
dictionary. It ought to be easy.
Cheers,
Tom P