def parseCondition(condition, user):
    k = condition.get('key', 'name')
    k = {
        'user': '******',
    }.get(k, k)
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = '='
    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if k == 'id':
        v = decode_id(v)

    key = '%s%s' % (k, {
        '==': '__iexact',
        '^': '__istartswith',
        '$': '__iendswith',
    }.get(op,'__icontains'))

    key = str(key)
    if isinstance(v, unicode):
        v = unicodedata.normalize('NFKD', v).lower()
    if exclude:
        q = ~Q(**{k: v})
    else:
        q = Q(**{k: v})
    return q
def parseCondition(condition, user):
    '''
    condition: {
            value: "war"
    }
    or
    condition: {
            key: "year",
            value: "1970-1980,
            operator: "!="
    }
    ...
    '''
    k = condition.get('key', 'name')
    k = {
        'user': '******',
    }.get(k, k)
    if not k:
        k = 'name'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = '='
    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if op == '-':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        if exclude:
            return ~q
        else:
            return q
    if k == 'id':
        v = decode_id(v)
    if isinstance(v, bool):  #featured and public flag
        key = k
    elif k in ('id', ):
        key = '%s%s' % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
        }.get(op, ''))
    else:
        key = '%s%s' % (k, {
            '==': '__iexact',
            '^': '__istartswith',
            '$': '__iendswith',
        }.get(op, '__icontains'))

    key = str(key)
    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q
Пример #3
0
def parseCondition(condition, user):
    k = condition.get('key', 'name')
    k = {
        'user': '******',
    }.get(k, k)
    if not k:
        k = 'name'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = ''
    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if op == '-':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        if exclude:
            return ~q
        else:
            return q
    if k == 'id':
        v = decode_id(v)
    if isinstance(v, bool): #featured and public flag
        key = k
    elif k in ('id',):
        key = "%s%s" % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
        }.get(op, ''))
    else:
        key = "%s%s" % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
            '==': '__iexact',
            '=': '__icontains',
            '^': '__istartswith',
            '$': '__iendswith',
        }.get(op, '__icontains'))

    key = str(key)
    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q
Пример #4
0
def parseCondition(condition, user):
    '''
    condition: {
            value: "war"
    }
    or
    condition: {
            key: "year",
            value: "1970-1980,
            operator: "!="
    }
    ...
    '''
    k = condition.get('key', 'title')
    k = {
        'user': '******',
    }.get(k, k)
    if not k:
        k = 'title'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = '='
    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if op == '-':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        if exclude:
            return ~q
        else:
            return q
    if k == 'id':
        v = decode_id(v)
    elif isinstance(v, unicode):
        v = unicodedata.normalize('NFKD', v)
    if isinstance(v, bool): #featured and public flag
        key = k
    elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches', 'id'):
        key = '%s%s' % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
        }.get(op,''))
    else:
        key = '%s%s' % (k, {
            '==': '__iexact',
            '^': '__istartswith',
            '$': '__iendswith',
        }.get(op,'__icontains'))

    key = str(key)
    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q
Пример #5
0
def parseCondition(condition, user):
    '''
    condition: {
            value: "war"
    }
    or
    condition: {
            key: "year",
            value: "1970-1980,
            operator: "!="
    }
    ...
    '''
    k = condition.get('key', 'name')
    k = {
        'user': '******',
    }.get(k, k)
    if not k:
        k = 'name'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = '='
    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if isinstance(v, list) and len(v) == 2 and op == '=':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        if exclude:
            q = ~q
        return q
    if k == 'id':
        v = decode_id(v)
    if isinstance(v, bool): #featured and public flag
        key = k
    elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches', 'id'):
        key = '%s%s' % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
        }.get(op,''))
    else:
        key = '%s%s' % (k, {
            '==': '__iexact',
            '^': '__istartswith',
            '$': '__iendswith',
        }.get(op,'__icontains'))

    key = str(key)
    if isinstance(v, unicode):
        v = unicodedata.normalize('NFKD', v).lower()

    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q
Пример #6
0
def parseCondition(condition, user):
    '''
    condition: {
            value: "war"
    }
    or
    condition: {
            key: "year",
            value: "1970-1980,
            operator: "!="
    }
    '''
    k = condition.get('key', 'name')
    k = {
        'event': 'annotations__events__id',
        'in': 'start',
        'out': 'end',
        'place': 'annotations__places__id',
        'text': 'findvalue',
        'annotations': 'findvalue',
        'user': '******',
    }.get(k, k)
    if not k:
        k = 'name'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = ''
    if k in settings.CONFIG.get('clipLayers', []):
        return parseCondition({'key': 'annotations__findvalue',
                               'value': v,
                               'operator': op}, user) \
             & parseCondition({'key': 'annotations__layer',
                               'value': k,
                               'operator': '=='}, user)

    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if op == '-':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        return exclude and ~q or q
    if (not exclude and op == '=' or op in ('$', '^', '>=', '<')) and v == '':
        return Q()

    if k == 'id':
        itemId, points = v.split('/')
        points = [float('%0.03f' % float(p)) for p in points.split('-')]
        q = Q(item__itemId=itemId, start=points[0], end=points[1])
        return exclude and ~q or q

    elif k.endswith('__id'):
        v = decode_id(v)
    if isinstance(v, bool):  #featured and public flag
        key = k
    elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east',
               'matches', 'id') or k.endswith('__id'):
        key = "%s%s" % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
        }.get(op, ''))
    else:
        key = "%s%s" % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
            '==': '__iexact',
            '=': '__icontains',
            '^': '__istartswith',
            '$': '__iendswith',
        }.get(op, '__icontains'))

    key = str(key)
    if isinstance(v, unicode):
        v = unicodedata.normalize('NFKD', v).lower()
    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q
