mflbackend/src/helpers.py
def check_identifier(_id, field, resource, mode, unique=True, fail=True):
    " Check whether an identifier has been used before "
    q = {'size': 0, 'q': 'extended||and|%s.search|equals|%s' % (field, _id)}
    res = karp_query('query', q, mode=mode, resource=resource)
    used = es_total(res) > 0
    ok = (used and not unique) or (not used and unique)
    if not ok and fail:
        text = 'already in use' if unique else 'not found'
        raise errs.MflException("Identifier %s %s" % (_id, text),
                                code="unique_%s" % field)
    return ok
 Check whether an identifier has been used before 
Check whether an identifier has been used before
Check whether an identifier has been used before
def check_identifier(_id, field, resource, mode, unique=True, fail=True):
    q = {'size': 0, 'q': 'extended||and|%s.search|equals|%s' % (field, _id)}
    res = karp_query('query', q, mode=mode, resource=resource)
    used = es_total(res) > 0
    ok = (used and not unique) or (not used and unique)
    if not ok and fail:
        text = 'already in use' if unique else 'not found'
        raise errs.MflException("Identifier %s %s" % (_id, text),
                                code="unique_%s" % field)
    return ok
def check_identifier ( _id , field , resource , mode , unique = True , fail = True ) : q = { 'size' : 0 , 'q' : 'extended||and|%s.search|equals|%s' % ( field , _id ) } res = karp_query ( 'query' , q , mode = mode , resource = resource ) used = es_total ( res ) > 0 ok = ( used and not unique ) or ( not used and unique ) if not ok and fail : text = 'already in use' if unique else 'not found' raise errs . MflException ( "Identifier %s %s" % ( _id , text ) , code = "unique_%s" % field ) return ok
Check whether an identifier has been used before
Check whether an identifier has been used before
" Check whether an identifier has been used before "
_id
field
resource
mode
unique
fail