def login_staff(request): if request.method == "POST": redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '') form = AuthenticationForm(data=request.POST) if form.is_valid(): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) try: request.session['django_language'] = user.get_profile( ).language except: request.session['django_language'] = get_setting( 'default_language') netloc = urlparse.urlparse(redirect_to)[1] # Use default setting if redirect_to is empty if not redirect_to: redirect_to = '/' # Security check -- don't allow redirection to a different # host. elif netloc and netloc != request.get_host(): redirect_to = '/' return redirect(redirect_to) else: form = AuthenticationForm(request) return render(request, 'login.html', locals())
def __init__(self, *args, **kwargs): super(SATaxForm, self).__init__(*args, **kwargs) self.fields['applies_to'].empty_label = _('Everything') self.fields['shipping_to_region'].empty_label = _('Worldwide') self.fields['applies_after_promos'].label = _( "Applies after Coupons and Promotions") self.fields['applies_to_free_items'].label = _("Applies to Free Items") self.fields['applies_to_manufacturer_promos'].label = _( "Applies to Manufacturer Coupons and Promotions") self.fields['applies_to_delivery'].label = _( "Applies to Shipping and Delivery charges") if get_setting('front_personal_account_allowed') != 'True': self.fields[ 'applies_to_personal_accounts'].widget = forms.HiddenInput() if get_setting('front_business_account_allowed') != 'True': self.fields[ 'applies_to_business_accounts'].widget = forms.HiddenInput()
def get_currency(user, shop=None): default_currency = get_setting('default_currency') if user.is_superuser: return default_currency value = None if shop: value = shop.default_currency if not value: value = get_ba_settings(user).get('default_currency') return value or default_currency
def get_default_setting(key, user, shop=None): if user.is_superuser: return if key not in dict(BRAND_SETTING_KEY_CHOICES): return value = None if shop and shop.owner: value = get_ba_settings(shop.owner).get(key) if not value: value = get_ba_settings(user).get(key) if not value and key in dict(SETTING_KEY_CHOICES): value = get_setting(key) return value
def __init__(self, user=None, having_orders=False, *args, **kwargs): initial = kwargs.get('initial', {}) if user is not None: initial = get_ba_settings(user).copy() initial['default_currency'] = initial.get('default_currency') \ or get_setting('default_currency') initial['starting_invoice_number'] = initial.get('starting_invoice_number') \ or get_setting('starting_invoice_number') initial['use_after_tax_price'] = initial.get('use_after_tax_price') \ or get_setting('use_after_tax_price') initial['use_after_tax_price'] = initial[ 'use_after_tax_price'] == 'True' initial['order_require_confirmation'] = initial.get( 'order_require_confirmation') == 'True' initial['unique_items'] = initial.get('unique_items') == 'True' super(SABrandSettingsForm, self).__init__(initial=initial, *args, **kwargs) if having_orders: self.fields['use_after_tax_price'].widget = \ forms.CheckboxInput({'disabled': 'true'})
def get_brand_currency(user): default_currency = get_setting('default_currency') value = get_ba_settings(user).get('default_currency') return value or default_currency
def __init__(self,*args,**kwargs): super(UserProfileForm,self).__init__(*args,**kwargs) if 'instance' not in kwargs.keys(): self.fields['language'].initial = get_setting('default_language')
def get_object(self): user = super(DeleteUserView, self).get_object() self.object, created = UserProfile.objects.get_or_create( user=user, defaults={"language": get_setting('default_language')}) return self.object
def get_initial(self): initials = super(CreateUserView, self).get_initial() initials.update({"language": get_setting('default_language')}) return initials