示例#1
0
 def lookup(cls, dataset, data, account, match_entity=True,
         readonly=False):
     data = AliasLookupSchema().to_python(data)
     if match_entity:
         entity = Entity.by_name(dataset, data['name'])
         if entity is not None:
             return entity
     else:
         entity = None
     alias = cls.by_name(dataset, data['name'])
     if alias is not None:
         return alias
     choices = match_op(data['name'], dataset)
     choices = filter(lambda (c,v,s): s > 99.9, choices)
     if len(choices)==1:
         c, entity_id, s = choices.pop()
         entity = Entity.by_id(dataset, entity_id)
     if readonly:
         return entity
     alias = cls()
     alias.creator = account
     alias.dataset = dataset
     alias.entity = entity
     alias.is_matched = entity is not None
     alias.name = data['name']
     alias.data = data['data']
     db.session.add(alias)
     db.session.flush()
     if entity is not None:
         add_candidate_to_cache(dataset, alias.name, entity.id)
     return alias
示例#2
0
 def lookup(cls, dataset, data, account, match_entity=True, readonly=False):
     data = AliasLookupSchema().to_python(data)
     if match_entity:
         entity = Entity.by_name(dataset, data['name'])
         if entity is not None:
             return entity
     else:
         entity = None
     alias = cls.by_name(dataset, data['name'])
     if alias is not None:
         return alias
     choices = match_op(data['name'], dataset)
     choices = filter(lambda (c, v, s): s > 99.9, choices)
     if len(choices) == 1:
         c, entity_id, s = choices.pop()
         entity = Entity.by_id(dataset, entity_id)
     if readonly:
         return entity
     alias = cls()
     alias.creator = account
     alias.dataset = dataset
     alias.entity = entity
     alias.is_matched = entity is not None
     alias.name = data['name']
     alias.data = data['data']
     db.session.add(alias)
     db.session.flush()
     if entity is not None:
         add_candidate_to_cache(dataset, alias.name, entity.id)
     return alias
示例#3
0
 def _to_python(self, value, state):
     if value == 'NEW':
         return value
     elif value == 'INVALID' and state.dataset.enable_invalid:
         return value
     entity = Entity.by_id(state.dataset, value)
     if entity is not None:
         return entity
     raise Invalid('No such entity.', value, None)
示例#4
0
 def _to_python(self, value, state):
     if value == 'NEW':
         return value
     elif value == 'INVALID' and state.dataset.enable_invalid:
         return value
     entity = Entity.by_id(state.dataset, value)
     if entity is not None:
         return entity
     raise Invalid('No such entity.', value, None)