def org_new(request): error = None args = {} if isUserLogged(request): usr_details = request.session['usr_details'] if request.POST: formOrg = CYMOrganisationCreationForm(request.POST) formAddress = AddressForm(request.POST) if formOrg.is_valid() & formAddress.is_valid(): address = Address() organisation = Organisation() settings = OrgSettings() address.address_line1 = formAddress.cleaned_data['address_line1'] address.address_line2 = formAddress.cleaned_data['address_line2'] address.address_city = formAddress.cleaned_data['address_city'] address.address_state = formAddress.cleaned_data['address_state'] pin = formAddress.cleaned_data['address_pincode'] address.address_pincode = pin address.address_status = True organisation.org_name = formOrg.cleaned_data['org_name'] organisation.org_brand = formOrg.cleaned_data['org_brand'] organisation.org_phone = formOrg.cleaned_data['org_phone'] organisation.org_active = formOrg.cleaned_data['org_active'] organisation.org_emailid = formOrg.cleaned_data['org_emailid'] settings.orgsettings_status = formOrg.cleaned_data['org_active'] try: with transaction.atomic(): address.save() settings.save() organisation.org_address = address organisation.org_settings = settings organisation.save() organisation.org_billing_id = organisation.org_id identifier = str(organisation.org_id) + '_' + organisation.org_brand organisation.org_identifier = identifier.replace(" ", "") organisation.save() success = createSuperUserAndGroup(organisation.org_emailid,organisation.org_phone,organisation,'Super Admin',organisation.org_identifier) if success: print 'Super User Created' else: print 'Error while creating super user' send_mail_to_org_admin(organisation) args['usr_details'] = usr_details args['new_org_added'] = organisation.org_name args['new_org_id'] = organisation.org_id return render_to_response('org_dashboard.html',args) except IntegrityError: traceback.print_exc() error = 'Error creating new organisation' else: error = 'Error creating new organisation. Invalid form!' else: formOrg = CYMOrganisationCreationForm() formAddress = AddressForm() args.update(csrf(request)) args['formOrg'] = formOrg args['formAddress'] = formAddress args['usr_details'] = usr_details args['error'] = error return render_to_response('org_new.html',args) else: return userSessionExpired()