def _registration_created(self, registration, management, **kwargs): if management: return regform = registration.registration_form personal_data_form = g.pop('personal_data_form', None) if not regform.cern_access_request or not regform.cern_access_request.is_active or not personal_data_form: return req = get_last_request(registration.event) if not req or not req.data['during_registration']: return required = req.data['during_registration_required'] if not required and not personal_data_form.request_cern_access.data: return license_plate = ( sanitize_license_plate(personal_data_form.license_plate.data) if personal_data_form.license_plate.data else None ) registration.cern_access_request = CERNAccessRequest(birth_date=personal_data_form.birth_date.data, nationality=personal_data_form.nationality.data, birth_place=personal_data_form.birth_place.data, license_plate=license_plate, request_state=CERNAccessRequestState.not_requested, reservation_code='')
def _process(self): start_dt, end_dt = get_access_dates(self.cern_access_request) expired = now_utc() > end_dt form = AccessIdentityDataForm() access_request = self.registration.cern_access_request email_ticket = self.registration.registration_form.ticket_on_email if access_request is not None and not access_request.has_identity_info and form.validate_on_submit( ): if expired: raise Forbidden form.populate_obj(access_request, skip={'license_plate'}) access_request.license_plate = ( sanitize_license_plate(form.license_plate.data) if form.by_car.data and form.license_plate.data else None) db.session.flush() # if the user has entered car plate info, we have to provide it to ADAMS if form.by_car.data: send_adams_post_request(self.event, [self.registration], update=True) if email_ticket: send_ticket(self.registration) return redirect( url_for('.access_identity_data', self.registration.locator.uuid)) return WPAccessRequestDetails.render_template( 'identity_data_form.html', self.event, form=form, access_request=access_request, start_dt=start_dt, end_dt=end_dt, expired=expired, email_ticket=email_ticket)
def validate_license_plate(self, field): if self.by_car.data and not sanitize_license_plate(field.data): raise ValidationError(_('Please insert a valid license plate number!'))
def test_license_plate_handling_error(): assert sanitize_license_plate('') is None assert sanitize_license_plate('------') is None assert sanitize_license_plate('123/456') is None assert sanitize_license_plate('VALID 1234 \U0001F4A9') is None
def test_license_plate_handling(input, expected): assert sanitize_license_plate(input) == expected