[Zope-dev] Re: ZCatalog
Jason Spisak
webmaster@mtear.com
Wed, 14 Jul 1999 17:56:22 -0800
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