def no_date(): print "updating all without dates to queued" i = 0 couch.init(app.config) for doc in couch.PonyExpressMessage.no_date(limit=1200).all(): if doc.template == 'vp_shared': doc.delete() continue doc.status = 'queued' doc.save() i += 1 return 'Finished Processing %i orphans(s)' % i
def couch_sync(): couch_db = couch.init(app.config) path = os.getcwd() path = path.replace('/manage.py','') if not path: return "You must provide the path to PonyExpress" dir = '%s/ponyexpress/_design' % path print "Syncronizing Couchdb Views from %s" % dir loader = FileSystemDocsLoader(dir) loader.sync(couch_db, verbose=True)
def queue(): print "" print "Connecting to Couchdb..." couch.init(app.config) i = 0 for doc in couch.PonyExpressMessage.by_status(status='queued', limit=250).all(): i += 1 rs = {} try: pony = core.PonyExpress.from_couchdb(doc=doc) rs = pony.send(config=app.config) except Exception, e: print "Exception: %s" % e 'update status to failed' doc.status = 'failed' doc.save() if (rs or {}).get('result'): print "Success: %s" % doc._id else: print "Failed: %s" % doc._id
def to_couchdb(self, status='queued', save=True, config=None): """ Create a PonyExpressMessage document for couchdb logging or queue. """ self._message_doc = couch.PonyExpressMessage( status = status, date = datetime.datetime.now(), template = self._id, lang = self._lang, sender_address = self._sender_address, recipient_address = self._recipient_address, sender_name = self._sender_name, recipient_name = self._recipient_name, replacements = self._replacements, tags = self._tags or []) if save: # couchdb initialized? if not couch.couch_db: config = config or {} couch.init(config) self._message_doc.save() return self._message_doc
doc.save() return redirect(url_for('view_template', doc_id=doc._id)) @app.route('/list_templates') def list_templates(): view = couch.PonyExpressTemplate.view('ponyexpress/all_templates') return render_template('list_templates.html', results=view.all()) @app.route('/send', methods=['PUT']) def send(): """ RESTfull inteface to send messages """ if request.method == 'PUT': 'JSON expected' pony = core.PonyExpress.from_dict(request.json) rs = pony.send(config=app.config) return jsonify(rs) if __name__ == '__main__': # couchdb init couch_db = couch.init(app.config) # TODO - make the settings below CLI options app.run(host='0.0.0.0', port=4000)