Esempio n. 1
0
def MapOperationFactory(options):

    name = options['name']
    pieces = name.split('.')
    if pieces[0] == 'formatters':
        wrapper = MapOperationWrapper(formattersManager.getFormatter(pieces[1]), options.get('arguments', {}))
        return wrapper
    
    raise
Esempio 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