Пример #7
0
def parseCondition(condition, user):
    '''
    condition: {
            value: "war"
    }
    or
    condition: {
            key: "year",
            value: "1970-1980,
            operator: "!="
    }
    '''
    k = condition.get('key', 'name')
    k = {'in': 'start', 'out': 'end'}.get(k, k)
    if not k:
        k = 'name'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = ''

    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if op == '-':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        return exclude and ~q or q
    if (not exclude and op == '=' or op in ('$', '^', '>=', '<')) and v == '':
        return Q()

    if k == 'id':
        itemId, points = v.split('/')
        points = [float('%0.03f' % float(p)) for p in points.split('-')]
        q = Q(sort__item__itemId=itemId, start=points[0], end=points[1])
        return exclude and ~q or q
    if k == 'hash':
        v = models.parse_hash(v)
    if k == 'mode':
        v = models.Sequence.MODE[v]
    if k.endswith('__id'):
        v = decode_id(v)
    if isinstance(v, bool):  #featured and public flag
        key = k
    else:
        if k in ('mode', 'hash'):
            key = k
        else:
            key = "%s%s" % (k, {
                '>': '__gt',
                '>=': '__gte',
                '<': '__lt',
                '<=': '__lte',
                '==': '__iexact',
                '=': '__icontains',
                '^': '__istartswith',
                '$': '__iendswith',
            }.get(op, '__icontains'))

    key = str(key)
    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q
Пример #8
0
def parseCondition(condition, user):
    '''
    condition: {
            value: "war"
    }
    or
    condition: {
            key: "year",
            value: "1970-1980,
            operator: "!="
    }
    '''
    k = condition.get('key', 'name')
    k = {
        'in': 'start',
        'out': 'end'
    }.get(k, k)
    if not k:
        k = 'name'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = ''

    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if op == '-':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        return exclude and ~q or q
    if (not exclude and op == '=' or op in ('$', '^', '>=', '<')) and v == '':
        return Q()

    if k == 'id':
        itemId, points = v.split('/')
        points = [float('%0.03f'%float(p)) for p in points.split('-')]
        q = Q(sort__item__itemId=itemId, start=points[0], end=points[1])
        return exclude and ~q or q
    if k == 'hash':
        v =  models.parse_hash(v)
    if k == 'mode':
        v = models.Sequence.MODE[v]
    if k.endswith('__id'):
        v = decode_id(v)
    if isinstance(v, bool): #featured and public flag
        key = k
    else:
        if k in ('mode', 'hash'):
            key = k
        else:
            key = "%s%s" % (k, {
                '>': '__gt',
                '>=': '__gte',
                '<': '__lt',
                '<=': '__lte',
                '==': '__iexact',
                '=': '__icontains',
                '^': '__istartswith',
                '$': '__iendswith',
            }.get(op, '__icontains'))

    key = str(key)
    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q
Пример #9
0
def parseCondition(condition, user):
    '''
    condition: {
            value: "war"
    }
    or
    condition: {
            key: "year",
            value: "1970-1980,
            operator: "!="
    }
    '''
    k = condition.get('key', 'name')
    k = {
        'event': 'annotations__events__id',
        'in': 'start',
        'out': 'end',
        'place': 'annotations__places__id',
        'text': 'findvalue',
        'annotations': 'findvalue',
        'user': '******',
    }.get(k, k)
    if not k:
        k = 'name'
    v = condition['value']
    op = condition.get('operator')
    if not op:
        op = ''
    if k in settings.CONFIG.get('clipLayers', []):
        return parseCondition({'key': 'annotations__findvalue',
                               'value': v,
                               'operator': op}, user) \
             & parseCondition({'key': 'annotations__layer',
                               'value': k,
                               'operator': '=='}, user)

    if op.startswith('!'):
        op = op[1:]
        exclude = True
    else:
        exclude = False
    if op == '-':
        q = parseCondition({'key': k, 'value': v[0], 'operator': '>='}, user) \
            & parseCondition({'key': k, 'value': v[1], 'operator': '<'}, user)
        return exclude and ~q or q
    if (not exclude and op == '=' or op in ('$', '^', '>=', '<')) and v == '':
        return Q()

    if k == 'id':
        itemId, points = v.split('/')
        points = [float('%0.03f'%float(p)) for p in points.split('-')]
        q = Q(item__itemId=itemId, start=points[0], end=points[1])
        return exclude and ~q or q

    elif k.endswith('__id'):
        v = decode_id(v)
    if isinstance(v, bool): #featured and public flag
        key = k
    elif k in ('lat', 'lng', 'area', 'south', 'west', 'north', 'east', 'matches',
               'id') or k.endswith('__id'):
        key = "%s%s" % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
        }.get(op, ''))
    else:
        key = "%s%s" % (k, {
            '>': '__gt',
            '>=': '__gte',
            '<': '__lt',
            '<=': '__lte',
            '==': '__iexact',
            '=': '__icontains',
            '^': '__istartswith',
            '$': '__iendswith',
        }.get(op, '__icontains'))

    key = str(key)
    if isinstance(v, unicode):
        v = unicodedata.normalize('NFKD', v).lower()
    if exclude:
        q = ~Q(**{key: v})
    else:
        q = Q(**{key: v})
    return q