def download(self, REQUEST=None, RESPONSE=None): """returns all the subscriptions in a csv file""" header = ['User', 'Location', 'Notification type', 'Language'] rows = [] for s in self.admin_get_subscriptions(): row = [] row.append(s['user']) if (s['location']): row.append(s['location']) else: row.append('entire portal') row.append(s['notif_type']) row.append(s['lang']) rows.append(row) file_type = REQUEST.get('file_type', 'CSV') if file_type == 'CSV': RESPONSE.setHeader('Content-Type', 'text/csv') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=subscriptions.csv') return generate_csv(header, rows) if file_type == 'Excel' and self.rstk['we_provide']('Excel export'): RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=subscriptions.xls') return generate_excel(header, rows) else: raise ValueError('unknown file format %r' % file_type)
def download(self, RESPONSE, search_string=u'', sort_by='', reverse_sort='False', file_type='CSV'): """returns all the search results in a csv or excel file""" reverse_sort = reverse_sort != 'False' users = self._search_users(search_string, sort_by, reverse_sort) if self.is_member(): header = ['Name', 'Organisation', 'Postal address', 'Email', 'Access level', 'User ID'] rows = [[user['name'], user['organisation'], user['postal_address'], user['email'], user['access_level'], user['userid']] for user in users] else: header = ['Name', 'Organisation'] rows = [[user['name'], user['organisation']] for user in users] if file_type == 'CSV': RESPONSE.setHeader('Content-Type', 'text/csv') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.csv' % self.id) return generate_csv(header, rows) elif file_type == 'Excel' and self.rstk.we_provide('Excel export'): RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.xls' % self.id) return generate_excel(header, rows) else: raise ValueError('unknown file format %r' % file_type)
def download(self, REQUEST=None, RESPONSE=None): """returns all the answers in a csv file""" def stringify(value): if not isinstance(value, basestring): value = unicode(value) if isinstance(value, str): return unicode(value, 'utf-8') return value def all_stringify(row): return [stringify(value) for value in row] answers = self.getAnswers() widgets = self.getSortedWidgets() header = ['Respondent'] for widget in widgets: header += [widget.title_or_id()] if widget.meta_type == 'Naaya Radio Matrix Widget': header += widget.rows rows = [answer.answer_values() for answer in answers] rows = [all_stringify(item) for item in rows] file_type = REQUEST.get('file_type', 'CSV') if file_type == 'CSV': RESPONSE.setHeader('Content-Type', 'text/csv') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.csv' % self.id) return generate_csv(header, rows) if file_type == 'Excel' and self.rstk.we_provide('Excel export'): RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.xls' % self.id) return generate_excel(header, rows) else: raise ValueError('unknown file format %r' % file_type)
def download(self, REQUEST=None, RESPONSE=None): """returns all the answers in a csv file""" def stringify(value): if not isinstance(value, basestring): value = unicode(value) if isinstance(value, str): return unicode(value, 'utf-8') return value def all_stringify(row): return [stringify(value) for value in row] answers = self.getAnswers() widgets = self.getSortedWidgets() header = ['Respondent'] for widget in widgets: header += [widget.title_or_id()] if widget.meta_type == 'Naaya Radio Matrix Widget': header += widget.rows rows = [answer.answer_values() for answer in answers] rows = [all_stringify(item) for item in rows] file_type = REQUEST.get('file_type', 'CSV') if file_type == 'CSV': RESPONSE.setHeader('Content-Type', 'text/csv') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.csv' % self.id) return generate_csv(header, rows) if file_type == 'Excel' and self.rstk.we_provide('Excel export'): RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.xls' % self.id) return generate_excel(header, rows) else: raise ValueError('unknown file format %r' % file_type)
def download(self, RESPONSE, search_string=u'', sort_by='', reverse_sort='False', file_type='CSV'): """returns all the search results in a csv or excel file""" reverse_sort = reverse_sort != 'False' users = self._search_users(search_string, sort_by, reverse_sort) if self.is_member(): header = [ 'Name', 'Organisation', 'Postal address', 'Email', 'Access level', 'User ID' ] rows = [[ user['name'], user['organisation'], user['postal_address'], user['email'], user['access_level'], user['userid'] ] for user in users] else: header = ['Name', 'Organisation'] rows = [[user['name'], user['organisation']] for user in users] if file_type == 'CSV': RESPONSE.setHeader('Content-Type', 'text/csv') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.csv' % self.id) return generate_csv(header, rows) elif file_type == 'Excel' and self.rstk.we_provide('Excel export'): RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.xls' % self.id) return generate_excel(header, rows) else: raise ValueError('unknown file format %r' % file_type)
def download(self, REQUEST=None, RESPONSE=None): """returns all the subscriptions in a csv file""" header = ['User', 'Location', 'Notification type', 'Language'] rows = [] for s in self.admin_get_subscriptions(): row = [] row.append(s['user']) if (s['location']): row.append(s['location']) else: row.append('entire portal') row.append(s['notif_type']) row.append(s['lang']) rows.append(row) file_type = REQUEST.get('file_type', 'CSV') if file_type == 'CSV': RESPONSE.setHeader('Content-Type', 'text/csv') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=subscriptions.csv') return generate_csv(header, rows) if file_type == 'Excel' and self.rstk['we_provide']('Excel export'): RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=subscriptions.xls') return generate_excel(header, rows) else: raise ValueError('unknown file format %r' % file_type)
def download(self, REQUEST=None, RESPONSE=None): """exports the participants listing in an excel file""" assert self.rstk.we_provide('Excel export') header = ['Name', 'User ID', 'Email', 'Organisation', 'Represented country', 'Reimbursed participation', 'Phone', 'Status', 'Last modified by', 'Reason for modification (when saved by an administrator)'] meeting = self.getMeeting() survey = self.get_survey() if meeting.survey_required and survey: survey_questions = [] for question in self.get_survey_questions(): survey_question = getattr(survey, question[0]) if survey_question.meta_type == 'Naaya Radio Matrix Widget': survey_questions.extend(survey_question.rows) else: survey_questions.append(question[1]) header.extend(survey_questions) rows = [] participants = self.getAttendees() for participant in participants: part_info = self.getAttendeeInfo(participant) participant_info = [ part_info['name'], part_info['uid'], part_info['email'], part_info['organization'], country_from_country_code.get(part_info['country'], ''), part_info['reimbursed'], part_info['phone'], part_info['role'], part_info['saved_by'], part_info['justification']] if meeting.survey_required and survey: survey_answers = [] for question in self.get_survey_questions(): survey_question = getattr(survey, question[0]) survey_answer = self.get_survey_answer(part_info['uid'], question[0]) if survey_answer is None: survey_answer = '-' if isinstance(survey_answer, basestring): survey_answers.append(survey_answer) else: survey_answers.extend(survey_answer) participant_info.extend(survey_answers) rows.append(participant_info) filename = '%s_%s_%s.xls' % (self.getMeeting().getId(), self.id, datetime.now().strftime( "%Y-%m-%d_%H-%M-%S")) RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % filename) return generate_excel(header, rows)
def download(self, REQUEST=None, RESPONSE=None): """exports the participants listing in an excel file""" assert self.rstk.we_provide('Excel export') header = ['Name', 'User ID', 'Email', 'Organisation', 'Phone', 'Status'] rows = [] participants = self.getAttendees() for participant in participants: part_info = self.getAttendeeInfo(participant) rows.append([part_info['name'], part_info['uid'], part_info['email'], part_info['organization'], part_info['phone'], part_info['role']]) RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s.xls' % self.id) return generate_excel(header, rows)
def export_email_list_xcel(site, cols, where_to_read="sent-bulk"): """Generate excel file with columns named after first value of tuples in cols, and the contets of the cells set by the key in the second value of the tuple in cols If key named exactly 'status' is present make a status check and include it in the resulting excel. """ emails = get_bulk_emails(site, where_to_read=where_to_read) header = [v[0] for v in cols] rows = [] check_status = True if "status" in [v[1] for v in cols] else False for email in emails: _prepare_xcel_data(email, site, check_status) r = [] for _, key in cols: r.append(email.get(key, "")) rows.append(r) r = import_export.generate_excel(header, rows) return r
def export_email_list_xcel(site, cols, where_to_read='sent-bulk'): """Generate excel file with columns named after first value of tuples in cols, and the contets of the cells set by the key in the second value of the tuple in cols If key named exactly 'status' is present make a status check and include it in the resulting excel. """ emails = get_bulk_emails(site, where_to_read=where_to_read) header = [v[0] for v in cols] rows = [] check_status = True if 'status' in [v[1] for v in cols] else False for email in emails: _prepare_xcel_data(email, site, check_status) r = [] for _, key in cols: r.append(email.get(key, '')) rows.append(r) r = import_export.generate_excel(header, rows) return r
def download(self, REQUEST=None, RESPONSE=None): """exports the participants listing in an excel file""" assert self.rstk.we_provide('Excel export') header = [ 'Name', 'User ID', 'Email', 'Organisation', 'Represented country', 'Reimbursed participation', 'Phone', 'Status', 'Last modified by', 'Reason for modification (when saved by an administrator)' ] meeting = self.getMeeting() if meeting.survey_required and self.get_survey(): header.extend( [question[1] for question in self.get_survey_questions()]) rows = [] participants = self.getAttendees() for participant in participants: part_info = self.getAttendeeInfo(participant) participant_info = [ part_info['name'], part_info['uid'], part_info['email'], part_info['organization'], country_from_country_code.get(part_info['country'], ''), part_info['reimbursed'], part_info['phone'], part_info['role'], part_info['saved_by'], part_info['justification'] ] if meeting.survey_required and self.get_survey(): survey_answers = [ self.get_survey_answer(part_info['uid'], question[0]) or '-' for question in self.get_survey_questions() ] participant_info.extend(survey_answers) rows.append(participant_info) filename = '%s_%s_%s.xls' % (self.getMeeting().getId( ), self.id, datetime.now().strftime("%Y-%m-%d_%H-%M-%S")) RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % filename) return generate_excel(header, rows)
def export_database(self): """ export the entire database to excel """ assert self.rstk.we_provide('Excel export') session = self._get_session() header = ['Author', 'Au', 'Id_unique', 'ImageID', 'Format', 'Form', 'Stock_Armoires', 'Sujet_tot', 'Nat-Parc', 'Topic', 'Ref_geo', 'No_collection', 'Sujet_bref', 'Esp_nom_com', 'Esp_nom_lat', 'Biome', 'V\xc3\xa9g\xc3\xa9tation', 'Paysage', 'Batiment', 'Personne', 'Altitude', 'Date', 'R\xc3\xa9f\xc3\xa9rence', 'Ref_ID_Local', 'Longitude', 'Latitude'] rows = [] try: documents = session.query( Document, Author, Image, Park, Biome, Vegetation)\ .filter(Author.authorid == Document.authorid)\ .filter(Image.imageid == Document.imageid)\ .filter(Park.parkid == Document.parkid)\ .filter(Biome.biomeid == Document.biomeid)\ .filter(Vegetation.vegetationid == Document.vegetationid) for document in documents: rows.append([check_encoding(document.Author.name), check_encoding(document.Author.code), check_encoding(document.Image.code), str(document.Image.imageid), check_encoding(document.Image.format), check_encoding(document.Image.form), check_encoding(document.Image.stock), check_encoding(document.Document.subject), check_encoding(document.Park.code), check_encoding(document.Document.topic), check_encoding(document.Document.ref_geo), check_encoding(document.Document.no_collection), check_encoding(document.Document.sujet_bref), check_encoding(document.Document.esp_nom_com), check_encoding(document.Document.esp_nom_lat), check_encoding(document.Biome.name), check_encoding(document.Vegetation.name), check_encoding(document.Document.paysage), check_encoding(document.Document.batiment), check_encoding(document.Document.personne), check_encoding(document.Document.altitude), check_encoding(document.Document.date), check_encoding(document.Document.reference), check_encoding(document.Document.ref_id_local), check_encoding(document.Document.longitude), check_encoding(document.Document.latitude) ]) except: raise finally: if session is not None: session.close() filename = 'apncb_photo_%s.xls' % datetime.now().strftime( "%Y-%m-%d_%H-%M-%S") self.REQUEST.RESPONSE.setHeader('Content-Type', 'application/vnd.ms-excel') self.REQUEST.RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % filename) return generate_excel(header, rows)