Beispiel #1
0
def get_next_redirect_url(request, redirect_field_name="next"):
    """
    Returns the next URL to redirect to, if it was explicitly passed
    via the request.
    """
    redirect_to = get_request_param(request, redirect_field_name)
    if not get_adapter(request).is_safe_url(redirect_to):
        redirect_to = None
    return redirect_to
Beispiel #2
0
 def logout(self):
     get_adapter(self.request).add_message(
         self.request, messages.SUCCESS, 'account/messages/logged_out.txt')
     auth_logout(self.request)
Beispiel #3
0
 def get_redirect_url(self):
     return (get_next_redirect_url(self.request, self.redirect_field_name)
             or get_adapter(self.request).get_logout_redirect_url(
                 self.request))
Beispiel #4
0
    def save_user(self, request, user, form, commit=True):
        """
        Saves a new `User` instance using information provided in the
        signup form.
        """
        # from .utils import user_username, user_email, user_field

        data = form.cleaned_data

        person_pk = None
        company_pk = None
        person = None
        company = None
        # companypersonrole = None

        # Update Company Model
        company_pk_str = request.session.get('account_company', None)
        if company_pk_str:
            company_pk = url_str_to_company_pk(company_pk_str)
            company = Company.objects.get(comp_id=company_pk_str)
            if company:
                company_field(company, 'comp_name', data.get('compname'))
                company_field(company, 'comp_email', data.get('compemail'))
                company_field(company, 'comp_website', data.get('website'))
                company_field(company, 'comp_phone', data.get('phone'))
                company_field(company, 'comp_phone', data.get('phone'))
                company_field(company, 'fax', data.get('fax'))

                # Update Address for the company
                address = company.address
                Form_Data_addressline1 = data.get('addressline1')
                Form_Data_addressline2 = data.get('addressline2')
                Form_Data_zipcode = data.get('zipcode')
                Form_Data_cityopt = data.get('cityopt')
                Form_Data_city = data.get('city')
                city = None
                if (Zipcode.objects.filter(zipc_code=Form_Data_zipcode).exists()):
                    if (City.objects.filter(
                        zipc_code=Form_Data_zipcode).exists() and Form_Data_cityopt != 'None' and Form_Data_city):
                        if (City.objects.filter(name=Form_Data_city, zipc_code=Form_Data_zipcode).exists()):
                            city = City.objects.get(name=Form_Data_city, zipc_code=Form_Data_zipcode).city_id.__str__()
                        else:
                            city = City.objects.create(zipc_code=Zipcode.objects.get(zipc_code=Form_Data_zipcode),
                                                       name=Form_Data_city, city_is_user_added='Y')
                        city_id_str = city.__str__()
                    else:
                        city_id_str = Form_Data_cityopt.city_id.__str__()
                        city = City.objects.get(city_id=city_id_str).city_id.__str__()

                if Form_Data_addressline1:
                    address_field(address, 'address_line_1', Form_Data_addressline1)
                if Form_Data_addressline2:
                    address_field(address, 'address_line_2', Form_Data_addressline2)
                if city:
                    address_field(address, 'city_id', city_id_str)

                self.populate_address(request, address)
                print('Saving Changed address for Company in user adapter',address)
                address.save()
                print('Address Saved')

                #TODO : traverse the array list if language is more then one
                if(CompanyLanguage.objects.filter(comp_id=company.comp_id).exists()):
                    CompanyLanguage.objects.filter(comp_id=company.comp_id).all().delete()
                companylanguagechecklist = list(data.get('languagechecklist'))
                print('companylanguagechecklist :', len(companylanguagechecklist))
                if len(companylanguagechecklist) > 1:
                    for language in companylanguagechecklist:
                        print("companylanguagechecklist : Language.lang_code", language.lang_code)
                        adapter = get_adapter(request)
                        if (CompanyLanguage.objects.filter(comp_id=company.comp_id, lang_code=language.lang_code).exists()):
                            companylanguage = CompanyLanguage.objects.get(comp_id=company.comp_id, lang_code=language.lang_code)
                            company_language_field(companylanguage, 'lang_code',
                                                   Language.objects.get(pk=language.lang_code))
                            company_language_field(companylanguage, 'comp_id', company.comp_id)
                            if commit:
                                print('companylanguage.update()')
                                companylanguage.update()
                        else:
                            companylanguage = adapter.new_company_language(request)
                            company_language_field(companylanguage, 'lang_code',
                                                   Language.objects.get(pk=language.lang_code))
                            company_language_field(companylanguage, 'comp_id', company.comp_id)
                            if commit:
                                print('companylanguage.save()')
                                companylanguage.save()
            self.populate_company(request, company)


        ohsubscription_pk_str = request.session.get('ohaccount_subscription', None)
        print('ohsubscription_pk_str and data.get(naicslevel5opt)',ohsubscription_pk_str,data.get('naicslevel5opt'))
        if ohsubscription_pk_str and data.get('naicslevel5opt'):
            if(Subscription.objects.filter(pk=ohsubscription_pk_str).exists()):
                ohsubscription = Subscription.objects.get(pk=ohsubscription_pk_str)
                subscription_field(ohsubscription, 'naicslevel5', NaicsLevel5.objects.get(pk=data.get('naicslevel5opt').naic_level_5_code))
                print('ohsubscription.save()')
                ohsubscription.save()

        person_pk_str = request.session.get('account_person', None)
        if person_pk_str:
            person = Person.objects.get(pk=person_pk_str)
            if person:
                if (PersonLanguage.objects.filter(prsn_id=person.prsn_id).exists()):
                    PersonLanguage.objects.filter(prsn_id=person.prsn_id).all().delete()

                personlanguagechecklist = list(data.get('personlanguagechecklist'))
                print('personlanguagechecklist :', len(personlanguagechecklist))
                if len(personlanguagechecklist) > 1:
                    for language in personlanguagechecklist:
                        print("personlanguagechecklist : language.lang_code ", language.lang_code)
                        adapter = get_adapter(request)
                        if (PersonLanguage.objects.filter(prsn_id=person.prsn_id,
                                                           lang_code=language.lang_code).exists()):
                            personlanguage = PersonLanguage.objects.get(prsn_id=person.prsn_id,
                                                                          lang_code=language.lang_code)
                            person_language_field(personlanguage, 'lang_code',
                                                   Language.objects.get(pk=language.lang_code))
                            person_language_field(personlanguage, 'prsn_id', person.prsn_id)
                            if commit:
                                print('personlanguage.update()')
                                personlanguage.update()
                        else:
                            personlanguage = adapter.new_person_language(request)
                            person_language_field(personlanguage, 'lang_code',
                                                  Language.objects.get(pk=language.lang_code))
                            person_language_field(personlanguage, 'prsn_id', person.prsn_id)
                            if commit:
                                print('personlanguage.save()')
                                personlanguage.save()

        person_role_company_str = request.session.get('company_person_role', None)
        if person_role_company_str:
            print('person_role_company_str',person_role_company_str)
            if(CompanyPersonRole.objects.filter(pk=person_role_company_str).exists()):
                companypersonrole = CompanyPersonRole.objects.get(pk=person_role_company_str)
                if companypersonrole and data.get('personroles'):
                    personrole = data.get('personroles')
                    company_person_role_field(companypersonrole, 'crol_code', CompanyRole.objects.get(pk=personrole))
                    if commit:
                        print('companypersonrole.save()',companypersonrole)
                        companypersonrole.save()
                ohsubscriptiondetail_pk_str = request.session.get('ohaccount_subscriptiondetail', None)
                print('ohsubscriptiondetail_pk_str and companypersonrole', ohsubscriptiondetail_pk_str,companypersonrole)
                if (ohsubscriptiondetail_pk_str and companypersonrole):
                    if (SubscriptionDetail.objects.filter(pk=ohsubscriptiondetail_pk_str).exists()):
                        ohsubscriptiondetail = SubscriptionDetail.objects.get(pk=ohsubscriptiondetail_pk_str)
                        subscriptiondetail_field(ohsubscriptiondetail, 'cprs_id',companypersonrole)

                        ohsubscriptiondetail.save()
                        print('User_Adapter_ohsubscriptiondetail.save()')

        username = data.get('username')
        print('username = data.get(username)', username)
        if username:
            user_username(user, username)

        if 'password1' in data:
            user.set_password(data["password1"])
        else:
            user.set_unusable_password()

        if(form == 'onhand.subscription.forms.SignupForm'):
            user_field(user, 'role_code', Role.objects.get(pk=app_settings.DEFAULT_USER_ENROLMENT_ROLE))

        print('user_field(user, cprs_id, companypersonrole)',int(companypersonrole.pk))
        user_field(user, 'cprs_id', companypersonrole)

        self.populate_username(request, user)

        if commit:
            user.save()
        return user