Exemplo n.º 1
0
def objects(request, collection, database=None):
    """
    Main view to send commands to handler
    """
    out = createBaseResponseObject()

    database = database or settings.MONGO_SERVER_DEFAULT_DB

    mongo = MongoWrapper()

    try:

        mongo.connect()

        existing_dbs = mongo.connection.database_names()
        if database not in existing_dbs:
            raise Exception("Database %s does not exist" % database)

        database_object = mongo.getDb(database)
        existing_collections = database_object.collection_names()
        if collection not in existing_collections:
            raise Exception("Collection %s does not exist" % collection)

        query_dict = getQueryDict(request)
        offset = getOffset(request)
        limit = getLimit(request)

        formatter = getFormatter(request)

        from formattersmanager import formattersManager
        formatters = formattersManager.getFormatters()
        if formatter and formatter not in formatters:
            raise Exception("Formatter %s is not available" % str(formatter))
        if formatter:
            formatter_callback = formattersManager.getFormatter(formatter)
        else:
            formatter_callback = None

        query_result = mongo.objects(database,
                                     collection,
                                     query_dict=query_dict,
                                     offset=offset,
                                     limit=limit,
                                     formatter_callback=formatter_callback)
        records = query_result['records']
        has_more = query_result['has_more']
        out['results'] = records
        out['has_more'] = has_more

    except Exception, e:
        raise
        out['errors'] = str(e)
        out['status'] = 0
Exemplo n.º 2
0
def objects(request, collection, database=None):
    """
    Query view, gets some objects
    """
    out = createBaseResponseObject()

    database = database or settings.MONGO_SERVER_DEFAULT_DB
    
    try:
        
        existing_dbs = mongo.connection.database_names()
        if database not in existing_dbs:
            raise Exception("Database %s does not exist" % database)
            
        database_object = mongo.getDb(database)
        existing_collections = database_object.collection_names()
        if collection not in existing_collections:
            raise Exception("Collection %s does not exist" % collection)
            
        query_dict = getQueryDict(request)
        offset = getOffset(request)
        limit = getLimit(request)
        write_collection = getWriteCollection(request)
        formatter = getFormatter(request)
        
        formatters = formattersManager.getFormatters()
        if formatter and formatter not in formatters:
            raise Exception("Formatter %s is not available" % str(formatter))
        if formatter:
            formatter_callback = formattersManager.getFormatter(formatter)
        else:
            formatter_callback = None
        
        
        drop_collection = request.GET.get('drop_collection', None)
        if drop_collection and drop_collection.startswith('results'):
            mongo.dropCollection(database, drop_collection)
        
        query_result = mongo.objects(database, collection, query_dict=query_dict, offset=offset, limit=limit, 
                                     formatter_callback=formatter_callback, write_collection=write_collection)
                                     
        out['results'] = query_result['records']
        out['num_records'] = query_result['num_records']
        out['has_more'] = query_result['has_more']
        out['collection_out'] = query_result['collection_out']
    
    except Exception, e:
        raise
        out['errors'] = str(e)
        out['status'] = 0
Exemplo n.º 3
0
def objects(request, collection, database=None):
    """
    Main view to send commands to handler
    """
    out = createBaseResponseObject()

    database = database or settings.MONGO_SERVER_DEFAULT_DB
    
    mongo = MongoWrapper()
    
    try:
        
        mongo.connect()
    
        existing_dbs = mongo.connection.database_names()
        if database not in existing_dbs:
            raise Exception("Database %s does not exist" % database)
            
        database_object = mongo.getDb(database)
        existing_collections = database_object.collection_names()
        if collection not in existing_collections:
            raise Exception("Collection %s does not exist" % collection)
            
        query_dict = getQueryDict(request)
        offset = getOffset(request)
        limit = getLimit(request)

        formatter = getFormatter(request)
        
        from formattersmanager import formattersManager
        formatters = formattersManager.getFormatters()
        if formatter and formatter not in formatters:
            raise Exception("Formatter %s is not available" % str(formatter))
        if formatter:
            formatter_callback = formattersManager.getFormatter(formatter)
        else:
            formatter_callback = None
        
        query_result = mongo.objects(database, collection, query_dict=query_dict, offset=offset, limit=limit, 
                                     formatter_callback=formatter_callback)
        records = query_result['records']
        has_more = query_result['has_more']
        out['results'] = records
        out['has_more'] = has_more
    
    except Exception, e:
        raise
        out['errors'] = str(e)
        out['status'] = 0