def exportToHtml(response, records): template = Template(filename=settings.TEMPLATE_DIRS[0] + '/html_table_export.html') template.output_encoding = 'utf-8' html_text = template.render(params={'records': records}) response.write(html_text) return response
def exportToPdf(response, records): template = Template(filename=settings.TEMPLATE_DIRS[0] + '/html_table_export.html') template.output_encoding = 'utf-8' html_text = template.render(params={'records': records}) pdf = xhtml2pdf.CreatePDF(html_text, response) if not pdf.err: xhtml2pdf.startViewer(response) return response
def __scheduleGenericNotification(self, eventId, expressions): """Schedule email for any user who would wish to be notified of a notification.""" #first pick the template path that we are to use for building the email body cursor = self.connection.cursor() cursor.execute("SELECT template_path, from_email FROM event_type et INNER JOIN event e ON e.event_type_id = et.id WHERE e.id = %d" % eventId) record = cursor.fetchone() template = Template(filename=settings.APPLICATION_SETTINGS['COREAPP_HOME'] + record[0], input_encoding='utf-8') template.output_encoding = 'utf-8' params = {} params['from_email'] = record[1] params['subject'] = 'Creche Parentale Notification' params['scheduled_for_relay'] = True params['event_id'] = eventId params['last_updated'] = datetime.now() params['date_created'] = datetime.now() cursor.execute(""" SELECT wu.mail, wud.full_name FROM web_users wu INNER JOIN system_user_has_event_type suhet ON suhet.system_user_id = wu.uid INNER JOIN web_user_detail wud ON wud.user_id = wu.uid INNER JOIN event_type et ON suhet.event_type_id = et.id WHERE et.id = %d""" % expressions['event_type_id']) subscribers = cursor.fetchall() for user in subscribers: recipient = 'User' if user[1]: recipient = user[1] expressions['recipient'] = recipient params['message_body'] = template.render(params=expressions)#message to be relayed to the subscribers params['to_email'] = user[0] fields = ', '.join(params.keys()) values = ', '.join(['%%(%s)s' % x for x in params]) query = 'INSERT INTO email_schedule (%s) VALUES (%s)' % (fields, values) cursor.execute(query, params) cursor.close() return params