Beispiel #1
0
    def delete(self):
        args = self.req_parser.parse_args()
        event_id = args['event_id']
        user_id = args['user_id']
        registration_user_id = g.current_user['id']

        registration_user = user_repository.get_by_id(registration_user_id)
        if not registration_user.is_registration_volunteer(event_id):
            return FORBIDDEN

        event = event_repository.get_by_id(event_id)
        if event is None:
            return EVENT_NOT_FOUND

        user = user_repository.get_by_id(user_id)
        if user is None:
            return USER_NOT_FOUND

        attendance = attendance_repository.get(event_id, user_id)
        if attendance is None:
            return ATTENDANCE_NOT_FOUND

        attendance_repository.delete(attendance)

        return 200
Beispiel #2
0
    def test_delete_attendance(self):
        self.seed_static_data()
        self.setup_delete_attendance()
        header = self.get_auth_header_for('*****@*****.**')
        params = {'user_id': 1, 'event_id': 1}

        response = self.app.delete(
            '/api/v1/attendance', headers=header, data=params)

        attendance = attendance_repository.get(1, 1)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(attendance, None)
Beispiel #3
0
    def post(self):
        args = self.req_parser.parse_args()
        event_id = args['event_id']
        user_id = args['user_id']
        registration_user_id = g.current_user['id']

        registration_user = user_repository.get_by_id(registration_user_id)
        if not registration_user.is_registration_volunteer(event_id):
            return FORBIDDEN

        event = event_repository.get_by_id(event_id)
        if event is None:
            return EVENT_NOT_FOUND

        user = user_repository.get_by_id(user_id)
        if user is None:
            return USER_NOT_FOUND

        if attendance_repository.exists(event_id, user_id):
            return ATTENDANCE_ALREADY_CONFIRMED

        attendance = Attendance(event_id, user_id, registration_user_id)
        attendance_repository.create(attendance)

        send_mail(recipient=user.email,
                  subject='Welcome to {}'.format(event.name),
                  body_text=ATTENDANCE_EMAIL_BODY.format(
                      user_title=user.user_title,
                      first_name=user.firstname,
                      last_name=user.lastname,
                      event_name=event.name))

        # Other Fields
        unavailable_response = None
        invitedguest_role = unavailable_response
        is_invited_guest = unavailable_response
        has_accepted_accom_award = unavailable_response

        offer = db.session.query(Offer).filter(
            Offer.user_id == user_id).filter(
                Offer.event_id == event_id).first()
        if offer:
            has_accepted_accom_award = (offer.accommodation_award
                                        and offer.accepted_accommodation_award)

        # Check if invited guest
        invited_guest = db.session.query(InvitedGuest).filter(
            InvitedGuest.event_id == event_id).filter(
                InvitedGuest.user_id == user.id).first()
        if (invited_guest):
            is_invited_guest = True
            invitedguest_role = invited_guest.role

        # Shirt Size
        shirt_answer = (
            get_registration_answer_based_headline(user_id, "T-Shirt Size")
            and get_registration_answer_based_headline(
                user_id, "T-Shirt Size").value) or unavailable_response

        # Poster registration
        bringing_poster = False
        poster_answer = get_registration_answer_based_headline(
            user_id, "Will you be bringing a poster?")
        if (poster_answer is not None and poster_answer.value == 'yes'):
            bringing_poster = True

        attendance_user = AttendanceUser(attendance, has_accepted_accom_award,
                                         shirt_answer, is_invited_guest,
                                         bringing_poster, invitedguest_role)
        return attendance_user, 201
Beispiel #4
0
 def setup_delete_attendance(self):
     attendance = Attendance(1, 1, 2)
     attendance_repository.create(attendance)