Exemplo n.º 1
0
 def __init__(self, app):
     '''
     Create a new NewsInvestigator object, with the given 
     Flask app settings.
     '''
     self._manager = CouchDBManager()
     self._manager.setup(app)
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
COUCHDB_DATABASE = 'flask-photolog'

# application

app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('PHOTOLOG_SETTINGS', silent=True)

# uploads

uploaded_photos = flask_uploads.UploadSet('photos', flask_uploads.IMAGES)
flask_uploads.configure_uploads(app, uploaded_photos)

# documents

manager = CouchDBManager()


def unique_id():
    return hex(uuid.uuid4().time)[2:-1]


class Post(Document):
    doc_type = 'post'
    title = TextField()
    filename = TextField()
    caption = TextField()
    published = DateTimeField(default=datetime.datetime.utcnow)

    @property
    def imgsrc(self):
Exemplo n.º 5
0
        };
    }
    ''')


views_by_workflow_locking_module = ViewDefinition('hello', 'workflow_locking_module', '''
    function (doc) {
         if (doc.doc_type && doc.doc_type == 'workflow_locking_module') {
            emit(doc.workflow_id, doc._id)
        };
    }
    ''')



manager = CouchDBManager()
manager.setup(app)
manager.add_viewdef([views_by_user, views_by_non_validated_clones, views_by_pipeline_module, views_by_email, views_by_saved_pipeline, views_by_workflow_locking_turn, views_by_workflow_locking_module])
manager.sync(app)



tasks = [
    {
        'id': 1,
        'title': u'Buy groceries',
        'description': u'Milk, Cheese, Pizza, Fruit, Tylenol', 
        'done': False
    },
    {
        'id': 2,
Exemplo n.º 6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flaskext.couchdb import CouchDBManager, ViewDefinition

manager = CouchDBManager() # auto_sync=False

all_users_view = ViewDefinition('users', 'all', '''\
        function (doc) {
            if (doc.type == 'user') {
                emit(doc.openid, null)
            };
        }''')
all_text_view = ViewDefinition('text', 'all', '''\
        function (doc) {
            if (doc.type != 'user') {
                emit(doc.date, {title:doc.title, content: doc.content, user:
                doc.user})
            };
        }''')

manager.add_viewdef((all_users_view, all_text_view))
Exemplo n.º 7
0
import os
import datetime
from flask import Flask, g, session, render_template, Markup, request, make_response, abort, redirect, url_for, flash
from flaskext.couchdb import CouchDBManager, Document, TextField, DateTimeField, ListField, IntegerField, ViewField, Row
from flaskext.markdown import Markdown
manager = CouchDBManager()

app = Flask(__name__)
app.config['COUCHDB_SERVER'] = 'https://app2833465.heroku:[email protected]'
app.config['COUCHDB_DATABASE'] = 'app_test'
app.config['SECRET_KEY'] = 'development key'
manager.setup(app)
Markdown(app)
class Story(Document):
    doc_type = 'story'
    title = TextField()
    content = TextField()
    author = TextField()
    created = DateTimeField(default=datetime.datetime.now)
    tags = ListField(TextField())
    likes = IntegerField()
    dislikes = IntegerField()
    by_title = ViewField('story', '''\
        function (doc) {
            emit(doc.title, doc);
        }''')



@app.route("/", methods=['GET', 'POST'])
def index():
Exemplo n.º 8
0
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:
Exemplo n.º 9
0
# -*- coding: utf-8 -*-
import datetime
from flaskext.couchdb import (CouchDBManager, Document, TextField,
                              DateTimeField, ViewField, paginate)



# model
class Signature(Document):
    doc_type = 'signature'

    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)
Exemplo n.º 10
0
from flaskext.couchdb import CouchDBManager, paginate
from schema import TaskSchema
from views import user_tasks_view
from flask_cors import CORS, cross_origin
from GetTaskIDs import GetTaskIDs
from couchdb import Server
import requests

import uuid

#prepare app to be a flask based application
#Enable cors on the app
#set up couch DB manager to enable communication from API to DB
app = Flask(__name__)
cors = CORS(app, resources={r"/todo_list/*": {"origins": "*"}})
manager = CouchDBManager()

manager.setup(app)
#Add user_tasks_view to manager's list of views
manager.add_viewdef(user_tasks_view)


#Route to return all currently store tasks in the DB
@app.route('/todo_list/getAllViews', methods=['GET'])
@cross_origin()
def getAllTasks():
    #runs user_tasks_view and returns resulting IDs to docIDs
    docIDs = GetTaskIDs(user_tasks_view)
    documents = []

    #for ever ID locate the doc in DB and append to documents array
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
from flask import Flask, request, g
from flask_restful import Resource, Api
from flaskext.couchdb import CouchDBManager
import os

app = Flask(__name__)
api = Api(app)

manager = CouchDBManager()

manager.setup(app)

registry = {}

app.config['COUCHDB_SERVER'] = os.environ.get('COUCHDB_SERVER', 'http://couchdb:5984/')
app.config['COUCHDB_DATABASE'] = os.environ.get('COUCHDB_DATABASE', 'survey-registry')


class SurveyRegistry(Resource):

    def get(self, questionnaire_id):
        document = g.couch.get(questionnaire_id)
        if document:
            return document['content']
        else:
            return {}

    def post(self, questionnaire_id):
        questionnaire_data = request.get_json()
        document = dict(title=questionnaire_id, content=questionnaire_data)
        g.couch[questionnaire_id] = document
Exemplo n.º 13
0
from flaskext.uploads import (UploadSet, configure_uploads, IMAGES,
                              UploadNotAllowed)
from werkzeug.security import check_password_hash
from image_classifier import ImageClassifier
from webconfig import DevConfig

# application
app = Flask(__name__)
app.config.from_object(DevConfig)

# uploads
uploaded_photos = UploadSet('photos', IMAGES)
configure_uploads(app, uploaded_photos)

# documents
db = CouchDBManager()

image_classifier = ImageClassifier()


def unique_id():
    return hex(uuid.uuid4().time)[2:-1]


class Post(Document):
    doc_type = 'post'
    title = TextField()
    filename = TextField()
    location = TextField()
    semantic = TextField()
    scene = TextField()
Exemplo n.º 14
0
    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')
Exemplo n.º 15
0
views_by_txl_project_shared_members = ViewDefinition(
    'hello', 'findTXLProjectSharedMembers', '''
	function (doc) {
		if (doc.the_doc_type == 'txl_project') {
			emit(doc.shared_with, doc._id)
		};
	}
	''')

from flask import current_app as app

app = Flask(__name__)
app.config.update(COUCHDB_SERVER='http://*****:*****@app_txl_cloud.route('/editor')
def txl_index():
    return render_template('quick_txl.html')


@app_txl_cloud.route('/txl', methods=['POST'])
Exemplo n.º 16
0
app = Flask(__name__)
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])
Exemplo n.º 17
0
    'hello', 'appCodeClonefindEmailAndDocID', '''
	function (doc) {
		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():
Exemplo n.º 18
0
# application

app = Flask(__name__)
app.config.from_object(__name__)
app.config.from_envvar('PHOTOLOG_SETTINGS', silent=True)


# uploads

uploaded_photos = UploadSet('photos', IMAGES)
configure_uploads(app, uploaded_photos)


# documents

manager = CouchDBManager()

def unique_id():
    return hex(uuid.uuid4().time)[2:-1]


class Post(Document):
    doc_type = 'post'
    title = TextField()
    filename = TextField()
    caption = TextField()
    published = DateTimeField(default=datetime.datetime.utcnow)

    @property
    def imgsrc(self):
        return uploaded_photos.url(self.filename)
Exemplo n.º 19
0
class Signature(Document):
    doc_type = 'signature'
    
    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')
Exemplo n.º 20
0
            emit(doc.user, doc)
        };
    }
    ''')

views_by_non_validated_clones = ViewDefinition('hello', 'my_non_validated_clones', '''
    function (doc) {
         if (doc.is_clone_doc == 'yes' && doc.is_validated_by_any_user == 'no') {
            emit(doc._id, doc)
        };   
    }
    ''')


# userInfo & uplaod imgs database
manager = CouchDBManager()
manager.setup(app)
manager.add_viewdef([views_by_source, views_by_user, views_by_Lsysmodel, views_by_non_validated_clones])
manager.sync(app)
# imgs search database
search_obj = imgSearch()

imgId = []
idseq = 0


def image_source(selectedSource):
    sources = []
    for row in views_by_source(g.couch):
        sources.append(row.key)
    sources = list(set(sources))