-----Original Message----- From: Jason Spisak [mailto:webmaster@mtear.com] Sent: Wednesday, July 14, 1999 5:45 PM To: Michel Pelletier Cc: zope-dev@zope.com Subject: Re: ZCatalog
Michel,
I'm using the following external method because without it the Catalog won't let an object index itself. It's the one you sent me, but I get a NameError when I call urllib. Is there a special import I have to do to get access to urllib? Just out of curiousity(mostly because I know very little python), why return a script_name based url.
yes sorry, you'll need to import urllib and string. This is the method we use to catalog our objects in the Portal Tool Kit. -Michel
def url(self, ftype=urllib.splittype, fhost=urllib.splithost): """Return a SCRIPT_NAME-based url for an object.""" if hasattr(self, 'DestinationURL') and \ callable(self.DestinationURL): url='%s/%s' % (self.DestinationURL(), self.id) else: url=self.absolute_url() type, uri=ftype(url) host, uri=fhost(uri) script_name=self.REQUEST['SCRIPT_NAME'] __traceback_info__=(`uri`, `script_name`) if script_name: uri=filter(None, string.split(uri, script_name))[0] uri=uri or '/' if uri[0]=='/': uri=uri[1:] return uri
All my best,
Jason Spisak webmaster@mtear.com
Michel, That should have been obvious to me. Sorry. ;) It works fine now. But I am having trouble with my old import scripts which worked wonderous with Zope 1.10. Is self.manage_addProduct['meta_type'].add, still a valid way to call a DTML constructor? It reads the file fine but just fails to add them. This is the external method that isn't working: import string def import_company(self,file,REQUEST,RESPONSE,URL2): """ External Method to import Company data and build Company objects. file is a tab delimited file object (obtained from a file upload form). The file schema is: ID,COMPANY,FIRST_NAME,LAST_NAME,ADDRESS,CITY,STATE,ZIP,AREA_CODE, FAX_AREA_CODE,PHONE,FAX_PHONE,EXT,FAX_EXT,TITLE,USER1,USER2,USER3 USER4,USER5,USER6,E-MAIL """ added=[] failed=[] contact_id=10000 while 1: line=file.readline() if line=="": break fields=string.split(line,'\t') id=fields[0] name=fields[1] address=fields[4] environment="%s %s %s %s %s %s" % (fields[15], fields[16], fields[17], fields[18], fields[19], fields[20]) city=fields[5] state=fields[6] zip=fields[7] first_name=fields[3] if id=='ID': # bogus first line continue try: if id not in added: # add company REQUEST.set('id',id) REQUEST.set('company_name',name) REQUEST.set('company_address',address) REQUEST.set('company_city',city) REQUEST.set('company_state',state) REQUEST.set('company_zip',zip) REQUEST.set('environment',environment) REQUEST.set('main_area_code',fields[8]) REQUEST.set('main_phone',fields[10]) method=self.manage_addProduct['CompanyType'].add method(method,REQUEST=REQUEST,RESPONSE=RESPONSE, DestinationURL=lambda url=URL2: url) added=added+[id] # add contact inside company if first_name: contact_id=contact_id+1 REQUEST.set('id',str(contact_id)) REQUEST.set('first_name',fields[2]) REQUEST.set('last_name',fields[3]) REQUEST.set('area_code',fields[8]) REQUEST.set('phone',fields[10]) REQUEST.set('extension',fields[12]) REQUEST.set('fax_area_code',fields[9]) REQUEST.set('fax_phone',fields[11]) REQUEST.set('fax_extension',fields[13]) REQUEST.set('title',fields[14]) REQUEST.set('email_address',fields[21]) company=getattr(self,id) method=company.manage_addProduct['ContactType'].add method(method,REQUEST=REQUEST,RESPONSE=RESPONSE, DestinationURL=lambda url=URL2+'/'+id: url) except: failed.append(name) return """<html> <p>Added %d companies.</p> <p>Failed to add: <br> %s </p> </html>""" % (len(added), string.join(failed,"<br>")) Thanks again, Jason Spisak webmaster@mtaer.com
participants (2)
-
Jason Spisak -
Michel Pelletier