newbie - howto get a local javascript file to become a object in Zope
Hi First I would like to excuse those stupid questions, but allthough Im trying its hard to find the information elsewhere. I have a javascript file located at my local harddisk and I want it to become an object in zope. I have already tried to use manage_addFile, but it doesnt seem to find the file. In Zope mangement view its easy enough to create a txt-file and get it on working, but when I want to do the exact same thing in a Product created with Python, it just wont! So far I have also tried to find some other objects that I might use instead of manage_addFile, but havent succeded yet. any idears? Regards Danny Nielsen
On Sat, 2003-03-29 at 05:34, Danny wrote:
I have a javascript file located at my local harddisk and I want it to become an object in zope.
OK. Use the Add Product menu to make a new DTML Method, paste your JavaScript code in and save. JavaScript is just text as far as Zope is concerned. Zope doesn't treat it any differently than regular old markup. Any techniques you use for managing, formatting, and delivering text can be used with JavaScript.
In Zope mangement view its easy enough to create a txt-file and get it on working, but when I want to do the exact same thing in a Product created with Python, it just wont!
Well... products have no trouble using objects created in the ZMI. If you want to do this *without* adding an object to the ZMI, put the JavaScript code in a DTML file that gets associated with an interface in your product code. I'd also advise becomming pretty solid on Zope basics before taking on Products. It doen't make much sense to extend Zope until you have a pretty solid grasp of what's already available to you. HTH, Dylan
I have a javascript file located at my local harddisk and I want it to become an object in zope. I have already tried to use manage_addFile, but it doesnt seem to find the file. In Zope mangement view its easy enough to create a txt-file and get it on working, but when I want to do the exact same thing in a Product created with Python, it just wont!
So far I have also tried to find some other objects that I might use instead of manage_addFile, but havent succeded yet.
I'm mildly confused as to what you're trying to do here, and I suspect that's because you are too. If you want to simply create a single object in your ZODB containing the text of your javascript file, do it through the web as a File, selecting your js file for upload. Change the content type to text/plain or whatever MIME type Javascript might be, and you're done. I do this with CSS all the time. To add a File from python code, you must give it a fileish object or a string containing the contents as the 'file' parameter. That means that you must find the file via its path and create a Python file-ish object (usually by way of the built-in open() method) or read its contents into a string. This you can pass to manage_addFile. It won't deal with a path. Selecting the file and getting the data in the proper format is done automatically by your browser for the input type of 'file'. Outside it, you must do it yourself. If you're subclassing File (to make, say, a JavascriptFile) you'll have to write your own 'manage_addWhatever' function to be called from the web or other Products. It can be almost identical to manage_addFile, but you must call your new Product's class constructor, and not the File one. --jcc
participants (3)
-
Danny -
Dylan Reinhardt -
J Cameron Cooper