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 registrant.initialize_fields() 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 if not registrant.company_name: 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. NOTE: When updating this be sure to check with the anonymous registration impementation of events in the registration module. """ # arguments were getting kinda long # moved them to an unpacked version form, event, reg8n, \ price, amount = args registrant = Registrant() registrant.registration = reg8n registrant.pricing = price registrant.amount = amount registrant.override = kwargs.get('override', False) registrant.override_price = kwargs.get('override_price') registrant.discount_amount = kwargs.get('discount_amount', Decimal(0)) if registrant.override_price is None: registrant.override_price = Decimal(0) registrant.is_primary = kwargs.get('is_primary', False) custom_reg_form = kwargs.get('custom_reg_form', None) registrant.memberid = form.cleaned_data.get('memberid', '') registrant.reminder = form.cleaned_data.get('reminder', False) 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 registrant.initialize_fields() 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', '') registrant.comments = form.cleaned_data.get('comments', '') 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 if not registrant.company_name: registrant.company_name = user_profile.company registrant.position_title = user_profile.position_title registrant.save() return registrant