def createUser(fullname=None, email=None, mobile=None, college=None): try: newUser = User.objects.get(username = email.split('@')[0]) except User.DoesNotExist: newUser = User() newUser.email = email newUser.username = email.split('@')[0] newUser.first_name = fullname newUser.set_password('default') newUser.is_active = True newUser.save() # Get the college try: newCollege = College.objects.get(name = college) except: newCollege = College.objects.get_or_create(name = 'Default', city = 'Default', state = 'Default') # Create the user's profile newUserProfile = UserProfile() newUserProfile.user = newUser newUserProfile.mobile_number = mobile newUserProfile.gender = 'F' newUserProfile.age = 0 newUserProfile.shaastra_id = 'SHA' + str(1400000 + newUser.id) newUserProfile.college = newCollege newUserProfile.branch = 'Others' newUserProfile.want_accomodation = False newUserProfile.save() return newUser
def register(request,reg_form=None,coll_form=None): dajax=Dajax() if request.method=='POST': form = RegistrationForm(deserialize_form(reg_form)) collegeform = CollegeForm(deserialize_form(coll_form)) if form.is_valid(): if not collegeform.is_valid(): collist = form.cleaned_data['college'].split('|') collquery = College.objects.using(mainsite_db).filter(name = collist[0],city=collist[1], state=collist[2]) if collquery.count(): college=collquery[0] else: college = College(name=collist[0],city=collist[1],state=collist[2]) college.save(using='mainsite') else: college = collegeform.instance college.save(using='mainsite') cleaned_form = form.cleaned_data shaastraid = cleaned_form['shaastra_id'] if not id_in_db(shaastraid): new_user = User(first_name=cleaned_form['first_name'],last_name=cleaned_form['last_name'],username=cleaned_form['username'],email=cleaned_form['email']) new_user.set_password('default') new_user.is_active = True new_user.save(using='mainsite') userprofile = UserProfile(user=new_user, gender = cleaned_form['gender'], branch = cleaned_form['branch'], age = cleaned_form['age'], mobile_number = cleaned_form['mobile_number'], college_roll = cleaned_form['college_roll'], college = college, shaastra_id = shaastraid, ) userprofile.save(using='mainsite') else: userprofile = get_userprofile(shaastraid) userprofile.gender = cleaned_form['gender'] userprofile.branch = cleaned_form['branch'] userprofile.age = cleaned_form['age'] userprofile.mobile_number = cleaned_form['mobile_number'] userprofile.college_roll = cleaned_form['college_roll'] userprofile.college = college userprofile.save(using='mainsite') new_form = IndividualForm(initial={'shaastra_ID':shaastraid}) html_content = render_to_string('hospi/Checkin_form.html',locals(),RequestContext(request)) dajax.assign('#tab3',"innerHTML",html_content) return dajax.json() else: show_alert(dajax,"error","Form is invalid") return dajax.json()