try: db.session.delete(project) db.session.commit() except IntegrityError as err: db.session.rollback() log.exception(err) abort(400, {'message': 'Data integrity violated.'}) remove_notifications({ 'project_id': project_id, }) return NO_PAYLOAD project_api = ProjectDetailAPI.as_view('project_detail_api') api.add_url_rule('/projects/<int:project_id>', view_func=project_api, methods=('GET', 'PATCH', 'DELETE')) @api.route('/tags') def list_tags(): """List all available tags.""" out_schema = TagSchema(many=True) return out_schema.jsonify(Tag.query.all()) @api.route('/tags', methods=['POST']) @admin_required def create_tag(): """Create a new tag.""" in_schema = TagSchema(only=('name',))
application_id=application_id, reporter_email=current_user.email ).first_or_404() try: db.session.delete(report) db.session.commit() except IntegrityError as err: db.session.rollback() log.exception(err) abort(400, {'message': 'Data integrity violated.'}) return NO_PAYLOAD volunteering_report_api = VolunteeringReportAPI.as_view('volunteering_report_api') api.add_url_rule('/projects/<int:project_id>/activities/<int:activity_id>' '/applications/<int:application_id>/report', view_func=volunteering_report_api, methods=('POST', 'PATCH', 'DELETE')) # ----- Feedback ----- @api.route('/projects/<int:project_id>/activities/<int:activity_id>' '/applications/<int:application_id>/feedback', methods=['POST']) @login_required def leave_feedback(project_id, activity_id, application_id): """Leave feedback on a particular volunteering experience.""" application = Application.query.get_or_404(application_id) activity = Activity.query.get_or_404(activity_id) project = Project.query.get_or_404(project_id) if activity.project != project or application.activity_id != activity.id:
try: db.session.commit() remove_notifications({ 'activity_id': activity_id, }) except IntegrityError as err: db.session.rollback() log.exception(err) abort(400, {'message': 'Data integrity violated.'}) return NO_PAYLOAD activity_api = ActivityAPI.as_view('activity_api') api.add_url_rule('/projects/<int:project_id>/activities/<int:activity_id>', view_func=activity_api, methods=('PATCH', 'DELETE')) @allow_no_json @api.route('/projects/<int:project_id>/activities/<int:activity_id>/publish', methods=['PATCH']) @login_required def publish_activity(project_id, activity_id): """Publish the activity.""" project = Project.query.get_or_404(project_id) if not current_user.is_admin and current_user not in project.moderators: abort(403) activity = Activity.query.get_or_404(activity_id) if activity.internal:
try: db.session.delete(variety) db.session.commit() except IntegrityError as err: db.session.rollback() log.exception(err) abort(400, {'message': 'Data integrity violated.'}) remove_notifications({ 'variety_id': variety_id, }) return NO_PAYLOAD variety_api = VarietyAPI.as_view('variety_api') api.add_url_rule('/products/<int:product_id>/varieties/<int:variety_id>', view_func=variety_api, methods=('PATCH', 'DELETE')) @api.route('/products/<int:product_id>/varieties/<int:variety_id>/purchase', methods=['POST']) @login_required def purchase_variety(product_id, variety_id): """Purchase a particular variety of a product.""" purchased_amount = request.json.get('amount') if not isinstance(purchased_amount, int): abort(400, { 'message': 'The purchase amount must be specified as an integer.' }) if purchased_amount <= 0: