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)
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))
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())
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)
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)
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))