def save(self, event = None): assert event contact = Contact(first_name = self.cleaned_data['first_name'], middle_initial = self.cleaned_data['middle_initial'], last_name = self.cleaned_data['last_name'], title = self.cleaned_data['title'], email = self.cleaned_data['email'], phone1 = self.cleaned_data['phone1'], addr1_row1 = self.cleaned_data['addr1_row1'], addr1_row2 = self.cleaned_data['addr1_row2'], addr1_city = self.cleaned_data['addr1_city'], addr1_state = self.cleaned_data['addr1_state'], addr1_zip = self.cleaned_data['addr1_zip'], addr1_country = self.cleaned_data['addr1_country']) contact.save() registrant = Registrant(event = event, contact = contact, pending = True, discount_code = self.cleaned_data['discount_code']) registrant.save() return registrant
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
def email_register(request, slug): if request.method == 'POST': contact = get(Contact, email=request.POST.get('email', None)) event = get(Event, slug=slug) registrant = Registrant(contact = contact, event = event, pending = True, discount_code = request.POST.get('discount_code', None)) try: registrant.save() except ValueError, e: if str(e) == 'Already Registered': error = 'That email address is already registered' return render_to_response('event_email_register.html', locals()) else: print e raise from django.core.mail import EmailMultiAlternatives incorrect_link = "http://"+DOMAIN+reverse('event-register-token', kwargs={'slug':slug,'token':contact.get_token()})+"/" message = render_to_string("email_register_message.txt", locals()) html_message = render_to_string("email_register_message.html", locals()) mail = EmailMultiAlternatives("Registration Confirmation for %s" %(event, ), message, FROM_EMAIL, ['"%s %s" <%s>' % (contact.first_name, contact.last_name, contact.email)] ) mail.attach_alternative(html_message, "text/html") mail.send() email_log.info("Sent Email To:%s - From:%s - Subject:%s" % (contact.email, FROM_EMAIL, "Registration Confirmation For %s" %(event, ))) return render_to_response('registration_pending.html', locals())