Ejemplo n.º 1
0
def get_batchrecords(query_str):

    try:
        q = json.loads(query_str)
    except:
        q= dict()
    q = BatchRecordSearchForm(q)

    if not q.is_valid():
        resp = rc.BAD_REQUEST
        resp.write(str(q.errors))
        return resp

    name = q.cleaned_data['name']
    batch_number = q.cleaned_data['batch_number']
    date_of_manufacture_from = q.cleaned_data['date_of_manufacture_from']
    date_of_manufacture_to = q.cleaned_data['date_of_manufacture_to']

    query = dict()
    query['filters'] = []

    if name:
        query['filters'].append(dict(field='name',
                                     lookuptype='icontains',
                                     value=name,
                                     op='AND',
                                     exclude=False))

    if batch_number:
        query['filters'].append(dict(field='batch_number',
                                     lookuptype='icontains',
                                     value=batch_number,
                                     op='AND',
                                     exclude=False))

    if date_of_manufacture_from:
        query['filters'].append(dict(field='date_of_manufacture',
                                     lookuptype='gte',
                                     value=date_of_manufacture_from,
                                     op='AND',
                                     exclude=False))

    if date_of_manufacture_to:
        query['filters'].append(dict(field='date_of_manufacture',
                                     lookuptype='lte',
                                     value=date_of_manufacture_to,
                                     op='AND',
                                     exclude=False))
    
    if not query['filters']:
        #Needs at least one filter
        resp = rc.BAD_REQUEST
        resp.write("At least one search criterion needs to be entered.")
        return resp

    else:
        result = build_query(query, BatchRecord)

        return result
Ejemplo n.º 2
0
 def testDict(self):
     d_dict  = {'app': 'doc_engine',
                'model':'Document',
                'filters':[{'field': 'serial_number', 'lookuptype':'contains', 'value':'AF', 'op':'', 'exclude':False }]}
     result = core.build_query(d_dict)
     self.assertIsInstance(result, models.query.QuerySet)
     #There should be at least one result
     self.assertTrue(result)
Ejemplo n.º 3
0
    def read(self, request):
        
        if request.GET.get('query', None):
            try:
                q = json.loads(request.GET.get('query'))
            except:
                q= dict()

            q = BatchRecordSearchForm(q)

            if not q.is_valid():
                resp = rc.BAD_REQUEST
                resp.write(str(q.errors))
                return resp

            name = q.cleaned_data['name']
            batch_number = q.cleaned_data['batch_number']
            date_manufactured_from = q.cleaned_data['date_manufactured_from']
            date_manufactured_to = q.cleaned_data['date_manufactured_to']

            query = dict()
            query['filters'] = []

            if name:
                query['filters'].append(dict(field='name',
                                             lookuptype='icontains',
                                             value=name,
                                             op='AND',
                                             exclude=False))

            if batch_number:
                query['filters'].append(dict(field='batch_number',
                                             lookuptype='icontains',
                                             value=batch_number,
                                             op='AND',
                                             exclude=False))

            if date_manufactured_from:
                query['filters'].append(dict(field='date_manufactured',
                                             lookuptype='gte',
                                             value=date_manufactured_from,
                                             op='AND',
                                             exclude=False))

            if date_manufactured_to:
                query['filters'].append(dict(field='date_manufactured',
                                             lookuptype='lte',
                                             value=date_manufactured_to,
                                             op='AND',
                                             exclude=False))
            if not query['filters']:
                #Needs at least one filter
                resp = rc.BAD_REQUEST
                resp.write("Needs at least one filter")
                return resp

            else:
                result = build_query(query, BatchRecord)
                return result
        else:
            resp = rc.BAD_REQUEST
            resp.write("Needs a query parameter")
            return resp
Ejemplo n.º 4
0
 def testNoResult(self):
     d_json = '{"app": "doc_engine", "model": "Document", "filters": [{"lookuptype": "contains", "field": "title", "exclude": false, "value": "XXXXXXXXXXXXXXX", "op": ""}]}'
     result = core.build_query(d_json)
     self.assertFalse(result)
Ejemplo n.º 5
0
 def testWithModel(self):
     d_with_model = '{"filters": [{"lookuptype": "contains", "field": "serial_number", "exclude": false, "value": "AF", "op": ""}]}'
     result = core.build_query(d_with_model, Document)
     self.assertIsInstance(result, models.query.QuerySet)
     #There should be at least one result
     self.assertTrue(result)
Ejemplo n.º 6
0
 def testJSON(self):
     d_json = '{"app": "doc_engine", "model": "Document", "filters": [{"lookuptype": "contains", "field": "serial_number", "exclude": false, "value": "AF", "op": ""}]}'
     result = core.build_query(d_json)
     self.assertIsInstance(result, models.query.QuerySet)
     #There should be at least one result
     self.assertTrue(result)