コード例 #1
0
    def update(event_id, criteria_id):
        try:
            data = request.get_json()

            criteria = Criteria.query.filter(
                db.and_(Criteria.id == criteria_id,
                        Criteria.event_id == event_id)).first()

            criteria.name = data['name']
            criteria.max_points = data['max_points']
            db.session.commit()

            result = format_criteria(criteria)
            return jsonify(result), 200

        except TypeError as e:
            print("\nTypeError >>> EventController.update: " + str(e) + "\n")

            if "'NoneType' object is not subscriptable" in str(e):
                response = {
                    'status': 'failed',
                    'message': 'Submitted without data.'
                }
                return jsonify(response), 400

            response = {'status': 'failed', 'message': 'Type error'}
            return jsonify(response), 400

        except KeyError as e:
            print("\nKeyError >>> EventController.update: " + str(e) + "\n")

            response = {
                'status':
                'failed',
                'message':
                'Some of the key attributes submitted are missing or mispelled.'
            }
            return jsonify(response), 400

        except AttributeError as e:
            print("\nAttributeError >>> EventController.update: " + str(e) +
                  "\n")

            if "'NoneType' object has no attribute" in str(e):
                response = {
                    'status': 'failed',
                    'message': 'Submitted without data.'
                }
                return jsonify(response), 400

            response = {'status': 'failed', 'message': 'Attribute error'}
            return jsonify(response), 400
コード例 #2
0
    def delete_participant(id, participant_id):
        try:

            event_participant = EventParticipant.query.filter(
                db.and_(EventParticipant.event_id == id,
                        EventParticipant.participant_id ==
                        participant_id)).one_or_none()
            db.session.delete(event_participant)
            db.session.commit()

            return jsonify({}), 204

        except AttributeError as e:
            print("\nAttributeError >>> EventController.delete_participant: " +
                  str(e) + "\n")

            if "'NoneType' object has no attribute" in str(e):
                response = {
                    'status': 'failed',
                    'message': 'Event or Participant not found'
                }
                return jsonify(response), 404

            response = {'status': 'failed', 'message': 'Attribute error'}
            return jsonify(), 400

        except UnmappedInstanceError as e:
            print(
                "\nUnmappedInstanceError >>> EventController.delete_participant: "
                + str(e) + "\n")
            response = {
                'status': 'failed',
                'message': 'Event or Participant not found.'
            }
            return jsonify(response), 404

        except IntegrityError as e:
            db.session.rollback()
            print("\nIntegrityError >>> EventController.delete_participant: " +
                  str(e) + "\n")

            if "foreign key constraint fails" in str(e):
                response = {
                    'status':
                    'failed',
                    'message':
                    'Some other data is dependent to this Participant, remove them first.'
                }
                return jsonify(response), 400

            response = {'status': 'failed', 'message': 'Integrity error'}
            return jsonify(response), 400
コード例 #3
0
    def delete(event_id, criteria_id):
        try:
            criteria = Criteria.query.filter(
                db.and_(Criteria.id == criteria_id,
                        Criteria.event_id == event_id)).first()
            db.session.delete(criteria)
            db.session.commit()

            return jsonify({}), 204

        except AttributeError as e:
            print("\nAttributeError >>> EventController.delete_criteria: " +
                  str(e) + "\n")

            if "'NoneType' object has no attribute" in str(e):
                response = {'status': 'failed', 'message': 'Event not found'}
                return jsonify(response), 404

            response = {'status': 'failed', 'message': 'Attribute error'}
            return jsonify(response), 400

        except UnmappedInstanceError as e:
            print(
                "\nUnmappedInstanceError >>> EventController.delete_criteria: "
                + str(e) + "\n")
            response = {'status': 'failed', 'message': 'Event not found.'}
            return jsonify(response), 404

        except IntegrityError as e:
            db.session.rollback()
            print("\nIntegrityError >>> EventController.delete_criteria: " +
                  str(e) + "\n")

            if "foreign key constraint fails" in str(e):
                response = {
                    'status':
                    'failed',
                    'message':
                    'Some other data is dependent to this Event, remove them first.'
                }
                return jsonify(response), 400

            response = {'status': 'failed', 'message': 'Integrity error'}
            return jsonify(response), 400
コード例 #4
0
    def find(event_id, criteria_id):
        try:

            criteria = Criteria.query.filter(
                db.and_(Criteria.id == criteria_id,
                        Criteria.event_id == event_id)).first()

            result = format_criteria(criteria)

            return jsonify(result), 200

        except AttributeError as e:
            print("\nAttributeError >>> EventController.find_criteria: " +
                  str(e) + "\n")

            if "'NoneType' object has no attribute" in str(e):
                response = {
                    'status': 'failed',
                    'message': 'Event or Criteria not found'
                }
                return jsonify(response), 404

            response = {'status': 'failed', 'message': 'Attribute error'}
            return jsonify(response), 400