Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.contrib.localflavor.us.us_states import STATE_CHOICES
- from django import forms
- from django.contrib.localflavor.us.forms import USPhoneNumberField, USStateField
- from satchmo.contact.models import Contact
- from atsi.models import JoinRequest
- from django.forms.util import ErrorList
- from django.utils.safestring import mark_safe
- from atsi.models import *
- from django.contrib.formtools.wizard import FormWizard
- from django.forms.widgets import RadioSelect, CheckboxSelectMultiple, PasswordInput, Select
- from django.http import HttpResponseRedirect
- from django.core.urlresolvers import reverse
- from atsi.atsi_settings import COUNTRIES
- from django.contrib.auth.models import User
- import datetime
- from satchmo.shop.models import Cart
- from django.contrib.sites.models import Site
- from django.contrib.auth.views import login
- from ImageFile import raise_ioerror
- class ATSIMembershipWizard(FormWizard):
- def get_template(self, step):
- return ['signup/membership/wizard_%s.html' % step]
- def done(self, request, form_list):
- form_copy = request.POST.copy()#contact info
- membershiptypes = form_copy['0-membershiptypes']
- name = form_copy['1-name']
- website = form_copy['1-website']
- city = form_copy['1-city']
- zip = form_copy['1-zip']
- addressln1 = form_copy['1-addressln1']
- addressln2 = form_copy['1-addressln2']
- addressln3 = form_copy['1-addressln3']
- tollfree = form_copy['1-tollfree']
- description = form_copy['1-description']
- fax = form_copy['1-fax']
- opt_outlisting = form_copy['1-opt_outlisting']
- state = form_copy['1-state']
- phone = form_copy['1-phone']
- country = form_copy['1-country']
- platforms = form_copy['2-platforms']
- equipment_types = form_copy['2-equipment_types']
- services = form_copy['2-services']
- affilitates = form_copy['2-affilitates']
- username = form_copy['3-username']
- password = form_copy['3-password']
- password2 = form_copy['3-password2']
- first_name = form_copy['3-first_name']
- last_name = form_copy['3-last_name']
- dob = form_copy['3-dob']
- email = form_copy['3-email']
- date_time_created = datetime.datetime.now()
- # create a user
- try:
- u = User(username=username, first_name=first_name, last_name=last_name, email=email, password=password)
- u.save()
- login(request, u)
- except ValueError:
- print "error"
- #create contact
- try:
- c = Contact(first_name=first_name, last_name=last_name, user=u, email=email, create_date=date_time_created)
- c.save()
- except ValueError:
- print "error"
- #create ATSIOrganization
- try:
- membership_type = MembershipType.objects.get(id=membershiptypes)
- except ValueError:
- print "error"
- try:
- org = ATSIOrganization(membership_type=membership_type, name=name, role='Atsi Member')
- org.save()
- except ValueError:
- print "error"
- try:
- site = Site.objects.get_current()
- newcart = Cart(site=site)
- newcart.save()
- request.session['cart'] = newcart.id
- except ValueError:
- print "error"
- try:
- newcart.add_item(membership_type.product.product, number_added=1)
- newcart.save()
- except ValueError:
- print "error"
- return HttpResponseRedirect(reverse('DUMMY_satchmo_checkout-step2'))
- class AtsiMembershipType(forms.Form):
- membershiptypes = forms.ModelChoiceField(MembershipType.objects.filter(published=True), widget=RadioSelect(), label='Choose The Size of Your Company', empty_label=None)
- def clean(self):
- cleaned_data = self.cleaned_data
- membershiptypes = self.cleaned_data.get('membershiptypes')
- if not membershiptypes :
- msg = "Please Select One"
- self._errors["membershiptypes"] = ErrorList([msg])
- class AtsiMembershipCompanyInfo1(forms.Form):
- platforms = forms.ModelMultipleChoiceField(CommunicationPlatform.objects.filter(published=True), widget=CheckboxSelectMultiple(), label='Which communication platforms do you use?')
- affilitates = forms.ModelMultipleChoiceField(RegionalAffiliate.objects.filter(published=True), widget=CheckboxSelectMultiple(), label='What Affiliations does your company have?')
- equipment_types = forms.ModelMultipleChoiceField(EquipmentType.objects.filter(published=True), widget=CheckboxSelectMultiple(), label='Which Type of Equipment does your company use?')
- services = forms.ModelMultipleChoiceField(ServiceOffered.objects.filter(published=True), widget=CheckboxSelectMultiple(), label='Which services does your company provide?')
- class AtsiMembershipCompanyInfo(forms.ModelForm):
- ATSI_STATE_CHOICES = list(STATE_CHOICES)
- ATSI_STATE_CHOICES.insert(0, ('', '---------'))
- COUNTRY_CHOICES = list(COUNTRIES)
- COUNTRY_CHOICES.insert(0, ('', '---------'))
- phone = USPhoneNumberField(label="Phone Number")
- state = USStateField(widget=Select(choices=ATSI_STATE_CHOICES))
- city = forms.CharField(required=True)
- country = forms.CharField(widget=Select(choices=COUNTRY_CHOICES))
- def __init__(self, *args, **kw):
- super(forms.ModelForm, self).__init__(*args, **kw)
- self.fields.keyOrder = [
- 'opt_outlisting',
- 'name',
- 'country',
- 'addressln1',
- 'addressln2',
- 'addressln3',
- 'city',
- 'state',
- 'zip',
- 'phone',
- 'fax',
- 'tollfree',
- 'website',
- 'description', ]
- class Meta:
- model=ATSIOrganization
- class AtsiMembershipAdminInfo(forms.ModelForm):
- title = forms.CharField(max_length=100)
- username = forms.CharField(max_length=100, label="Create Username")
- password = forms.CharField(max_length=100, widget=PasswordInput(), label="Create Password" )
- password2 = forms.CharField(max_length=100, widget=PasswordInput(), label="Re-Type Password" )
- def __init__(self, *args, **kw):
- super(forms.ModelForm, self).__init__(*args, **kw)
- self.fields.keyOrder = [
- 'username',
- 'password',
- 'password2',
- 'first_name',
- 'last_name',
- 'dob',
- 'email',
- ]
- def clean(self):
- cleaned_data = self.cleaned_data
- title = self.cleaned_data.get('title')
- username = self.cleaned_data.get('username')
- password = self.cleaned_data.get('password')
- email = self.cleaned_data.get('email')
- #check to make sure the username has not been used
- if User.objects.filter(username=username).count() >0:
- msg = "This username is already in use"
- self._errors["username"] = ErrorList([msg])
- if User.objects.filter(email=email).count() > 0:
- msg = "This Email is already in use"
- self._errors["email"] = ErrorList([msg])
- class Meta:
- model=Contact
- class EmployeeSignUpForm(forms.Form):
- first_name = forms.CharField(max_length=50)
- last_name = forms.CharField(max_length=50)
- phone_number = USPhoneNumberField()
- email = forms.EmailField()
- selected_organization = forms.CharField(max_length=100, label="Enter a Company")
- def clean(self):
- cleaned_data = self.cleaned_data
- first_name = cleaned_data.get('first_name')
- last_name = cleaned_data.get('last_name')
- phone_number = cleaned_data.get('phone_number')
- email = cleaned_data.get('email')
- selected_organization = cleaned_data.get('selected_organization')
- form_msg = None;
- #If a user has already submitted a company request raise General Validation Error
- # To tell if they have already submitted a request use the email they have entered
- existing_join_requests = JoinRequest.objects.filter(email=email).count()
- if existing_join_requests > 0:
- user_exists = True
- else:
- user_exists = False
- companies = ATSIOrganization.objects.filter(name=selected_organization).count()
- if companies > 0:
- company_exists = True
- else:
- company_exists = False
- if user_exists :
- msg = "This Email Is already associated with an Join Request"
- self._errors["email"] = ErrorList([msg])
- existing_joinrequest = JoinRequest.objects.get(email=email)
- hash = existing_joinrequest.hash
- vmsg = mark_safe("To cancel your current Join Request for %s please %s:" % (selected_organization, '<a href="/signup/joinrequest/cancel/?hs='+hash+'&type=1" %}">click here</a>'))
- #form_msg = forms.ValidationError(vmsg)
- if not company_exists:
- msg = "Please Select A Valid Company"
- self._errors["selected_organization"] = ErrorList([msg])
- # if form_msg and company_exists: raise form_msg
- return cleaned_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement