def save(self): # Reset user's offers if self.cleaned_data['user']: user = ESPUser.objects.get(id=self.cleaned_data['user']) user.volunteeroffer_set.all().delete() if self.cleaned_data.get('clear_requests', False): # They want to cancel all shifts - don't do anything further. return [] # Create user if one doesn't already exist, otherwise associate a user. # Note that this will create a new user account if they enter an e-mail # address different from the one on file. if not self.cleaned_data['user']: user_data = { 'first_name': self.cleaned_data['name'].split()[0], 'last_name': ' '.join(self.cleaned_data['name'].split()[1:]), 'email': self.cleaned_data['email'], } existing_users = ESPUser.objects.filter( **user_data).order_by('-id') if existing_users.exists(): # Arbitrarily pick the most recent account # This is not too important, we just need a link to an e-mail address. user = existing_users[0] else: auto_username = ESPUser.get_unused_username( user_data['first_name'], user_data['last_name']) user = ESPUser.objects.create_user(auto_username, user_data['email']) user.__dict__.update(user_data) user.save() # Record this user account as a volunteer user.makeVolunteer() # Remove offers with the same exact contact info VolunteerOffer.objects.filter(email=self.cleaned_data['email'], phone=self.cleaned_data['phone'], name=self.cleaned_data['name']).delete() offer_list = [] for req in self.cleaned_data['requests']: o = VolunteerOffer() o.user_id = user.id o.email = self.cleaned_data['email'] o.phone = self.cleaned_data['phone'] o.name = self.cleaned_data['name'] o.confirmed = self.cleaned_data['confirm'] if 'shirt_size' in self.cleaned_data: o.shirt_size = self.cleaned_data['shirt_size'] if 'shirt_type' in self.cleaned_data: o.shirt_type = self.cleaned_data['shirt_type'] if 'comments' in self.cleaned_data: o.comments = self.cleaned_data['comments'] o.request_id = req o.save() offer_list.append(o) return offer_list
def save(self): # Reset user's offers if self.cleaned_data['user']: user = ESPUser.objects.get(id=self.cleaned_data['user']) user.volunteeroffer_set.all().delete() if self.cleaned_data.get('clear_requests', False): # They want to cancel all shifts - don't do anything further. return [] # Create user if one doesn't already exist, otherwise associate a user. # Note that this will create a new user account if they enter an e-mail # address different from the one on file. if not self.cleaned_data['user']: user_data = {'first_name': self.cleaned_data['name'].split()[0], 'last_name': ' '.join(self.cleaned_data['name'].split()[1:]), 'email': self.cleaned_data['email'], } existing_users = ESPUser.objects.filter(**user_data).order_by('-id') if existing_users.exists(): # Arbitrarily pick the most recent account # This is not too important, we just need a link to an e-mail address. user = existing_users[0] else: auto_username = ESPUser.get_unused_username(user_data['first_name'], user_data['last_name']) user = ESPUser.objects.create_user(auto_username, user_data['email']) user.__dict__.update(user_data) user.save() # Record this user account as a volunteer user.makeVolunteer() # Remove offers with the same exact contact info VolunteerOffer.objects.filter(email=self.cleaned_data['email'], phone=self.cleaned_data['phone'], name=self.cleaned_data['name']).delete() offer_list = [] for req in self.cleaned_data['requests']: o = VolunteerOffer() o.user_id = user.id o.email = self.cleaned_data['email'] o.phone = self.cleaned_data['phone'] o.name = self.cleaned_data['name'] o.confirmed = self.cleaned_data['confirm'] if 'shirt_size' in self.cleaned_data: o.shirt_size = self.cleaned_data['shirt_size'] if 'shirt_type' in self.cleaned_data: o.shirt_type = self.cleaned_data['shirt_type'] if 'comments' in self.cleaned_data: o.comments = self.cleaned_data['comments'] o.request_id = req o.save() offer_list.append(o) return offer_list
def onsite_create(self, request, tl, one, two, module, extra, prog): if request.method == 'POST': form = OnSiteRegForm(request.POST) if form.is_valid(): new_data = form.cleaned_data username = ESPUser.get_unused_username(new_data['first_name'], new_data['last_name']) new_user = ESPUser.objects.create_user( username=username, first_name=new_data['first_name'], last_name=new_data['last_name'], email=new_data['email']) self.student = new_user regProf = RegistrationProfile.getLastForProgram( new_user, self.program) contact_user = ContactInfo(first_name=new_user.first_name, last_name=new_user.last_name, e_mail=new_user.email, user=new_user) contact_user.save() regProf.contact_user = contact_user student_info = StudentInfo( user=new_user, graduation_year=ESPUser.YOGFromGrade( new_data['grade'], ESPUser.program_schoolyear(self.program))) try: if isinstance(new_data['k12school'], K12School): student_info.k12school = new_data['k12school'] else: if isinstance(new_data['k12school'], int): student_info.k12school = K12School.objects.get( id=int(new_data['k12school'])) else: student_info.k12school = K12School.objects.filter( name__icontains=new_data['k12school'])[0] except: student_info.k12school = None student_info.school = new_data[ 'school'] if not student_info.k12school else student_info.k12school.name student_info.save() regProf.student_info = student_info regProf.save() if new_data['paid']: self.createBit('paid') self.updatePaid(True) else: self.updatePaid(False) self.createBit('Attended') if new_data['medical']: self.createBit('Med') if new_data['liability']: self.createBit('Liab') self.createBit('OnSite') new_user.groups.add(Group.objects.get(name="Student")) new_user.recoverPassword() return render_to_response( self.baseDir() + 'reg_success.html', request, { 'student': new_user, 'retUrl': '/onsite/%s/classchange_grid?student_id=%s' % (self.program.getUrlBase(), new_user.id) }) else: form = OnSiteRegForm() return render_to_response(self.baseDir() + 'reg_info.html', request, {'form': form})
def onsite_create(self, request, tl, one, two, module, extra, prog): if request.method == 'POST': form = OnSiteRegForm(request.POST) if form.is_valid(): new_data = form.cleaned_data username = ESPUser.get_unused_username(new_data['first_name'], new_data['last_name']) new_user = ESPUser(username = username, first_name = new_data['first_name'], last_name = new_data['last_name'], email = new_data['email'], is_staff = False, is_superuser = False) new_user.save() self.student = new_user regProf = RegistrationProfile.getLastForProgram(new_user, self.program) contact_user = ContactInfo(first_name = new_user.first_name, last_name = new_user.last_name, e_mail = new_user.email, user = new_user) contact_user.save() regProf.contact_user = contact_user student_info = StudentInfo(user = new_user, graduation_year = ESPUser.YOGFromGrade(new_data['grade'])) student_info.save() regProf.student_info = student_info regProf.save() if new_data['paid']: self.createBit('Paid') self.updatePaid(True) else: self.updatePaid(False) self.createBit('Attended') if new_data['medical']: self.createBit('MedicalFiled') if new_data['liability']: self.createBit('LiabilityFiled') self.createBit('OnSite') v = GetNode( 'V/Flags/UserRole/Student') ub = UserBit() ub.user = new_user ub.recursive = False ub.qsc = GetNode('Q') ub.verb = v ub.save() new_user.recoverPassword() return render_to_response(self.baseDir()+'reg_success.html', request, (prog, tl), { 'student': new_user, 'retUrl': '/onsite/%s/classchange_grid?student_id=%s' % (self.program.getUrlBase(), new_user.id) }) else: form = OnSiteRegForm() return render_to_response(self.baseDir()+'reg_info.html', request, (prog, tl), {'form':form, 'current_year':ESPUser.current_schoolyear()})
def onsite_create(self, request, tl, one, two, module, extra, prog): if request.method == 'POST': form = OnSiteRegForm(request.POST) if form.is_valid(): new_data = form.cleaned_data username = ESPUser.get_unused_username(new_data['first_name'], new_data['last_name']) new_user = ESPUser.objects.create_user(username = username, first_name = new_data['first_name'], last_name = new_data['last_name'], email = new_data['email']) self.student = new_user regProf = RegistrationProfile.getLastForProgram(new_user, self.program) contact_user = ContactInfo(first_name = new_user.first_name, last_name = new_user.last_name, e_mail = new_user.email, user = new_user) contact_user.save() regProf.contact_user = contact_user student_info = StudentInfo(user = new_user, graduation_year = ESPUser.YOGFromGrade(new_data['grade'], ESPUser.program_schoolyear(self.program))) try: if isinstance(new_data['k12school'], K12School): student_info.k12school = new_data['k12school'] else: if isinstance(new_data['k12school'], int): student_info.k12school = K12School.objects.get(id=int(new_data['k12school'])) else: student_info.k12school = K12School.objects.filter(name__icontains=new_data['k12school'])[0] except: student_info.k12school = None student_info.school = new_data['school'] if not student_info.k12school else student_info.k12school.name student_info.save() regProf.student_info = student_info regProf.save() if new_data['paid']: self.createBit('paid') self.updatePaid(True) else: self.updatePaid(False) self.createBit('Attended') if new_data['medical']: self.createBit('Med') if new_data['liability']: self.createBit('Liab') self.createBit('OnSite') new_user.groups.add(Group.objects.get(name="Student")) new_user.recoverPassword() return render_to_response(self.baseDir()+'reg_success.html', request, { 'student': new_user, 'retUrl': '/onsite/%s/classchange_grid?student_id=%s' % (self.program.getUrlBase(), new_user.id) }) else: form = OnSiteRegForm() return render_to_response(self.baseDir()+'reg_info.html', request, {'form':form})