Exemplo n.º 1
0
def dispatch(request, object_type, object_name):

    o = ObjectRequest(request, object_type, object_name)

    if request.method == 'POST':
        req_items = request.POST
    elif request.method == 'GET':
        #return error('only post request is supported')
        req_items = request.GET

    for el in req_items.items():
        if el[0].startswith('filters'):
            o.filters[el[0][8:-1]] = el[1]
        elif el[0].startswith('options'):
            o.options = req_items.getlist('options[]')

    try:
        response = o.delete()

        if response:
            return success('record deleted')
        else:
            return error('an error has occurred')

    except Exception, e:
        return error(str(e))
Exemplo n.º 2
0
def dispatch(request, object_type, object_name):

    o = ObjectRequest(request, object_type, object_name)

    if request.method == 'POST':
        req_items = request.POST
    elif request.method == 'GET':
        #return error('only post request is supported')
        req_items = request.GET
    for el in list(req_items.items()):
        # Filters not used for create
        if el[0].startswith('filters'):
            o.filters[el[0][8:-1]] = el[1]
        elif el[0].startswith('params'):
            #o.params[el[0][7:-1]] = el[1]
            o.params.append({el[0][7:-1]: el[1]})
        elif el[0].startswith('fields'):
            o.fields = req_items.getlist('fields[]')
        elif el[0].startswith('options'):
            o.options = req_items.getlist('options[]')

    try:
        response = o.create()

        if response:
            return success('record created')
        else:
            return error('an error has occurred')

    except Exception as e:
        return error(str(e))
Exemplo n.º 3
0
def dispatch(request, object_type, object_name):

    o = ObjectRequest(request, object_type, object_name)

    if request.method == 'POST':
        req_items = request.POST
    elif request.method == 'GET':
        #return error('only post request is supported')
        req_items = request.GET
    logger.debug(req_items)
    for el in req_items.items():

        logger.debug("#===============> {}".format(el))
        if el[0].startswith('filters'):
            o.filters[el[0][8:-1]] = el[1]
        elif el[0].startswith('params'):
            logger.debug("#======> 0 {}".format(el[0]))
            logger.debug("#======> 1 {}".format(req_items.getlist(el[0])))

            if (el[0][-2:] == '[]'):
                # when receiving params[key][] = 'value1' ...
                #o.params.append({el[0][7:-3]:",".join(req_items.getlist(el[0]))})
                o.params.append({el[0][7:-3]: req_items.getlist(el[0])})
            else:
                # when receiving params[key] = 'value'
                o.params.append({el[0][7:-1]: el[1]})

            logger.debug("o.params = {}".format(o.params))

        elif el[0].startswith('fields'):
            o.fields = req_items.getlist('fields[]')
        elif el[0].startswith('options'):
            o.options = req_items.getlist('options[]')

    try:
        response = o.update()

        if response:
            return success('record updated')
        else:
            return error('an error has occurred')

    except Exception, e:
        return error("exception:" + str(e))
Exemplo n.º 4
0
        def csv_json(id_one, id_two, rows, data):
            errors = {}
            response = []

            for row, row_number, errors in rows:
                if errors:
                    errors[row_number] = errors
                else:
                    response.append(row)

            if errors:
                return rest.error(errors)
            else:
                return rest.created(response)
Exemplo n.º 5
0
        def csv_json(id_one, id_two, rows, data):
            errors = {}
            response = []

            for row, row_number, errors in rows:
                if errors:
                    errors[row_number] = errors
                else:
                    response.append(row)

            if errors:
                return rest.error(errors)
            else:
                return rest.created(response)
Exemplo n.º 6
0
 def error():
     return rest.error({
         'name': ['field is required'],
         'motown_philly': ['too hard', 'too soft'],
     })
Exemplo n.º 7
0
 def error():
   return rest.error({
     'name':           ['field is required'],
     'motown_philly':  ['too hard', 'too soft'],
   })