Exemplo n.º 1
0
def filters_from_request(request):
    raw_filters = {}
    for key in request.POST:
        splt = key.split('-')
        if splt[0].startswith('filter'):
            ident = splt[1]
            typ = splt[2]
            if not ident in raw_filters:
                raw_filters[ident] = {}
            raw_filters[ident][typ] = request.POST[key]
    filters = {}
    for ident, raw_filter in raw_filters.items():
        value = raw_filter.get('value', '')
        if value.strip():
            typ = raw_filter['typ']
            module = _get_module('silk.request_filters')
            filter_class = getattr(module, typ)
            try:
                f = filter_class(value)
                filters[ident] = f
            except FilterValidationError:
                logger.warn('Validation error when processing filter %s(%s)' % (typ, value))
    return filters
Exemplo n.º 2
0
def filters_from_request(request):
    raw_filters = {}
    for key in request.POST:
        splt = key.split('-')
        if splt[0].startswith('filter'):
            ident = splt[1]
            typ = splt[2]
            if not ident in raw_filters:
                raw_filters[ident] = {}
            raw_filters[ident][typ] = request.POST[key]
    filters = {}
    for ident, raw_filter in raw_filters.items():
        value = raw_filter.get('value', '')
        if value.strip():
            typ = raw_filter['typ']
            module = _get_module('silk.request_filters')
            filter_class = getattr(module, typ)
            try:
                f = filter_class(value)
                filters[ident] = f
            except FilterValidationError:
                logger.warn('Validation error when processing filter %s(%s)' % (typ, value))
    return filters
Exemplo n.º 3
0
 def test_dot(self):
     module = _get_module('silk.models')
     self.assertEqual(module.__class__.__name__, 'module')
     self.assertEqual('silk.models', module.__name__)
     self.assertTrue(hasattr(module, 'SQLQuery'))
Exemplo n.º 4
0
 def test_singular(self):
     module = _get_module('silk')
     self.assertEqual(module.__class__.__name__, 'module')
     self.assertEqual('silk', module.__name__)
     self.assertTrue(hasattr(module, 'models'))
 def test_dot(self):
     module = _get_module('silk.models')
     self.assertEqual(module.__class__.__name__, 'module')
     self.assertEqual('silk.models', module.__name__)
     self.assertTrue(hasattr(module, 'SQLQuery'))
 def test_singular(self):
     module = _get_module('silk')
     self.assertEqual(module.__class__.__name__, 'module')
     self.assertEqual('silk', module.__name__)
     self.assertTrue(hasattr(module, 'models'))