def read_csv(self, filename): file = open(os.path.join(os.path.dirname(__file__), "data", filename), 'r') reader = CSVReader(file, "comma", "utf-8") result = reader.read() file.close() return result
def spreadsheet_import(self, file, lang, dialect, encoding='utf-8'): """Imports translations from a spreadsheet format into the message catalog.""" from Products.NaayaCore.managers.import_export import CSVReader # read translations from spreadsheet file translations = CSVReader(file, dialect, encoding) translations = translations.read()[0] #result.read() is ([{id, source, target}], '') # iterate translations for translation in translations: #import only translated messages if translation['target'] != '': self._catalog.edit_message( translation['source'].decode(encoding), lang, translation['target'].decode(encoding))
def spreadsheet_import(self, file, lang, dialect, encoding='utf-8'): """Imports translations from a spreadsheet format into the message catalog.""" from Products.NaayaCore.managers.import_export import CSVReader # read translations from spreadsheet file translations = CSVReader(file, dialect, encoding) translations = translations.read()[ 0] #result.read() is ([{id, source, target}], '') # iterate translations for translation in translations: #import only translated messages if translation['target'] != '': self._catalog.edit_message( translation['source'].decode(encoding), lang, translation['target'].decode(encoding))
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())
def read_csv(self, filename): file = open(os.path.join(os.path.dirname(__file__), "data", filename), "r") reader = CSVReader(file, "comma", "utf-8") result = reader.read() file.close() return result