def create_registrant(form, event, reg8n, **kwargs): """ Create the registrant. form is a RegistrantForm where the registrant's data is. reg8n is the Registration instance to associate the registrant with. """ custom_reg_form = kwargs.get('custom_reg_form', None) price = form.get_price() # initialize the registrant instance and data registrant = Registrant() registrant.registration = reg8n registrant.amount = price registrant.pricing = form.cleaned_data['pricing'] if custom_reg_form and isinstance(form, FormForCustomRegForm): entry = form.save(event) registrant.custom_reg_form_entry = entry user = form.get_user() if not user.is_anonymous(): registrant.user = user else: registrant.first_name = form.cleaned_data.get('first_name', '') registrant.last_name = form.cleaned_data.get('last_name', '') registrant.email = form.cleaned_data.get('email', '') registrant.phone = form.cleaned_data.get('phone', '') registrant.company_name = form.cleaned_data.get('company_name', '') # associate the registrant with a user of the form user = form.get_user() if not user.is_anonymous(): registrant.user = user try: user_profile = registrant.user.get_profile() except: user_profile = None if user_profile: registrant.mail_name = user_profile.display_name registrant.address = user_profile.address registrant.city = user_profile.city registrant.state = user_profile.state registrant.zip = user_profile.zipcode registrant.country = user_profile.country registrant.company_name = user_profile.company registrant.position_title = user_profile.position_title registrant.save() return registrant
def create_registrant_from_form(*args, **kwargs): """ Create the registrant Args are split up below into the appropriate attributes """ # arguments were getting kinda long # moved them to an unpacked version form, event, reg8n, \ price, amount = args registrant = Registrant() registrant.registration = reg8n registrant.amount = amount custom_reg_form = kwargs.get('custom_reg_form', None) if custom_reg_form and isinstance(form, FormForCustomRegForm): entry = form.save(event) registrant.custom_reg_form_entry = entry user = form.get_user() if not user.is_anonymous(): registrant.user = user else: registrant.first_name = form.cleaned_data.get('first_name', '') registrant.last_name = form.cleaned_data.get('last_name', '') registrant.email = form.cleaned_data.get('email', '') registrant.phone = form.cleaned_data.get('phone', '') registrant.company_name = form.cleaned_data.get('company_name', '') if registrant.email: users = User.objects.filter(email=registrant.email) if users: registrant.user = users[0] try: user_profile = registrant.user.get_profile() except: user_profile = None if user_profile: registrant.mail_name = user_profile.display_name registrant.address = user_profile.address registrant.city = user_profile.city registrant.state = user_profile.state registrant.zip = user_profile.zipcode registrant.country = user_profile.country registrant.company_name = user_profile.company registrant.position_title = user_profile.position_title registrant.save() return registrant