Customer

The customer app includes models to record product alerts and sent emails. It also contains the views that allow a customer to manage their data (profile information, shipping addresses, etc.)

Abstract models

class oscar.apps.customer.abstract_models.AbstractProductAlert(*args, **kwargs)[source]

An alert for when a product comes back in stock

save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

class oscar.apps.customer.abstract_models.AbstractUser(*args, **kwargs)[source]

An abstract base user suitable for use in Oscar projects.

This is basically a copy of the core AbstractUser model but without a username field

clean()[source]

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

email_user(subject, message, from_email=None, **kwargs)[source]

Send an email to this user.

get_full_name()[source]

Return the first_name plus the last_name, with a space in between.

get_short_name()[source]

Return the short name for the user.

save(*args, **kwargs)[source]

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

Forms

class oscar.apps.customer.forms.ConfirmPasswordForm(user, *args, **kwargs)[source]

Extends the standard django AuthenticationForm, to support 75 character usernames. 75 character usernames are needed to support the EmailOrUsername authentication backend.

property media

Return all media required to render the widgets on this form.

class oscar.apps.customer.forms.EmailAuthenticationForm(host, *args, **kwargs)[source]

Extends the standard django AuthenticationForm, to support 75 character usernames. 75 character usernames are needed to support the EmailOrUsername authentication backend.

property media

Return all media required to render the widgets on this form.

class oscar.apps.customer.forms.EmailUserCreationForm(host=None, *args, **kwargs)[source]
clean_email()[source]

Checks for existing users with the supplied email address.

property media

Return all media required to render the widgets on this form.

save(commit=True)[source]

Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.

class oscar.apps.customer.forms.OrderSearchForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]
clean()[source]

Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.

description()[source]

Uses the form’s data to build a useful description of what orders are listed.

property media

Return all media required to render the widgets on this form.

class oscar.apps.customer.forms.PasswordResetForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]

This form takes the same structure as its parent from django.contrib.auth

property media

Return all media required to render the widgets on this form.

save(domain_override=None, request=None, **kwargs)[source]

Generates a one-use only link for resetting password and sends to the user.

class oscar.apps.customer.forms.ProductAlertForm(user, product, *args, **kwargs)[source]
clean()[source]

Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.

property media

Return all media required to render the widgets on this form.

save(commit=True)[source]

Save this form’s self.instance object if commit=True. Otherwise, add a save_m2m() method to the form which can be called after the instance is saved manually at a later time. Return the model instance.

oscar.apps.customer.forms.ProfileForm

alias of oscar.apps.customer.forms.UserForm

class oscar.apps.customer.forms.UserForm(user, *args, **kwargs)[source]
clean_email()[source]

Make sure that the email address is always unique as it is used instead of the username. This is necessary because the uniqueness of email addresses is not enforced on the model level in django.contrib.auth.models.User.

property media

Return all media required to render the widgets on this form.

Views

class oscar.apps.customer.views.AccountAuthView(**kwargs)[source]

This is actually a slightly odd double form view that allows a customer to either login or register.

login_form_class

alias of oscar.apps.customer.forms.EmailAuthenticationForm

registration_form_class

alias of oscar.apps.customer.forms.EmailUserCreationForm

class oscar.apps.customer.views.AccountRegistrationView(**kwargs)[source]
form_class

alias of oscar.apps.customer.forms.EmailUserCreationForm

form_valid(form)[source]

If the form is valid, redirect to the supplied URL.

get(request, *args, **kwargs)[source]

Handle GET requests: instantiate a blank version of the form.

get_context_data(*args, **kwargs)[source]

Insert the form into the context dict.

get_form_kwargs()[source]

Return the keyword arguments for instantiating the form.

class oscar.apps.customer.views.AccountSummaryView(**kwargs)[source]

View that exists for legacy reasons and customisability. It commonly gets called when the user clicks on “Account” in the navbar.

Oscar defaults to just redirecting to the profile summary page (and that redirect can be configured via OSCAR_ACCOUNT_REDIRECT_URL), but it’s also likely you want to display an ‘account overview’ page or such like. The presence of this view allows just that, without having to change a lot of templates.

class oscar.apps.customer.views.AddressChangeStatusView(**kwargs)[source]

Sets an address as default_for_(billing|shipping)

class oscar.apps.customer.views.AddressCreateView(**kwargs)[source]
form_class

alias of oscar.apps.address.forms.UserAddressForm

get_context_data(**kwargs)[source]

Insert the form into the context dict.

get_form_kwargs()[source]

Return the keyword arguments for instantiating the form.

get_success_url()[source]

Return the URL to redirect to after processing a valid form.

model

alias of oscar.apps.address.models.UserAddress

