def create_app(config_name=None, **kwargs): """ Entry point to the Flask RESTful Server application. """ from app.products.views import products_api connexion_app = connexion.FlaskApp(__name__, specification_dir='openapi/', **kwargs) app = connexion_app.app try: app.config.from_object(get_config(config_name)) except ImportError: raise Exception('Invalid Config') connexion_app.add_api('products-api-docs.yaml', resolver=RestyResolver('products')) app.register_blueprint(products_api, url_prefix='/v1.0/api/products/') managet = CouchDBManager() managet.add_document(Products) managet.setup(app) flask_injector.FlaskInjector(app=app, modules=INJECTOR_DEFAULT_MODULES.values()) app.run(port=8080) return app
message = TextField() author = TextField() time = DateTimeField(default=datetime.datetime.now) all = ViewField('guestbook', ''' function (doc) { if (doc.doc_type == 'signature') { emit(doc.time, doc); }; }''', descending=True) manager = CouchDBManager() manager.add_document(Signature) manager.setup(app) # views @app.route('/') def display(): page = paginate(Signature.all(), 5, request.args.get('start')) return render_template('display.html', page=page) @app.route('/', methods=['POST']) def post(): message = request.form.get('message') author = request.form.get('author') if not message or not author: flash("You must fill in both a message and an author")
if (doc.the_doc_type == 'app_code_clone_user') { emit(doc.user_email, doc._id) }; } ''') from flask import current_app as app app = Flask(__name__) app.config.update(COUCHDB_SERVER='http://*****:*****@app_code_clone.route('/cloneCognition') def cloneCognition(): return render_template('index_cloneValidationFramework.html')
from flask import render_template, jsonify, request, g, redirect, url_for, flash from app import app from flaskext.couchdb import CouchDBManager, Document, TextField, DateField, BooleanField from werkzeug.local import LocalProxy manager = CouchDBManager() #instantiate manager.setup(app) #start class NewBooking(Document): #class for interrogating CouchDB book_name = TextField() book_email = TextField() book_date = TextField() book_time = TextField() book_confirmation = BooleanField(default=False) class approvedBooking(Document): #class for interrogating CouchDB book_name = TextField() book_email = TextField() book_date = TextField() book_time = TextField() book_confirmation = BooleanField(default=False)
app.config.from_object(__name__) app.config.update( dict(COUCHDB_DATABASE="insults", COUCHDB_SERVER="http://localhost:5984", RIEMANN_ADDRESS="localhost:5555", BASE_URL="http://localhost:5000", STATSD_ADDRESS="localhost:8125")) app.config.from_envvar('APP_CONFIG_FILE', silent=True) api = swagger.docs(flask_restful.Api(app), apiVersion="1.0.0", basePath=app.config['BASE_URL']) # couchdb setup couchdb_manager = CouchDBManager(auto_sync=False) couchdb_manager.setup(app) riemann_client = riemann.get_client(app.config['RIEMANN_ADDRESS'], tags=[__version__]) statsd_client = metrics.statsd_client(app.config['STATSD_ADDRESS']) app.wsgi_app = riemann.wsgi_middelware( metrics.statsd_wsgi_middelware(app.wsgi_app, statsd_client), riemann_client) #app.before_first_request(init) # get a timer decorator with riemann client pre-injected timed = partial(metrics.TimerDecorator, [riemann_client.riemann_timer_reporter, statsd_client.timing]) if not app.debug:
class NewsInvestigatorDatabase(object): '''A NewsInvestigatorDatabase object.''' def __init__(self, app): ''' Create a new NewsInvestigator object, with the given Flask app settings. ''' self._manager = CouchDBManager() self._manager.setup(app) def _save_document(self, id, document, doc_type): ''' Save the document into the database. ''' document['doc_type'] = doc_type g.couch[id] = document g.couch.save(document) def retrieve_results(self, query): ''' Retrieve the results of a user generated query. ''' return g.couch.query(query) def get_view(self, name): ''' Grab the results of a predefined view. ''' return g.couch.view(name) def save_news_source(self, id, document): ''' Save a news source to the database. ''' self._save_document('news_source_' + id, document, 'news_source') def save_keyword(self, id, document): ''' Save a keyword to the database. ''' self._save_document('keyword_' + id, document, 'keyword') def save_handle(self, id, document): ''' Save a handle to the database. ''' self._save_document('handle_' + id, document, 'handle') def save_tweet(self, id, document): ''' Save a tweet to the database. ''' self._save_document('tweet_' + id, document, 'tweet') def save_site(self, id, document): ''' Save a site to the database. ''' self._save_document('site_' + id, document, 'site') def save_domain(self, id, document): ''' Save a domain to the database. ''' self._save_document('domain_' + id, document, 'domain') def delete_document(self, id): ''' Delete a document, given the id. ''' document = g.couch[id] g.couch.delete(document)
@property def imgsrc(self): return uploaded_photos.url(self.filename) all = ViewField('Citizen Sensor', '''\ function (doc) { if (doc.doc_type == 'post') emit(doc.published, doc); }''', descending=True) db.add_document(Post) db.setup(app) # utils def to_index(): return redirect(url_for('index')) @app.before_request def login_handle(): g.logged_in = bool(session.get('logged_in')) # views @app.route('/') def index():
app.config.update(dict( COUCHDB_DATABASE="insults", COUCHDB_SERVER="http://localhost:5984", RIEMANN_ADDRESS="localhost:5555", BASE_URL="http://localhost:5000", STATSD_ADDRESS="localhost:8125" )) app.config.from_envvar('APP_CONFIG_FILE', silent=True) api = swagger.docs(flask_restful.Api(app), apiVersion="1.0.0", basePath=app.config['BASE_URL']) # couchdb setup couchdb_manager = CouchDBManager(auto_sync=False) couchdb_manager.setup(app) riemann_client = riemann.get_client(app.config['RIEMANN_ADDRESS'], tags=[__version__]) statsd_client = metrics.statsd_client(app.config['STATSD_ADDRESS']) app.wsgi_app = riemann.wsgi_middelware( metrics.statsd_wsgi_middelware(app.wsgi_app, statsd_client), riemann_client ) #app.before_first_request(init) # get a timer decorator with riemann client pre-injected timed = partial(metrics.TimerDecorator, [riemann_client.riemann_timer_reporter, statsd_client.timing]) if not app.debug: app.logger.addHandler(logging.StreamHandler())