def put(self, id): request_data = request.get_json() instance = db.session.query(Event).filter_by(id=id).first() if instance.zip != request_data['zip'] \ or instance.street_address1 != request_data['street_address1']\ or instance.latitude is None: address_dict = { 'street': request_data['street_address1'], 'city': request_data['city'], 'state': request_data['state'], 'zip': request_data['zip'] } geocode = Geocode.get_geocode(address_dict=address_dict) request_data['latitude'] = geocode['lat'] request_data['longitude'] = geocode['lng'] updated, errors = self.schema.load(request_data, instance=instance) if errors: raise RestException(RestException.INVALID_OBJECT, details=errors) updated.last_updated = datetime.datetime.utcnow() db.session.add(updated) db.session.commit() elastic_index.update_document(updated, 'Event', latitude=updated.latitude, longitude=updated.longitude) self.log_update(event_id=updated.id, event_title=updated.title, change_type='edit') return self.schema.dump(updated)
def put(self, id): request_data = request.get_json() instance = db.session.query(Study).filter_by(id=id).first() updated, errors = self.schema.load(request_data, instance=instance) if errors: raise RestException(RestException.INVALID_OBJECT, details=errors) updated.last_updated = datetime.datetime.now() db.session.add(updated) db.session.commit() elastic_index.update_document(updated, 'Study') return self.schema.dump(updated)
def post(self, resource_id): request_data = request.get_json() resource_categories = self.schema.load(request_data, many=True).data db.session.query(ResourceCategory).filter_by(resource_id=resource_id).delete() for c in resource_categories: db.session.add(ResourceCategory(resource_id=resource_id, category_id=c.category_id, type='resource')) db.session.commit() instance = db.session.query(Resource).filter_by(id=resource_id).first() elastic_index.update_document(instance, 'Resource') return self.get(resource_id)
def post(self, event_id): request_data = request.get_json() event_categories = self.schema.load(request_data, many=True).data db.session.query(ResourceCategory).filter_by(resource_id=event_id).delete() for c in event_categories: db.session.add(ResourceCategory(resource_id=event_id, category_id=c.category_id, type='event')) db.session.commit() instance = db.session.query(Event).filter_by(id=event_id).first() elastic_index.update_document(instance, 'Event', latitude=instance.latitude, longitude=instance.longitude) return self.get(event_id)
def post(self, location_id): request_data = request.get_json() for item in request_data: item['resource_id'] = location_id location_categories = self.schema.load(request_data, many=True) db.session.query(ResourceCategory).filter_by(resource_id=location_id).delete() for c in location_categories: db.session.add(ResourceCategory(resource_id=location_id, category_id=c.category_id, type='location')) db.session.commit() instance = db.session.query(Location).filter_by(id=location_id).first() elastic_index.update_document(instance, 'Location', latitude=instance.latitude, longitude=instance.longitude) return self.get(location_id)
def put(self, id): request_data = request.get_json() instance = db.session.query(Resource).filter_by(id=id).first() try: updated = self.schema.load(request_data, instance=instance, session=db.session) except Exception as e: raise RestException(RestException.INVALID_OBJECT, details=e) updated.last_updated = datetime.datetime.utcnow() db.session.add(updated) db.session.commit() elastic_index.update_document(updated, 'Resource') self.log_update(resource_id=updated.id, resource_title=updated.title, change_type='edit') return self.schema.dump(updated)