def processObjects(request, collection, database=None): """ this view applies processing to a set of records """ #TODO: get the records with a filter or with a list of ids #TODO: handle a list of processing functions and argss to be passed in #TODO: consider GET vs POST for calling this view. If no records are changed server side, # GET method should be used #TODO: consider writing output to a collection #TODO: leverage map/reduce when possible database = database or settings.MONGO_SERVER_DEFAULT_DB from processingmanager import processingManager if 'ids' in request.GET: ids = request.GET['ids'] #TODO: get records by id records = [] if 'query' in request.GET: query = request.GET['query'] #todo: get records by query records = [] if 'in_collection' in request.GET: in_collection = request.GET['in_collection'] records = mongo.objectsFromCollection(database, in_collection) write_collection = getWriteCollection(request) processor = getProcessor(request) if processor not in processingManager.getProcessors(): raise #processing cycle if write_collection: for record in records: pass else: for record in records: pass out = createBaseResponseObject() database = database or settings.MONGO_SERVER_DEFAULT_DB return HttpResponse(json.dumps(out, default=bson.json_util.default))
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