def get(self): args = self.post_req_parser.parse_args() token = args['token'] reference_request = reference_request_repository.get_by_token( token) # type: ReferenceRequest if not reference_request: return REFRERENCE_REQUEST_WITH_TOKEN_NOT_FOUND response_id = reference_request.response_id response = response_repository.get_by_id(response_id) # type: Response if not response: return RESPONSE_NOT_FOUND event = event_repository.get_event_by_response_id( response_id) # type: Event if not event: return EVENT_NOT_FOUND reference = reference_repository.get_by_reference_request_id( reference_request.id) app_form = event.get_application_form() # type: ApplicationForm # Determine whether the response is a nomination try: candidate, _, nominator = _get_candidate_nominator(response) except ValueError as e: LOGGER.error(e) return BAD_CONFIGURATION return_object = { 'candidate': candidate, 'nominator': nominator, 'relation': reference_request.relation, 'name': event.get_name('en'), 'description': event.get_description('en'), 'is_application_open': event.is_application_open, 'email_from': event.email_from, 'reference_submitted_timestamp': reference.timestamp if reference is not None else None } return return_object, 200
def put(self): args = self.put_req_parser.parse_args() token = args['token'] uploaded_document = args['uploaded_document'] reference_request = reference_request_repository.get_by_token(token) event = event_repository.get_event_by_response_id( reference_request.response_id) reference = reference_request_repository.get_reference_by_reference_request_id( reference_request.id) if not reference_request: return REFERENCE_REQUEST_NOT_FOUND if not event.is_application_open: return APPLICATIONS_CLOSED reference.uploaded_document = uploaded_document reference_request_repository.commit() return {}, 200
def post(self): args = self.post_req_parser.parse_args() token = args['token'] uploaded_document = args['uploaded_document'] reference_request = reference_request_repository.get_by_token(token) event = event_repository.get_event_by_response_id( reference_request.response_id) if not reference_request: return REFRERENCE_REQUEST_WITH_TOKEN_NOT_FOUND if reference_request.has_reference: return DUPLICATE_REFERENCE_SUBMISSION if not event.is_application_open: return APPLICATIONS_CLOSED reference = Reference(reference_request_id=reference_request.id, uploaded_document=uploaded_document) reference_request_repository.add(reference) return {}, 201