def afterSetUp(self): self.portal.manage_install_pluggableitem('Naaya Contact') from Products.Naaya.NyFolder import addNyFolder from naaya.content.contact.contact_item import addNyContact addNyFolder(self.portal, 'myfolder', contributor='contributor', submitted=1) addNyContact(self.portal.myfolder, id='mycontact', title='My contact', submitted=1, contributor='contributor') import transaction; transaction.commit()
def test_export_contact(self): addNyContact(self.test_folder, id="important_contact", title="Important contact") export_value = self.test_folder.zip_export.do_export() zip = ZipFile(export_value, "r") self.assertEqual(sorted(zip.namelist()), sorted(["index.txt", "zip_export_folder/Important contact.vcf"])) vcard_content = zip.read("zip_export_folder/Important contact.vcf") self.assertTrue("BEGIN:VCARD" in vcard_content) self.assertTrue("Important contact" in vcard_content) self.assertTrue("END:VCARD" in vcard_content)
def test_export_geotype(self): toexport = self.portal['toexport'] addNyContact(toexport, id='contact1', title='Contact 1', contributor='contributor') toexport['contact1'].test_geo_type = 'sym1' csv_output = toexport.csv_export.export(meta_type='Naaya Contact') csv_lines = csv_output.strip().split('\n') self.assertEqual(len(csv_lines), 2) # header line and one object csv_data = dict(zip(*(line.split(',') for line in csv_lines))) self.assertEqual(csv_data['Geo Type'], 'Test symbol one')
def test_export_contact(self): addNyContact(self.test_folder, id="important_contact", title='Important contact') export_value = self.test_folder.zip_export.do_export() zip = ZipFile(export_value, 'r') self.assertEqual(sorted(zip.namelist()), sorted(['index.txt', 'zip_export_folder/important_contact.vcf'])) exported_vcard_content = \ zip.read('zip_export_folder/important_contact.vcf') self.assertTrue('BEGIN:VCARD' in exported_vcard_content) self.assertTrue('Important contact' in exported_vcard_content) self.assertTrue('END:VCARD' in exported_vcard_content)
def test_export_geolocation(self): toexport = self.portal['toexport'] addNyContact(toexport, id='contact1', title='Contact 1', contributor='contributor') toexport['contact1'].test_geo_loc = Geo('13.45', '22.60', 'somewhere') csv_output = toexport.csv_export.export(meta_type='Naaya Contact') csv_lines = csv_output.strip().split('\n') self.assertEqual(len(csv_lines), 2) # header line and one object csv_data = dict(zip(*(line.split(',') for line in csv_lines))) self.assertEqual(csv_data['Geo Loc - lat'], '13.45') self.assertEqual(csv_data['Geo Loc - lon'], '22.60') self.assertEqual(csv_data['Geo Loc - address'], 'somewhere')
def test_export_geotype(self): toexport = self.portal['toexport'] addNyContact(toexport, id='contact1', title='Contact 1', contributor='contributor') toexport['contact1'].test_geo_type = 'sym1' csv_output = toexport.csv_export.export(meta_type='Naaya Contact') csv_lines = csv_output.strip().split('\n') self.assertEqual(len(csv_lines), 2) # header line and one object csv_data = dict(zip(*(line.split(',') for line in csv_lines))) self.assertEqual(csv_data['Geo Type'], 'Test symbol one')
def test_export_contact(self): addNyContact(self.test_folder, id="important_contact", title='Important contact') export_value = self.test_folder.zip_export.do_export() zip = ZipFile(export_value, 'r') self.assertEqual( sorted(zip.namelist()), sorted(['index.txt', 'zip_export_folder/Important contact.vcf'])) vcard_content = zip.read('zip_export_folder/Important contact.vcf') self.assertTrue('BEGIN:VCARD' in vcard_content) self.assertTrue('Important contact' in vcard_content) self.assertTrue('END:VCARD' in vcard_content)
def test_export_geolocation(self): toexport = self.portal['toexport'] addNyContact(toexport, id='contact1', title='Contact 1', contributor='contributor') toexport['contact1'].test_geo_loc = Geo('13.45', '22.60', 'somewhere') csv_output = toexport.csv_export.export(meta_type='Naaya Contact') csv_lines = csv_output.strip().split('\n') self.assertEqual(len(csv_lines), 2) # header line and one object csv_data = dict(zip(*(line.split(',') for line in csv_lines))) self.assertEqual(csv_data['Geo Loc - lat'], '13.45') self.assertEqual(csv_data['Geo Loc - lon'], '22.60') self.assertEqual(csv_data['Geo Loc - address'], 'somewhere')
def addNyContact_market(self, id='', REQUEST=None, contributor=None, **kwargs): """ Create a Contact type of object in 'market-place' folder adding * extra validation for topics and target-groups * pointers in the selected topics and target-groups """ schema_raw_data = dict(REQUEST.form) topics = schema_raw_data.get("topics", []) if not topics: # unfortunately we both need _prepare_error_response # (on NyContentData) and methods for session (by acquisition) ob = NyContact('', '').__of__(self) form_errors = {'topics': ['Please select at least one Topic']} ob._prepare_error_response(REQUEST, form_errors, schema_raw_data) REQUEST.RESPONSE.redirect('%s/market_place_contact' % self.absolute_url()) return response = contact_item.addNyContact(self.restrictedTraverse('market-place'), '', REQUEST) if isinstance(response, NyContact): REQUEST.RESPONSE.redirect(response.absolute_url()) pass # Contacts are now redirected from post-add event else: # we have errors REQUEST.RESPONSE.redirect('%s/market_place_contact' % self.absolute_url())
def addNyContact_market(self, id='', REQUEST=None, contributor=None, **kwargs): """ Create a Contact type of object in 'market-place' folder adding * extra validation for topics and target-groups * pointers in the selected topics and target-groups """ schema_raw_data = dict(REQUEST.form) topics = schema_raw_data.get("topics", []) if not topics: # unfortunately we both need _prepare_error_response # (on NyContentData) and methods for session (by acquisition) ob = NyContact('', '').__of__(self) form_errors = {'topics': ['Please select at least one Topic']} ob._prepare_error_response(REQUEST, form_errors, schema_raw_data) REQUEST.RESPONSE.redirect('%s/market_place_contact' % self.absolute_url()) return response = contact_item.addNyContact( self.restrictedTraverse('market-place'), '', REQUEST) if isinstance(response, NyContact): REQUEST.RESPONSE.redirect(response.absolute_url()) pass # Contacts are now redirected from post-add event else: # we have errors REQUEST.RESPONSE.redirect('%s/market_place_contact' % self.absolute_url())
def afterSetUp(self): self.portal.manage_install_pluggableitem('Naaya Contact') from naaya.content.contact.contact_item import addNyContact addNyContact(self.portal.info, id='ver_contact', title='ver_contact', submitted=1) import transaction; transaction.commit()
def add_object(self, parent): parent.getSite().manage_install_pluggableitem('Naaya Contact') ob = parent[addNyContact(parent, title='My contact')] ob.approveThis() return ob
def import_contacts_from_csv(self, file=None, dialect='comma', encoding='utf-8', location='', REQUEST=None): """Bulk import of Naaya Contacts from a CSV file""" e = [] if not location: e.append('You must specify a location.') if location == '/': location = '' if file: content = CSVReader(file=file, dialect=dialect, encoding=encoding) content = content.read()[0] if content == None: self.setSessionErrorsTrans("File encoding doesn't match selected encoding.") return self.REQUEST.RESPONSE.redirect('%s/admin_contacts_html?section=import' % self.absolute_url()) if not file: e.append('You must specify a file.') if e and REQUEST is not None: self.setSessionErrorsTrans(e) return self.REQUEST.RESPONSE.redirect('%s/admin_contacts_html?section=import' % self.absolute_url()) lang = self.gl_get_selected_language() location = self.unrestrictedTraverse(location) for contact in content: #contact base data title = contact.get('Title', '') first_name = contact.get('First name', '') last_name = contact.get('Last name', '') if not title: if first_name or last_name: title = '%s %s' % (first_name, last_name) else: title = title = self.utGenRandomId(6) description = contact.get('Description', '') coverage = contact.get('Coverage', '') keywords = contact.get('Keywords', '') personaltitle = contact.get('Personal title', '') firstname = contact.get('First name', '') lastname = contact.get('Last name', '') jobtitle = contact.get('Job title', '') department = contact.get('Department', '') organisation = contact.get('Organisation', '') postaladdress = contact.get('Postal address', '') phone = contact.get('Phone', '') fax = contact.get('Fax', '') cellphone = contact.get('Cell phone', '') email = contact.get('Email', '') webpage = contact.get('Webpage', '') contact_id = addNyContact(location, title=title, description=description, coverage=coverage, keywords=keywords, personaltitle=personaltitle, firstname=firstname, lastname=lastname, jobtitle=jobtitle, department=department, organisation=organisation, postaladdress=postaladdress, phone=phone, fax=fax, cellphone=cellphone, email=email, webpage=webpage) if REQUEST is not None: self.setSessionInfoTrans('Contacts successfully imported.') return self.REQUEST.RESPONSE.redirect('%s/admin_contacts_html' % self.absolute_url())