Exemplo n.º 1
0
def import_upload(dataset_name, id, account_id,
                  entity_col, alias_col):
    dataset = Dataset.find(dataset_name)
    account = Account.by_id(account_id)
    metadata, row_set = parse_upload(dataset, id)
    headers = detect_headers(row_set)
    for row in row_set:
        data = dict([(c.column, c.value) for c in row])
        entity = data.pop(entity_col) if entity_col else None
        alias = data.pop(alias_col) if alias_col else None
        if alias_col and alias is not None and len(alias) and alias != entity:
            d = {'name': alias, 'data': data}
            alias_obj = Alias.lookup(dataset, d, account,
                                     match_entity=False)
            data = {}
        if entity_col and entity is not None and len(entity):
            d = {'name': entity, 'data': data}
            entity_obj = Entity.by_name(dataset, entity)
            if entity_obj is None:
                entity_obj = Entity.create(dataset, d, account)
            entity_obj.data = data
        if alias_col and entity_col:
            alias_obj.match(dataset, {'choice': entity_obj.id}, account)
    db.session.commit()
    flush_cache(dataset)
Exemplo n.º 2
0
 def update(self, data, account):
     state = EntityState(self.dataset, self)
     data = EntitySchema().to_python(data, state)
     self.creator = account
     self.name = data['name']
     self.data = data['data']
     flush_cache(self.dataset)
     db.session.add(self)
Exemplo n.º 3
0
 def update(self, data, account):
     state = EntityState(self.dataset, self)
     data = EntitySchema().to_python(data, state)
     self.creator = account
     self.name = data['name']
     self.data = data['data']
     flush_cache(self.dataset)
     db.session.add(self)
Exemplo n.º 4
0
 def create(cls, data, account):
     data = DatasetNewSchema().to_python(data)
     dataset = cls()
     dataset.owner = account
     dataset.name = data['name']
     dataset.label = data['label']
     db.session.add(dataset)
     db.session.flush()
     flush_cache(dataset)
     return dataset
Exemplo n.º 5
0
 def create(cls, data, account):
     data = DatasetNewSchema().to_python(data)
     dataset = cls()
     dataset.owner = account
     dataset.name = data['name']
     dataset.label = data['label']
     db.session.add(dataset)
     db.session.flush()
     flush_cache(dataset)
     return dataset
Exemplo n.º 6
0
 def update(self, data):
     data = DatasetEditSchema().to_python(data)
     self.label = data['label']
     self.normalize_text = data['normalize_text']
     self.ignore_case = data['ignore_case']
     self.public_edit = data['public_edit']
     self.match_aliases = data['match_aliases']
     self.enable_invalid = data['enable_invalid']
     self.algorithm = data['algorithm']
     db.session.add(self)
     db.session.flush()
     flush_cache(self)
Exemplo n.º 7
0
def update(dataset):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_manage(dataset))
    data = request_content()
    try:
        flush_cache(dataset)
        dataset.update(data)
        db.session.commit()
        flash("Updated %s" % dataset.label, 'success')
        return redirect(url_for('.view', dataset=dataset.name))
    except Invalid, inv:
        return handle_invalid(inv, edit, args=[dataset.name], data=data)
Exemplo n.º 8
0
 def update(self, data):
     data = DatasetEditSchema().to_python(data)
     self.label = data['label']
     self.normalize_text = data['normalize_text']
     self.ignore_case = data['ignore_case']
     self.public_edit = data['public_edit']
     self.match_aliases = data['match_aliases']
     self.enable_invalid = data['enable_invalid']
     self.algorithm = data['algorithm']
     db.session.add(self)
     db.session.flush()
     flush_cache(self)
Exemplo n.º 9
0
def update(dataset):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_manage(dataset))
    data = request_content()
    try:
        flush_cache(dataset)
        dataset.update(data)
        db.session.commit()
        flash("Updated %s" % dataset.label, 'success')
        return redirect(url_for('.view', dataset=dataset.name))
    except Invalid, inv:
        return handle_invalid(inv, edit, 
                args=[dataset.name], data=data)
Exemplo n.º 10
0
def merge(dataset, value):
    dataset = Dataset.find(dataset)
    authz.require(authz.dataset_edit(dataset))
    value = Value.find(dataset, value)
    data = request_content()
    try:
        target = value.merge_into(data, request.account)
        flush_cache(dataset)
        db.session.commit()
        flash("Merged %s" % value.value, 'success')
        return redirect(url_for('.view', dataset=dataset.name,
                        value=target.id))
    except Invalid, inv:
        print inv
        return handle_invalid(inv, view, data=data,
                              args=[dataset.name, value.id])
Exemplo n.º 11
0
 def merge_into(self, data, account):
     from nomenklatura.model.alias import Alias
     state = EntityState(self.dataset, self)
     data = EntityMergeSchema().to_python(data, state)
     target = data.get('target')
     for alias in self.aliases:
         alias.entity = target
     alias = Alias()
     alias.name = self.name
     alias.creator = self.creator
     alias.matcher = account
     alias.entity = target
     alias.dataset = self.dataset
     alias.is_matched = True
     db.session.delete(self)
     db.session.add(alias)
     db.session.commit()
     flush_cache(self.dataset)
     return target
Exemplo n.º 12
0
 def merge_into(self, data, account):
     from nomenklatura.model.alias import Alias
     state = EntityState(self.dataset, self)
     data = EntityMergeSchema().to_python(data, state)
     target = data.get('target')
     for alias in self.aliases:
         alias.value = target
     alias = Alias()
     alias.name = self.name
     alias.creator = self.creator
     alias.matcher = account
     alias.entity = target
     alias.dataset = self.dataset
     alias.is_matched = True
     db.session.delete(self)
     db.session.add(alias)
     db.session.commit()
     flush_cache(self.dataset)
     return target
Exemplo n.º 13
0
def import_upload(dataset_name, sig, account_id, entity_col, alias_col):
    dataset = Dataset.find(dataset_name)
    account = Account.by_id(account_id)
    metadata, row_set = parse_upload(dataset, sig)
    headers = detect_headers(row_set)
    for row in row_set:
        data = dict([(c.column, c.value) for c in row])
        entity = data.pop(entity_col) if entity_col else None
        alias = data.pop(alias_col) if alias_col else None
        if alias_col and alias is not None and len(alias) and alias != entity:
            d = {'name': alias, 'data': data}
            alias_obj = Alias.lookup(dataset, d, account, match_entity=False)
            data = {}
        if entity_col and entity is not None and len(entity):
            d = {'name': entity, 'data': data}
            entity_obj = Entity.by_name(dataset, entity)
            if entity_obj is None:
                entity_obj = Entity.create(dataset, d, account)
            entity_obj.data = data
        if alias_col and entity_col:
            alias_obj.match(dataset, {'choice': entity_obj.id}, account)
    db.session.commit()
    flush_cache()