def publish_default(cls, template_id): html_read = '' html_write = '' table_head = '' row = '<tr>' html_table = read_file('/scripts/templates/base/table.html') if is_valid_id(template_id): template = cls.get_by_id(template_id) # get controls controls = template.get('controls') if controls: for control in controls: c = cls.flaf_control(control) html = cls.get_html(c) html_read += html.get('read', '') html_write += html.get('write', '') table_head += '<th>' + c['name'] + '</th>' row += '<td>{{{' + c['slug'] + '}}}</td>' html_table = html_table.replace( '<blibb:entry value="labels"/>', table_head) html_table = html_table.replace('<blibb:entry/>', row) res = dict() data = dict() data['entry'] = html_read res['ri'] = parse_text(html_read) res['rb'] = parse_text(cls.get_blibb_template_wrapper(data)) res['wb'] = parse_text(html_write) box = {'name': 'default', 'view': res} cls.publish(box, template_id) table_dict = dict() table_dict['ri'] = parse_text('<td>{{' + c['slug'] + '}}</td>') table_dict['rb'] = parse_text(html_table) table = {'name': 'table', 'view': table_dict} return cls.publish(table, template_id) return False
def send_message(): blitem_id = request.form['id'] transaction = request.form['transaction'] app_token = request.form['app_token'] if is_valid_id(blitem_id): blitem = Blitem.get({'_id': ObjectId(blitem_id), 'i.v': transaction}) if blitem: flat = Blitem.flat_object(blitem) current_app.logger.info(flat) template = read_file('/bsm/templates/mysecretvalentine.html') html_mail = template.decode('utf-8') html_mail = html_mail.replace("*|IMAGE|*", flat['url']) # html_mail = html_mail.replace("*|URL|*", 'http://blibb.net/go/' + flat['url_id']) html_mail = html_mail.replace("*|MESSAGE|*", flat['message']) mail = { 'to_address': flat['to'], 'from_name': 'Your Secret Valentine', 'from': '*****@*****.**', 'subject': 'Your Secret Valentine', 'txt_body': flat['message'], 'html_body': html_mail } print 'Mail sent to ' + mail['to_address'] sendgrid_user = get_config_value('SENDGRID_USER') sendgrid_password = get_config_value('SENDGRID_PASSWORD') s = sendgrid.Sendgrid(sendgrid_user, sendgrid_password, secure=True) message = sendgrid.Message((mail['from'], mail['from_name']), mail['subject'], mail['txt_body'], mail['html_body']) message.add_to(mail['to_address'], '') s.web.send(message) # return jsonify({'return': 'success'}) return html_mail abort(401) abort(400)
def get_blibb_template_wrapper(self, data): html = read_file('/scripts/templates/base/base.html') return html.replace('<blibb:entry/>', data['entry'])