def link_user_to_new_patient(self, appointment_details_form, user, booking): # user but no patient # create a patient and link it to existing user patient = Patient() # set the properties (just email) appointment_details_form.populate_obj(patient) self.set_gae_geography_from_headers(patient) # link to logged in user patient.user = user.key patient.email = user.get_email() # if it's a provider, copy over details like name, etc. provider = db.get_provider_from_user(user) if provider: patient.first_name = provider.first_name patient.last_name = provider.last_name patient.put() booking.patient = patient.key booking.put() # add patient role to user user.roles.append(auth.PATIENT_ROLE) user.put()
def post(self, vanity_url=None): provider = db.get_provider_from_vanity_url(vanity_url) patient_form = RegistrationDetailsForNewPatient().get_form( self.request.POST) if patient_form.validate(): booking_key_urlsafe = patient_form['booking_key'].data booking = db.get_from_urlsafe_key(booking_key_urlsafe) # create a new patient patient = Patient() patient_form.populate_obj(patient) self.set_gae_geography_from_headers(patient) patient.put() # create a new user user = self.create_empty_user_for_patient(patient) user.language = self.get_language() # set the password password = patient_form['password'].data password_hash = security.generate_password_hash(password, length=12) user.password = password_hash user.put() # login with new password self.login_user(user.get_email(), password) # store booking user = patient.user.get() booking.patient = patient.key booking.confirmed = user.confirmed = False booking.put() # send a confirmation/activation email url_obj = urlparse.urlparse(self.request.url) activation_url = urlparse.urlunparse( (url_obj.scheme, url_obj.netloc, '/login/booking/' + booking.key.urlsafe(), '', '', '')) logging.info( '(NewPatientHandler.post) generated activation url for user %s : %s ' % (patient.email, activation_url)) mail.email_booking_to_patient(self, booking, activation_url) PatientBaseHandler.render_confirmation_email_sent(self, booking) else: self.render_template('provider/public/booking_new_patient.html', provider=provider, patient_form=patient_form)
def post(self): patient_signup_form = forms.user.PatientSignupForm().get_form(self.request.POST) if patient_signup_form.validate(): # init the patient patient = Patient() patient_signup_form.populate_obj(patient) patient.put() msg = _('Thanks for your interest. We will be in touch soon!') self.render_template('user/signup_patient.html', success_message=msg, patient_signup_form=patient_signup_form) else: self.render_template('user/signup_patient.html', patient_signup_form=patient_signup_form)
def post(self, vanity_url=None): provider = db.get_provider_from_vanity_url(vanity_url) patient_form = RegistrationDetailsForNewPatient().get_form(self.request.POST) if patient_form.validate(): booking_key_urlsafe = patient_form['booking_key'].data booking = db.get_from_urlsafe_key(booking_key_urlsafe) # create a new patient patient = Patient() patient_form.populate_obj(patient) self.set_gae_geography_from_headers(patient) patient.put() # create a new user user = self.create_empty_user_for_patient(patient) user.language = self.get_language() # set the password password = patient_form['password'].data password_hash = security.generate_password_hash(password, length=12) user.password = password_hash user.put() # login with new password self.login_user(user.get_email(), password) # store booking user = patient.user.get() booking.patient = patient.key booking.confirmed = user.confirmed = False booking.put() # send a confirmation/activation email url_obj = urlparse.urlparse(self.request.url) activation_url = urlparse.urlunparse((url_obj.scheme, url_obj.netloc, '/login/booking/' + booking.key.urlsafe(), '', '', '')) logging.info('(NewPatientHandler.post) generated activation url for user %s : %s ' % (patient.email, activation_url)) mail.email_booking_to_patient(self, booking, activation_url) PatientBaseHandler.render_confirmation_email_sent(self, booking) else: self.render_template('provider/public/booking_new_patient.html', provider=provider, patient_form=patient_form)
def post(self): patient_signup_form = forms.user.PatientSignupForm().get_form( self.request.POST) if patient_signup_form.validate(): # init the patient patient = Patient() patient_signup_form.populate_obj(patient) patient.put() msg = _('Thanks for your interest. We will be in touch soon!') self.render_template('user/signup_patient.html', success_message=msg, patient_signup_form=patient_signup_form) else: self.render_template('user/signup_patient.html', patient_signup_form=patient_signup_form)
def create_test_patient(self): ''' Create a test patient (and linked user) in the datastore ''' user_created, new_user = User.create_user(self._TEST_PATIENT_EMAIL, password_raw=self._TEST_PATIENT_PASSWORD, roles=[auth.PATIENT_ROLE]) self.assertTrue(user_created) tp = Patient() tp.created_on = datetime.now() tp.user = new_user.key tp.first_name = 'Pat' tp.last_name = 'Patient' tp.email = "*****@*****.**" tp.telephone = '514-123-1234' tp.terms_agreement = True tp.put() new_user.language = 'fr' new_user.put()