class oscar.apps.customer.views.AddressDeleteView(**kwargs)[source]
get_queryset()[source]

Return the QuerySet that will be used to look up the object.

This method is called by the default implementation of get_object() and may not be called if get_object() is overridden.

model

alias of oscar.apps.address.models.UserAddress

class oscar.apps.customer.views.AddressListView(**kwargs)[source]

Customer address book

get_queryset()[source]

Return customer’s addresses

class oscar.apps.customer.views.AddressUpdateView(**kwargs)[source]
form_class

alias of oscar.apps.address.forms.UserAddressForm

get_context_data(**kwargs)[source]

Insert the form into the context dict.

get_form_kwargs()[source]

Return the keyword arguments for instantiating the form.

get_queryset()[source]

Return the QuerySet that will be used to look up the object.

This method is called by the default implementation of get_object() and may not be called if get_object() is overridden.

get_success_url()[source]

Return the URL to redirect to after processing a valid form.

model

alias of oscar.apps.address.models.UserAddress

class oscar.apps.customer.views.AnonymousOrderDetailView(**kwargs)[source]
get_object(queryset=None)[source]

Return the object the view is displaying.

Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.

model

alias of oscar.apps.order.models.Order

class oscar.apps.customer.views.ChangePasswordView(**kwargs)[source]
form_class

alias of django.contrib.auth.forms.PasswordChangeForm

form_valid(form)[source]

If the form is valid, redirect to the supplied URL.

get_form_kwargs()[source]

Return the keyword arguments for instantiating the form.

class oscar.apps.customer.views.EmailDetailView(**kwargs)[source]

Customer email

get_object(queryset=None)[source]

Return the object the view is displaying.

Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.

get_page_title()[source]

Append email subject to page title

class oscar.apps.customer.views.EmailHistoryView(**kwargs)[source]
get_queryset()[source]

Return Queryset of Email instances, that has been sent to the currently authenticated user.

class oscar.apps.customer.views.LogoutView(**kwargs)[source]
class oscar.apps.customer.views.OrderDetailView(**kwargs)[source]
do_reorder(order)[source]

‘Re-order’ a previous order.

This puts the contents of the previous order into your basket

get_object(queryset=None)[source]

Return the object the view is displaying.

Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.

get_page_title()[source]

Order number as page title

get_template_names()[source]

Return a list of template names to be used for the request. May not be called if render_to_response() is overridden. Return the following list:

  • the value of template_name on the view (if provided)

  • the contents of the template_name_field field on the object instance that the view is operating upon (if available)

  • <app_label>/<model_name><template_name_suffix>.html

model

alias of oscar.apps.order.models.Order

class oscar.apps.customer.views.OrderHistoryView(**kwargs)[source]

Customer order history

form_class

alias of oscar.apps.customer.forms.OrderSearchForm

get_context_data(*args, **kwargs)[source]

Get the context for this view.

get_queryset()[source]

Return Queryset of Order instances for the currently authenticated user.

model

alias of oscar.apps.order.models.Order

class oscar.apps.customer.views.OrderLineView(**kwargs)[source]

Customer order line

get_object(queryset=None)[source]

Return the object the view is displaying.

Require self.queryset and a pk or slug argument in the URLconf. Subclasses can override this to return any object.

class oscar.apps.customer.views.ProfileDeleteView(**kwargs)[source]
form_class

alias of oscar.apps.customer.forms.ConfirmPasswordForm

form_valid(form)[source]

If the form is valid, redirect to the supplied URL.

get_form_kwargs()[source]

Return the keyword arguments for instantiating the form.

class oscar.apps.customer.views.ProfileUpdateView(**kwargs)[source]
form_class

alias of oscar.apps.customer.forms.UserForm

form_valid(form)[source]

If the form is valid, redirect to the supplied URL.

get_form_kwargs()[source]

Return the keyword arguments for instantiating the form.

class oscar.apps.customer.views.ProfileView(**kwargs)[source]
get_model_field_data(model_class, field_name)[source]

Extract the verbose name and value for a model’s field value

Alerts

The alerts module provides functionality that allows customers to sign up for email alerts when out-of-stock products come back in stock. A form for signing up is displayed on product detail pages when a product is not in stock.

If the OSCAR_EAGER_ALERTS setting is True, then alerts are sent as soon as affected stock records are updated. Alternatively, the management command oscar_send_alerts can be used to send alerts periodically.

The context for the alert email body contains a hurry variable that is set to True if the number of active alerts for a product is greater than the quantity of the product available in stock.

CustomerDispatcher

oscar.apps.customer.utils.CustomerDispatcher is used to send customer emails (e.g., registration, password reset, order confirmations).

AlertsDispatcher

oscar.apps.customer.alerts.utils.AlertsDispatcher is used to send product alerts.