예제 #1
0
파일: db.py 프로젝트: vaad2/vest
def es_get():
    from pyelasticsearch import ElasticSearch
    from django.conf import settings
    connection = get_thread_var('es_connetion')

    if not connection:
        connection = ElasticSearch(
            'http://%s:%s/' %
            (settings.ES['default']['HOST'], settings.ES['default']['PORT']))
        set_thread_var('es_connetion', connection)

    return connection
예제 #2
0
파일: db.py 프로젝트: vaad2/vest
def mongo_get(collection=None):
    from django.conf import settings
    from pymongo import Connection
    connection = get_thread_var('mongo_connection')

    if not connection:
        connection = Connection()[settings.MONGO['default']['NAME']]
        set_thread_var('mongo_connection', connection)

    if connection and collection:
        if hasattr(collection, '_meta'):
            return connection[collection._meta.db_table]
        return connection[collection]

    return connection
예제 #3
0
파일: db.py 프로젝트: vaad2/vest
def es_utils_get(doctypes=None):
    # basic_s = S().es(urls=[URL]).indexes(INDEX).doctypes(DOCTYPE)
    from django.conf import settings
    connection = get_thread_var('es_utils_connetion')

    if not connection:

        from elasticutils import S

        # s = S().indexes('dbvestlitecms').doctypes('product')

        connection = S().es().indexes(settings.ES['default']['NAME'])

        # ElasticSearch('%s:%s/' % (settings.ES['default']['HOST'], settings.ES['default']['PORT']))
        set_thread_var('es_utils_connetion', connection)

    if doctypes:
        return connection.doctypes(doctypes)
    return connection
예제 #4
0
파일: middleware.py 프로젝트: vaad2/vest
 def process_request(self, request):
     set_thread_var('request', request)