Exemplo n.º 1
0
 def lookup(cls, dataset, data, account, match_value=True, readonly=False):
     data = LinkLookupSchema().to_python(data)
     if match_value:
         value = Value.by_value(dataset, data["key"])
         if value is not None:
             return value
     else:
         value = None
     link = cls.by_key(dataset, data["key"])
     if link is not None:
         return link
     choices = match_op(data["key"], dataset)
     choices = filter(lambda (c, v, s): s > 99.9, choices)
     if len(choices) == 1:
         c, value, s = choices.pop()
         value = Value.by_id(dataset, value)
     if readonly:
         return value
     link = cls()
     link.creator = account
     link.dataset = dataset
     link.value = value
     link.is_matched = value is not None
     link.key = data["key"]
     link.data = data["data"]
     db.session.add(link)
     db.session.flush()
     return link
Exemplo n.º 2
0
 def _to_python(self, value, state):
     if value == 'NEW':
         return value
     elif value == 'INVALID' and state.dataset.enable_invalid:
         return value
     value_obj = Value.by_id(state.dataset, value)
     if value_obj is not None:
         return value_obj
     raise Invalid('No such value.', value, None)
Exemplo n.º 3
0
 def _to_python(self, value, state):
     if value == "NEW":
         return value
     elif value == "INVALID" and state.dataset.enable_invalid:
         return value
     value_obj = Value.by_id(state.dataset, value)
     if value_obj is not None:
         return value_obj
     raise Invalid("No such value.", value, None)
Exemplo n.º 4
0
 def match(self, dataset, data, account):
     state = LinkMatchState(dataset)
     data = LinkMatchSchema().to_python(data, state)
     self.is_matched = True
     self.matcher = account
     if data['choice'] == 'INVALID':
         self.value = None
         self.is_invalid = True
     elif data['choice'] == 'NEW':
         self.value = Value.create(dataset, data, account)
         self.is_invalid = False
     else:
         self.value = data['choice']
         self.is_invalid = False
     db.session.add(self)
     db.session.flush()