Beispiel #1
0
def update(id):
    relation = object_or_404(Relation.by_id(id))
    authz.require(authz.project_edit(relation.project))
    data = request_data({'author': request.account})
    relation = relations.save(data, relation=relation)
    db.session.commit()
    return jsonify(relation)
Beispiel #2
0
def update(id):
    relation = object_or_404(Relation.by_id(id))
    authz.require(authz.project_edit(relation.project))
    data = request_data({'author': request.account})
    relation = relations.save(data, relation=relation)
    db.session.commit()
    return jsonify(relations.to_rest(relation))
Beispiel #3
0
    def save(self):
        """ Save the relation to the database. Do this only once, after all
        properties have been set. """

        # fetch existing:
        q = Relation.all()
        q = q.filter(Relation.project == self.loader.project)
        q = q.filter(Relation.source == self.source.entity)
        q = q.filter(Relation.target == self.target.entity)

        for name, only_active in self.update_criteria:
            value = self.properties.get(name).get('value')
            attr = self.loader.project.get_attribute('relation', name)
            q = Entity._filter_property(q, [attr],
                                        value,
                                        only_active=only_active)
        relation = q.first()

        try:
            data = {
                'project': self.loader.project,
                'author': self.loader.account,
                'schema': self.schemata.pop(),
                'properties': self.properties,
                'source': self.source.entity,
                'target': self.target.entity
            }
            self._relation = relations.save(data, relation=relation)
        except Invalid, inv:
            if not self.loader.ignore_errors:
                raise
            log.warning("Validation error: %r", inv.asdict())
Beispiel #4
0
    def save(self):
        """ Save the relation to the database. Do this only once, after all
        properties have been set. """

        # fetch existing:
        q = Relation.all()
        q = q.filter(Relation.project==self.loader.project)
        q = q.filter(Relation.source==self.source.entity)
        q = q.filter(Relation.target==self.target.entity)

        for name, only_active in self.update_criteria:
            value = self.properties.get(name).get('value')
            q = Entity._filter_property(q, name, value,
                only_active=only_active)
        relation = q.first()

        try:
            data = {
                'project': self.loader.project,
                'author': self.loader.account,
                'schema': self.schemata.pop(),
                'properties': self.properties,
                'source': self.source.entity,
                'target': self.target.entity
            }
            self._relation = relations.save(data, relation=relation)
        except Invalid, inv:
            log.warning("Validation error: %r", inv)
Beispiel #5
0
def create():
    data = request_data({'author': request.account})
    project = ProjectRef().get(data.get('project'))
    data['project'] = project
    authz.require(authz.project_edit(project))
    relation = relations.save(data)
    db.session.commit()
    return jsonify(relation)
Beispiel #6
0
def create():
    data = request_data({'author': request.account})
    project = ProjectRef().get(data.get('project'))
    data['project'] = project
    authz.require(authz.project_edit(project))
    relation = relations.save(data)
    db.session.commit()
    return jsonify(relations.to_rest(relation))