Customer

The customer app bundles communication with customers. This 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.AbstractCommunicationEventType(*args, **kwargs)[source]

A ‘type’ of communication. Like an order confirmation email.

get_messages(ctx=None)[source]

Return a dict of templates with the context merged in

We look first at the field templates but fail over to a set of file templates that follow a conventional path.

name

Name is the friendly description of an event for use in the admin

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

This is a record of all emails sent to a customer. Normally, we only record order-related emails.

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

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 auth backend.

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 auth backend.

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

Checks for existing users with the supplied email address.

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.

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

save(domain_override=None, use_https=False, 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__’.

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 aways unique as it is used instead of the username. This is necessary because the unique-ness of email addresses is not enforced on the model level in django.contrib.auth.models.User.

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 the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

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 the list of items for this view.

The return value must be an iterable and may be an instance of QuerySet in which case QuerySet specific behavior will be enabled.

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.

Alerts are sent using the Communication Event framework.