def put(self): args = self.req_parser.parse_args() if len(args['name']) == 0 or len(args['description']) == 0: return EVENT_MUST_CONTAIN_TRANSLATION if set(args['name']) != set(args['description']): return EVENT_TRANSLATION_MISMATCH event = event_repository.get_by_id(args['id']) if not event: return EVENT_NOT_FOUND if event_repository.exists_by_key( args['key']) and args['key'] != event.key: return EVENT_KEY_IN_USE user_id = g.current_user["id"] current_user = user_repository.get_by_id(user_id) if not current_user.is_event_admin(event.id): return FORBIDDEN event.update(args['name'], args['description'], args['start_date'], args['end_date'], args['key'], args['organisation_id'], args['email_from'], args['url'], args['application_open'], args['application_close'], args['review_open'], args['review_close'], args['selection_open'], args['selection_close'], args['offer_open'], args['offer_close'], args['registration_open'], args['registration_close'], args['travel_grant'], args['miniconf_url']) db.session.commit() event = event_repository.get_by_id(event.id) return event, 200
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
def post(self): args = self.req_parser.parse_args() user_id = g.current_user["id"] current_user = user_repository.get_by_id(user_id) if not current_user.is_admin: return FORBIDDEN if event_repository.exists_by_key(args['key']): return EVENT_KEY_IN_USE if len(args['name']) == 0 or len(args['description']) == 0: return EVENT_MUST_CONTAIN_TRANSLATION if set(args['name']) != set(args['description']): return EVENT_TRANSLATION_MISMATCH event = Event(args['name'], args['description'], args['start_date'], args['end_date'], args['key'], args['organisation_id'], args['email_from'], args['url'], args['application_open'], args['application_close'], args['review_open'], args['review_close'], args['selection_open'], args['selection_close'], args['offer_open'], args['offer_close'], args['registration_open'], args['registration_close'], EventType[args['event_type'].upper()], args['travel_grant'], args['miniconf_url']) event.add_event_role('admin', user_id) event = event_repository.add(event) event = event_repository.get_by_id(event.id) return event, 201
def post(self): args = self.req_parser.parse_args() registration_id = args['registration_id'] user_id = g.current_user['id'] try: current_user = UserRepository.get_by_id(user_id) registration, offer = RegistrationRepository.get_by_id_with_offer( registration_id) if not current_user.is_registration_admin(offer.event_id): return errors.FORBIDDEN registration.confirm() registration_user = UserRepository.get_by_id(offer.user_id) registration_event = EventRepository.get_by_id(offer.event_id) if _send_registration_confirmation_mail(registration_user, registration_event): registration.confirmation_email_sent_at = datetime.now() db.session.commit() return 'Confirmed Registration for {} {}'.format( registration_user.firstname, registration_user.lastname), 200 except Exception as e: LOGGER.error( 'Error occured while confirming registration with id {}: {}'. format(registration_id, e)) return errors.DB_NOT_AVAILABLE
def get(self): event_id = request.args['id'] event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND else: event_org = event_repository.get_by_id_with_organisation(event.id) return event_details(event_org), 200
def post(self, send_email=True): args = self.req_parser.parse_args() event_id = args['event_id'] email = args['email'] role = args['role'] user = user_repository.get_by_email(email, g.organisation.id) if not user: return USER_NOT_FOUND event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND existingInvitedGuest = db.session.query(InvitedGuest).filter( InvitedGuest.event_id == event_id).filter( InvitedGuest.user_id == user.id).first() if existingInvitedGuest: return INVITED_GUEST_FOR_EVENT_EXISTS invitedGuest = InvitedGuest(event_id=event_id, user_id=user.id, role=role) db.session.add(invitedGuest) try: db.session.commit() except IntegrityError: LOGGER.error("Failed to add invited guest: {}".format(email)) return ADD_INVITED_GUEST_FAILED if send_email: try: send_mail(recipient=user.email, subject='Your invitation to {}'.format(event.name), body_text=GUEST_EMAIL_TEMPLATE.format( user_title=user.user_title, firstname=user.firstname, lastname=user.lastname, role=role, event_name=event.name, event_key=event.key, system_name=g.organisation.system_name, host=misc.get_baobab_host())) except Exception as e: LOGGER.error( 'Failed to send email to invited guest with user Id {}, due to {}' .format(user.id, e)) return INVITED_GUEST_EMAIL_FAILED return invitedGuest_info(invitedGuest, user), 201
def post(self, send_email=True): args = self.req_parser.parse_args() event_id = args['event_id'] email = args['email'] role = args['role'] user = user_repository.get_by_email(email, g.organisation.id) if not user: return USER_NOT_FOUND event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND existingInvitedGuest = db.session.query(InvitedGuest).filter( InvitedGuest.event_id == event_id).filter(InvitedGuest.user_id == user.id).first() if existingInvitedGuest: return INVITED_GUEST_FOR_EVENT_EXISTS invitedGuest = InvitedGuest( event_id=event_id, user_id=user.id, role=role ) db.session.add(invitedGuest) try: db.session.commit() except IntegrityError: LOGGER.error( "Failed to add invited guest: {}".format(email)) return ADD_INVITED_GUEST_FAILED if send_email: try: email_user( 'guest-invitation-with-registration' if event.is_registration_open else 'guest-invitation', template_parameters=dict( role=role, system_name=g.organisation.system_name, host=misc.get_baobab_host(), event_key=event.key ), event=event, user=user) except Exception as e: LOGGER.error('Failed to send email to invited guest with user Id {}, due to {}'.format(user.id, e)) return INVITED_GUEST_EMAIL_FAILED return invitedGuest_info(invitedGuest, user), 201
def post(self, event_id): req_parser = reqparse.RequestParser() req_parser.add_argument('user_id', type=int, required=True) req_parser.add_argument('outcome', type=str, required=True) args = req_parser.parse_args() event = event_repository.get_by_id(event_id) if not event: return errors.EVENT_NOT_FOUND user = user_repository.get_by_id(args['user_id']) if not user: return errors.USER_NOT_FOUND try: status = Status[args['outcome']] except KeyError: return errors.OUTCOME_STATUS_NOT_VALID try: # Set existing outcomes to no longer be the latest outcome existing_outcomes = outcome_repository.get_all_by_user_for_event(args['user_id'], event_id) for existing_outcome in existing_outcomes: existing_outcome.reset_latest() # Add new outcome outcome = Outcome( event_id, args['user_id'], status, g.current_user['id']) outcome_repository.add(outcome) db.session.commit() if status != Status.ACCEPTED: # Email will be sent with offer for accepted candidates email_user( 'outcome-rejected' if status == Status.REJECTED else 'outcome-waitlist', template_parameters=dict( host=misc.get_baobab_host() ), event=event, user=user, ) return outcome, 201 except SQLAlchemyError as e: LOGGER.error("Database error encountered: {}".format(e)) return errors.DB_NOT_AVAILABLE except: LOGGER.error("Encountered unknown error: {}".format(traceback.format_exc())) return errors.DB_NOT_AVAILABLE
def put(self): args = self.req_parser.parse_args() event = event_repository.get_by_id(args['id']) if not event: return EVENT_NOT_FOUND user_id = g.current_user["id"] current_user = user_repository.get_by_id(user_id) if not current_user.is_event_admin(event.id): return FORBIDDEN _date_format = '%Y-%m-%dT%H:%M:%S.%fZ' name = args['name'] description = args['description'] start_date = datetime.strptime((args['start_date']), _date_format) end_date = datetime.strptime((args['end_date']), _date_format) key = args['key'] organisation_id = args['organisation_id'] email_from = args['email_from'] url = args['url'] application_open = datetime.strptime((args['application_open']), _date_format) application_close = datetime.strptime((args['application_close']), _date_format) review_open = datetime.strptime((args['review_open']), _date_format) review_close = datetime.strptime((args['review_close']), _date_format) selection_open = datetime.strptime((args['selection_open']), _date_format) selection_close = datetime.strptime((args['selection_close']), _date_format) offer_open = datetime.strptime((args['offer_open']), _date_format) offer_close = datetime.strptime((args['offer_close']), _date_format) registration_open = datetime.strptime((args['registration_open']), _date_format) registration_close = datetime.strptime((args['registration_close']), _date_format) event.update(name, description, start_date, end_date, key, organisation_id, email_from, url, application_open, application_close, review_open, review_close, selection_open, selection_close, offer_open, offer_close, registration_open, registration_close) try: db.session.commit() except IntegrityError: LOGGER.error("Event with KEY: {} already exists".format(key)) return EVENT_KEY_IN_USE event_org = event_repository.get_by_id_with_organisation(event.id) return event_details(event_org), 200
def get(self, event_id): event = event_repository.get_by_id(event_id) if not event: return errors.EVENT_NOT_FOUND try: outcomes = outcome_repository.get_latest_for_event(event_id) return outcomes except SQLAlchemyError as e: LOGGER.error("Database error encountered: {}".format(e)) return errors.DB_NOT_AVAILABLE except: LOGGER.error("Encountered unknown error: {}".format(traceback.format_exc())) return errors.DB_NOT_AVAILABLE
def get(self): args = self.get_req_parser.parse_args() event_id = args['event_id'] current_user_id = g.current_user['id'] event = event_repository.get_by_id(event_id) if not event: return errors.EVENT_NOT_FOUND if not event.has_application_form(): return errors.FORM_NOT_FOUND form = event.get_application_form() responses = response_repository.get_all_for_user_application(current_user_id, form.id) return responses
def post(self, event_id): parser = reqparse.RequestParser() parser.add_argument('response_ids', type=int, required=True, action='append') parser.add_argument('reviewer_email', type=str, required=True) args = parser.parse_args() response_ids = args['response_ids'] reviewer_email = args['reviewer_email'] filtered_response_ids = response_repository.filter_ids_to_event( response_ids, event_id) print('response_ids:', response_ids) print('filtered_response_ids:', filtered_response_ids) if set(filtered_response_ids) != set(response_ids): return FORBIDDEN event = event_repository.get_by_id(event_id) reviewer_user = user_repository.get_by_email(reviewer_email, g.organisation.id) if reviewer_user is None: return USER_NOT_FOUND if not reviewer_user.is_reviewer(event_id): _add_reviewer_role(reviewer_user.id, event_id) response_reviewers = [ ResponseReviewer(response_id, reviewer_user.id) for response_id in response_ids ] db.session.add_all(response_reviewers) db.session.commit() if len(response_ids) > 0: email_user('reviews-assigned', template_parameters=dict( num_reviews=len(response_ids), baobab_host=misc.get_baobab_host(), system_name=g.organisation.system_name, event_key=event.key), event=event, user=reviewer_user) return {}, 201
def post(self): args = self.post_req_parser.parse_args() user_id = g.current_user['id'] event_id = args['event_id'] reviewer_user_email = args['reviewer_user_email'] num_reviews = args['num_reviews'] event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND current_user = user_repository.get_by_id(user_id) if not current_user.is_event_admin(event_id): return FORBIDDEN reviewer_user = user_repository.get_by_email(reviewer_user_email, g.organisation.id) if reviewer_user is None: return USER_NOT_FOUND if not reviewer_user.is_reviewer(event_id): _add_reviewer_role(reviewer_user.id, event_id) config = review_configuration_repository.get_configuration_for_event( event_id) response_ids = self.get_eligible_response_ids( event_id, reviewer_user.id, num_reviews, config.num_reviews_required) response_reviewers = [ ResponseReviewer(response_id, reviewer_user.id) for response_id in response_ids ] db.session.add_all(response_reviewers) db.session.commit() if len(response_ids) > 0: email_user('reviews-assigned', template_parameters=dict( num_reviews=len(response_ids), baobab_host=misc.get_baobab_host(), system_name=g.organisation.system_name, event_key=event.key), event=event, user=reviewer_user) return {}, 201
def post(self): args = self.req_parser.parse_args() user_api = UserAPI.UserAPI() user, status = user_api.post(invitedGuest=True) if status != 201: return user, status invited_guest_api = InvitedGuestAPI() invited_guest_info, status = invited_guest_api.post(send_email=False) if status == 201: event_id = invited_guest_info['event_id'] role = invited_guest_info['role'] user = user_repository.get_by_id(user['id']) event = event_repository.get_by_id(event_id) reset_code = misc.make_code() password_reset = PasswordReset(user=user) db.session.add(password_reset) db.session.commit() try: send_mail(recipient=user.email, subject='Your invitation to {}'.format(event.name), body_text=NEW_GUEST_EMAIL_TEMPLATE.format( user_title=user.user_title, firstname=user.firstname, lastname=user.lastname, role=role, event_name=event.name, event_key=event.key, system_name=g.organisation.system_name, host=misc.get_baobab_host(), reset_code=password_reset.code)) except Exception as e: LOGGER.error( 'Failed to send email for invited guest with user Id {} due to: {}' .format(user.id, e)) return INVITED_GUEST_EMAIL_FAILED return invited_guest_info, status
def post(self): args = self.req_parser.parse_args() user_api = UserAPI.UserAPI() user, status = user_api.post(invitedGuest=True) if status != 201: return user, status invited_guest_api = InvitedGuestAPI() invited_guest_info, status = invited_guest_api.post(send_email=False) if status == 201: event_id = invited_guest_info['event_id'] role = invited_guest_info['role'] user = user_repository.get_by_id(user['id']) event = event_repository.get_by_id(event_id) reset_code = misc.make_code() password_reset=PasswordReset(user=user) db.session.add(password_reset) db.session.commit() try: email_user( 'new-guest-registration' if event.is_registration_open else 'new-guest-no-registration', template_parameters=dict( event_key=event.key, system_name=g.organisation.system_name, host=misc.get_baobab_host(), role=role, reset_code=password_reset.code, ), event=event, user=user ) except Exception as e: LOGGER.error('Failed to send email for invited guest with user Id {} due to: {}'.format(user.id, e)) return INVITED_GUEST_EMAIL_FAILED return invited_guest_info, status
def put(self): # Update an existing response for the logged-in user. req_parser = reqparse.RequestParser() args = self.req_parser.parse_args() try: user_id = verify_token(request.headers.get('Authorization'))['id'] registration = db.session.query(Registration).filter( Registration.id == args['registration_id']).one_or_none() if registration is None: return 'Registration not found', 404 db_offer = db.session.query(Offer).filter( Offer.id == registration.offer_id).one_or_none() if db_offer is None: return errors.OFFER_NOT_FOUND if db_offer.user_id != user_id: return errors.FORBIDDEN registration.registration_form_id = args['registration_form_id'] db.session.commit() for answer_args in args['answers']: answer = db.session.query(RegistrationAnswer).filter( RegistrationAnswer.registration_question_id == answer_args['registration_question_id'], RegistrationAnswer.registration_id == args['registration_id']).one_or_none() if answer is not None: answer.value = answer_args['value'] elif db.session.query(RegistrationQuestion).filter( RegistrationQuestion.id == answer_args['registration_question_id']).one(): answer = RegistrationAnswer( registration_id=registration.id, registration_question_id=answer_args[ 'registration_question_id'], value=answer_args['value']) db.session.add(answer) db.session.commit() current_user = user_repository.get_by_id(user_id) registration_answers = db.session.query(RegistrationAnswer).filter( RegistrationAnswer.registration_id == registration.id).all() registration_questions = db.session.query( RegistrationQuestion).filter( RegistrationQuestion.registration_form_id == args['registration_form_id']).all() registration_form = db.session.query(RegistrationForm).filter( RegistrationForm.id == args['registration_form_id']).first() event = event_repository.get_by_id(registration_form.event_id) self.send_confirmation(current_user, registration_questions, registration_answers, registration.confirmed, event) return 200 except Exception as e: return 'Could not access DB', 400
def post(self): # Save a new response for the logged-in user. req_parser = reqparse.RequestParser() args = self.req_parser.parse_args() offer_id = args['offer_id'] try: offer = db.session.query(Offer).filter( Offer.id == offer_id).first() if not offer: return errors.OFFER_NOT_FOUND user_id = verify_token(request.headers.get('Authorization'))['id'] if not user_id: return errors.USER_NOT_FOUND current_user = db.session.query(AppUser).filter( AppUser.id == user_id).first() registration_form = db.session.query(RegistrationForm).filter( RegistrationForm.id == args['registration_form_id']).first() if not registration_form: return errors.REGISTRATION_FORM_NOT_FOUND registration = Registration( offer_id=args['offer_id'], registration_form_id=args['registration_form_id'], confirmed=True if (not offer.payment_required) else False, confirmation_email_sent_at=date.today()) db.session.add(registration) db.session.commit() event = event_repository.get_by_id(registration_form.event_id) for answer_args in args['answers']: if db.session.query(RegistrationQuestion).filter( RegistrationQuestion.id == answer_args['registration_question_id']).first(): answer = RegistrationAnswer( registration_id=registration.id, registration_question_id=answer_args[ 'registration_question_id'], value=answer_args['value']) db.session.add(answer) db.session.commit() registration_answers = db.session.query(RegistrationAnswer).filter( RegistrationAnswer.registration_id == registration.id).all() registration_questions = db.session.query( RegistrationQuestion).filter( RegistrationQuestion.registration_form_id == args['registration_form_id']).all() self.send_confirmation(current_user, registration_questions, registration_answers, registration.confirmed, event) # 201 is 'CREATED' status code return marshal(registration, self.registration_fields), 201 except SQLAlchemyError as e: LOGGER.error("Database error encountered: {}".format(e)) return errors.DB_NOT_AVAILABLE except Exception as e: LOGGER.error("Encountered unknown error: {}".format( traceback.format_exc())) return errors.DB_NOT_AVAILABLE
def get(self, event_id): event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND num_responses = response_repository.get_total_count_by_event(event_id) num_submitted_respones = response_repository.get_submitted_count_by_event( event_id) num_withdrawn_responses = response_repository.get_withdrawn_count_by_event( event_id) submitted_response_timeseries = _process_timeseries( response_repository.get_submitted_timeseries_by_event(event_id)) review_config = review_config_repository.get_configuration_for_event( event_id) required_reviews = 1 if review_config is None else review_config.num_reviews_required reviews_completed = review_repository.get_count_reviews_completed_for_event( event_id) reviews_incomplete = review_repository.get_count_reviews_incomplete_for_event( event_id) reviews_unallocated = review_repository.count_unassigned_reviews( event_id, required_reviews) reviews_timeseries = _process_timeseries( review_repository.get_review_complete_timeseries_by_event( event_id)) offers_allocated = offer_repository.count_offers_allocated(event_id) offers_accepted = offer_repository.count_offers_accepted(event_id) offers_rejected = offer_repository.count_offers_rejected(event_id) offers_timeseries = _process_timeseries( offer_repository.timeseries_offers_accepted(event_id)) num_registrations = registration_repository.count_registrations( event_id) num_guests = guest_registration_repository.count_guests(event_id) num_registered_guests = guest_registration_repository.count_registered_guests( event_id) registration_timeseries = _process_timeseries( registration_repository.timeseries_registrations(event_id)) guest_registration_timeseries = _process_timeseries( guest_registration_repository.timeseries_guest_registrations( event_id)) registration_timeseries = _combine_timeseries( registration_timeseries, guest_registration_timeseries) return { 'num_responses': num_responses, 'num_submitted_responses': num_submitted_respones, 'num_withdrawn_responses': num_withdrawn_responses, 'submitted_timeseries': submitted_response_timeseries, 'reviews_completed': reviews_completed, 'review_incomplete': reviews_incomplete, 'reviews_unallocated': reviews_unallocated, 'reviews_complete_timeseries': reviews_timeseries, 'offers_allocated': offers_allocated, 'offers_accepted': offers_accepted, 'offers_rejected': offers_rejected, 'offers_accepted_timeseries': offers_timeseries, 'num_registrations': num_registrations, 'num_guests': num_guests, 'num_registered_guests': num_registered_guests, 'registration_timeseries': registration_timeseries }, 200
def get(self): event_id = request.args['id'] event = event_repository.get_by_id(event_id) if not event: return EVENT_NOT_FOUND return event
def post(self): # Process arguments args = self.req_parser.parse_args() event_id = args['event_id'] work_address = args['work_address'] if args[ 'work_address'] is not None else ' ' addressed_to = args['addressed_to'] or 'Whom it May Concern' residential_address = args['residential_address'] passport_name = args['passport_name'] passport_no = args['passport_no'] passport_issued_by = args['passport_issued_by'] passport_expiry_date = datetime.strptime( (args['passport_expiry_date']), '%Y-%m-%d') registration_event = EventRepository.get_by_id(event_id) if (registration_event is not None): to_date = registration_event.end_date from_date = registration_event.start_date else: return errors.EVENT_ID_NOT_FOUND # Finding registation_id for this user at this event user_id = verify_token(request.headers.get('Authorization'))['id'] offer = db.session.query(Offer).filter( Offer.user_id == user_id).filter( Offer.event_id == event_id).first() registration_form = db.session.query(RegistrationForm).filter( RegistrationForm.event_id == event_id).first() if not registration_form: return errors.REGISTRATION_FORM_NOT_FOUND # Check if Guest Registration registration = None registration = db.session.query(GuestRegistration).filter( GuestRegistration.user_id == user_id).filter( GuestRegistration.registration_form_id == registration_form.id).first() if registration: is_guest_registration = True else: is_guest_registration = False # Normal Registration if (not registration) and offer: registration = db.session.query(Registration).filter( Registration.offer_id == offer.id).first() if not registration: return errors.REGISTRATION_NOT_FOUND try: if (is_guest_registration): invitation_letter_request = InvitationLetterRequest( guest_registration_id=registration.id, event_id=event_id, work_address=work_address, addressed_to=addressed_to, residential_address=residential_address, passport_name=passport_name, passport_no=passport_no, passport_issued_by=passport_issued_by, passport_expiry_date=passport_expiry_date, to_date=to_date, from_date=from_date) else: invitation_letter_request = InvitationLetterRequest( registration_id=registration.id, event_id=event_id, work_address=work_address, addressed_to=addressed_to, residential_address=residential_address, passport_name=passport_name, passport_no=passport_no, passport_issued_by=passport_issued_by, passport_expiry_date=passport_expiry_date, to_date=to_date, from_date=from_date) db.session.add(invitation_letter_request) db.session.commit() except Exception as e: LOGGER.error( 'Failed to add invitation letter request for user id {} due to: {}' .format(user_id, e)) return errors.ADD_INVITATION_REQUEST_FAILED invitation_template = None if (is_guest_registration): invitation_template = (db.session.query(InvitationTemplate).filter( InvitationTemplate.send_for_both_travel_accommodation == False ).filter( InvitationTemplate.send_for_travel_award_only == False).filter( InvitationTemplate.send_for_accommodation_award_only == False).first()) elif (offer.accommodation_award and offer.accepted_accommodation_award and offer.travel_award and offer.accepted_travel_award): invitation_template = db.session.query(InvitationTemplate).filter( InvitationTemplate.event_id == offer.event_id).filter( InvitationTemplate.send_for_both_travel_accommodation == True).first() elif (offer.travel_award and offer.accepted_travel_award): invitation_template = db.session.query(InvitationTemplate).filter( InvitationTemplate.event_id == offer.event_id).filter( InvitationTemplate.send_for_travel_award_only == True).first() elif (offer.accommodation_award and offer.accepted_accommodation_award): invitation_template = db.session.query(InvitationTemplate).filter( InvitationTemplate.event_id == offer.event_id).filter( InvitationTemplate.send_for_accommodation_award_only == True).first() else: invitation_template = (db.session.query(InvitationTemplate).filter( InvitationTemplate.send_for_both_travel_accommodation == False ).filter( InvitationTemplate.send_for_travel_award_only == False).filter( InvitationTemplate.send_for_accommodation_award_only == False).first()) template_url = invitation_template.template_path user = db.session.query(AppUser).filter(AppUser.id == user_id).first() country_of_residence = db.session.query(Country).filter( Country.id == user.residence_country_id).first() nationality = db.session.query(Country).filter( Country.id == user.nationality_country_id).first() if user.user_dateOfBirth is not None: date_of_birth = user.user_dateOfBirth.strftime("%Y-%m-%d") else: return errors.MISSING_DATE_OF_BIRTH # Poster registration bringing_poster = "" poster_registration_question = db.session.query( RegistrationQuestion).filter( RegistrationQuestion.headline == "Will you be bringing a poster?").first() if poster_registration_question is not None: poster_answer = (db.session.query(RegistrationAnswer).join( Registration, RegistrationAnswer.registration_id == Registration.id).join( Offer, Offer.id == Registration.offer_id).filter( Offer.user_id == user_id).filter( RegistrationAnswer.registration_question_id == poster_registration_question.id).first()) if poster_answer is not None and poster_answer.value == 'yes': bringing_poster = "The participant will be presenting a poster of their research." # Handling fields invitation_letter_request.invitation_letter_sent_at = datetime.now() is_sent = generate( template_path=template_url, event_id=event_id, work_address=work_address, addressed_to=addressed_to, residential_address=residential_address, passport_name=passport_name, passport_no=passport_no, passport_issued_by=passport_issued_by, invitation_letter_sent_at=invitation_letter_request. invitation_letter_sent_at.strftime("%Y-%m-%d"), expiry_date=passport_expiry_date.strftime("%Y-%m-%d"), to_date=to_date.strftime("%Y-%m-%d"), from_date=from_date.strftime("%Y-%m-%d"), country_of_residence=country_of_residence.name, nationality=nationality.name, date_of_birth=date_of_birth, email=user.email, user_title=user.user_title, firstname=user.firstname, lastname=user.lastname, bringing_poster=bringing_poster, user=user) if not is_sent: return errors.SENDING_INVITATION_FAILED try: db.session.commit() return invitation_info(invitation_letter_request), 201 except Exception as e: LOGGER.error( "Failed to add invitation request for user with email: {} due to {}" .format(user.email, e)) return errors.ADD_INVITATION_REQUEST_FAILED
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
def put(self): # Update an existing response for the logged-in user. args = self.req_parser.parse_args() try: user_id = verify_token(request.headers.get('Authorization'))['id'] registration = db.session.query(GuestRegistration).filter( GuestRegistration.id == args['guest_registration_id']).one_or_none() if registration is None: return 'Registration not found', 404 registration.registration_form_id = args['registration_form_id'] db.session.commit() for answer_args in args['answers']: answer = db.session.query(GuestRegistrationAnswer).filter( GuestRegistrationAnswer.registration_question_id == answer_args['registration_question_id'], GuestRegistrationAnswer.guest_registration_id == args['guest_registration_id']).one_or_none() if answer is not None: answer.value = answer_args['value'] elif db.session.query(RegistrationQuestion).filter( RegistrationQuestion.id == answer_args['registration_question_id']).one(): answer = GuestRegistrationAnswer( guest_registration_id=registration.id, registration_question_id=answer_args[ 'registration_question_id'], value=answer_args['value']) db.session.add(answer) db.session.commit() current_user = user_repository.get_by_id(user_id) registration_answers = db.session.query( GuestRegistrationAnswer).filter( GuestRegistrationAnswer.guest_registration_id == registration.id).all() registration_questions = db.session.query( RegistrationQuestion).filter( RegistrationQuestion.registration_form_id == args['registration_form_id']).all() registration_form = db.session.query(RegistrationForm).filter( RegistrationForm.id == args['registration_form_id']).first() event = event_repository.get_by_id(registration_form.event_id) email_sent = self.send_confirmation(current_user, registration_questions, registration_answers, event) if email_sent: registration.confirmation_email_sent_at = date.today() db.session.commit() return 200 except Exception as e: return 'Could not access DB', 400