def get_item_by_id(username=None, slug=None, id=None): if username is None or slug is None or id is None: abort(404) blibb = Blibb.get_object({'u': username, 's': slug}) if blibb and is_valid_id(id): blibb_id = blibb['_id'] items = Blitem.get_item({'_id': ObjectId(id), 'b': ObjectId(blibb_id)}, {'i': 1, 'tg': 1, 'b': 1, 'c': 1} ) attributes = {'tags': True, 'comments': True} return jsonify(Blitem.flat_object(items, attributes)) else: return jsonify(Message.get('id_not_valid'))
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)