Oscar 2.0 release notes¶
- release
2019-07-04
Welcome to Oscar 2.0. This is a significant release which includes a number of new features and backwards incompatible changes. In particular the way Oscar configures apps has been refactored and projects that have forked apps will need to follow the section on Migrating forked apps.
Compatibility¶
Oscar 2.0 is compatible with Django 1.11, Django 2.1 and Django 2.2 as well as Python 3.5, 3.6 and 3.7.
Support for Python 2.7 and Python 3.4 has been dropped.
What’s new in Oscar 2.0?¶
Added an
is_public
field to theProduct
model that is used to exclude products from thebrowsable
queryset. Abrowsable_dashboard
queryset is provided for use in the dashboard, which includes non-public products. This is a model change, so you will need to run the supplied migrations.Added an
order.OrderStatusChange
model that is used to log order status changes applied byOrder.set_status()
. This is a new model, so you will need to run the supplied migrations.Added an
OSCAR_OFFERS_INCL_TAX
setting which can be used to configure whether offer discounts are applied on the tax-inclusive amount. This defaults toFalse
, to preserve the original behaviour of discount application.Added database index definitions for commonly queried fields in a range of models. See #2875. This will require projects that have forked Oscar apps to generate corresponding migrations.
Added a
filter_by_attributes
method on theProductQuerySet
, to allow database-level filtering of products by attribute.Added support for re-ordering product images in the dashboard, and for adding an arbitrary number of additional images into the formset.
Added an
OSCAR_THUMBNAILER
setting can be used to customise thumbnail generation. Support is included for Sorl and Easy Thumbnails. The default is'oscar.core.thumbnails.SorlThumbnail'
.Added
oscar_thumbnail
template tag (toimage_tags
) to generate thumbnails in templates. All uses of Sorl’sthumbnail
template tag in the shipped templates have been replaced withoscar_thumbnail
.sorl-thumbnail
has been dropped as a dependency. Usepip install django-oscar[sorl-thumbnail]
orpip install django-oscar[easy-thumbnails]
to explicitly install the dependencies for either of the two supported thumbnailers.Added the ability to manage
catalogue.Option
objects from the dashboard.
Removal of deprecated features¶
Product alert emails are now sent as Communication Events and the deprecated product alert email templates have been removed. The templates for these emails have been replaced as follows:
customer/alerts/emails/confirmation_subject.txt
tocustomer/emails/commtype_product_alert_confirmation_subject.txt
customer/alerts/emails/confirmation_body.txt
tocustomer/emails/commtype_product_alert_confirmation_body.txt
customer/alerts/emails/alert_subject.txt
tocustomer/emails/commtype_product_alert_subject.txt
customer/alerts/emails/alert_body.txt
tocustomer/emails/commtype_product_alert_body.txt
Support for category URLs without a primary key has been removed.
Enforcement of unique slugs for categories has also been removed, as enforcing this was inefficient and not thread safe. Since a primary key is now required for category URLs, there is no need for slugs to be unique.
customer.forms.SetPasswordForm
andcustomer.forms.PasswordChangeForm
have been removed. Usedjango.contrib.auth.forms.SetPasswordForm
anddjango.contrib.auth.forms.PasswordChangeForm
instead.The
views.decorators.staff_member_required
decorator has been removed. Usepermissions_required(['is_staff']
instead.The
UserAddress.num_orders
property has been removed. Usenum_orders_as_shipping_address
andnum_orders_as_billing_address
instead.Support has been removed for the dynamic loading of formset classes that were moved in previous releases. Projects must update their
get_class
calls to use the new paths. The paths that have changed are as follows:Old path
New path
Affected classes
basket.forms
basket.formsets
BaseBasketLineFormSet
BasketLineFormSet
BaseSavedLineFormSet
SavedLineFormSet
dashboard.catalogue.forms
dashboard.catalogue.formsets
BaseStockRecordFormSet
StockRecordFormSet
BaseProductCategoryFormSet
ProductCategoryFormSet
BaseProductImageFormSet
ProductImageFormSet
BaseProductRecommendationFormSet
ProductRecommendationFormSet
ProductAttributesFormSet
wishlists.forms
wishlists.formsets
LineFormset
Minor changes¶
Dropped
action=""
andaction="."
attributes, following the lead of Django and as per the HTML5 specification.Replaced use of Django’s procedural authentication views with the corresponding class-based views.
OrderPlacementMixin.get_message_context()
is now passed acode
argument specifying the communication event type code for the message being sent.We’ve dropped the dependency on Unidecode due to license incompatibilities,
oscar.core.utils.default_slugifier
now usesoscar.core.utils.cautious_slugify
to handle Unicode characters in slugs whenOSCAR_SLUG_ALLOW_UNICODE
isFalse
.Fixed input validation for
dashboard.offers.forms.BenefitForm
when arange
was specified but other fields were empty.Fixed calculation of weight-based shipping charges in cases where the basket weight is an exact multiple of a weight band’s upper limit.
The
sort_by
field oncatalogue.reviews.SortReviewsForm
was made optional and the logic inProductReviewList
adjusted so that the form fields don’t have to be rendered manually because of form errors.Added a
datetime_filters
tag library that provides atimedelta
template filter for rendering time deltas in human readable format.OSCAR_OFFER_ROUNDING_FUNCTION
previously accepted a function as its value. It now only accepts a dotted path to a function as its valueFixed the logic of
offers.Range.all_products()
to make it consistent withRange.contains_product()
in excluding products specified inexcluded_product_ids
.Added a
COMPARISON_FIELDS
constant tocatalogue.Category
to restrict which fields are fetched from the database when performing category comparison queries.Significantly improved the database efficiency of the
category_tree
template tag.Order confirmation emails now include an order status link for authenticated users, as well as guest users, and order status is displayed consistently in both logged-in and anonymous order detail views.
Fixed display of styled HTML emails in account email detail views, wrapping them in an iframe to avoid leakage of styles into the page.
Bootstrap datetime picker JS/CSS assets removed from base layout, see #2584.
Oscar’s 500 error template no longer inherits other templates and does not use any template template tags and styling to avoid potential errors caused by the template itself (see #2971).
Line discounts are now capped to a minimum of zero - i.e., negative discounts will not be reported.
Backwards incompatible changes in Oscar 2.0¶
Redirection to the parent detail view for child products is disabled by default. Child products now have their own detail view, which allows displaying their price and images independently from the parent product. To revert to the previous behaviour of redirecting to the parent product, set
oscar.apps.catalogue.views.ProductDetailView.enforce_parent
toFalse
.Renamed the modules containing the Django app config classes for Oscar apps (apart from the
oscar
app), fromconfig
toapps
.Removed the
app
modules of Oscar apps, moving the configuration (related to permissions, URLconfs, and feature hiding) they contained into the apps’ Django app config classes. They include the following attributes:name
(since renamednamespace
),login_url
,hidable_feature_name
,permissions_map
, anddefault_permissions
; methods: :meth:get_urls
, :meth:post_process_urls
, :meth:get_permissions
, :meth:get_url_decorator
, and :meth:urls
; and their respective view classes. The composite config classes for normal Oscar apps are subclasses ofoscar.core.application.OscarConfig
(previouslyoscar.core.application.Application
), and for Oscar Dashboard appsoscar.core.application.OscarDashboardConfig
(previouslyoscar.core.application.DashboardApplication
).Removed the
application
variable, which previously held an Oscar app config instance, from the Oscar app config module. A single Django/Oscar app config instance is now registered in the Django app registry, for each app label. It should be obtained by looking it up in the Django app registry.Changed the values returned by the Oscar app config
urls
property. It now returns a tuple containing the list of URL patterns, the app namespace (which could previously be None, but not any more), and the instance namespace (which would previously be overridden by the app namespace, if left blank, but must now be explicitly set). To include URLs with an instance namespace, use the formapp_config.urls
, and to include URLs without an instance namespace, use the formdjango.conf.urls.include(app_config.urls[0])
.Removed
oscar.get_core_apps
. Overriding apps is now done by replacing the Oscar app entry in theINSTALLED_APPS
setting with that of the forked app.Changed the calling signature for the
oscar_fork_app
management command. Theapp_label
argument is the Django app label of the app to be forked.target_path
is the directory into which the new app shall be copied.new_app_subpackage
is the optional dotted path to the package of the new app, from which, together with thetarget_path
, the full Python path to the app will be derived. Ifnew_app_subpackage
is omitted, then the package of the app being forked will be used instead.Removed the
promotions
app. The app is now available in a separate package - django_oscar_promotions.OSCAR_MAIN_TEMPLATE_DIR
setting has been removed and existing templates updated with the full path. See #1378, #2250. Please update your templates accordingly.OSCAR_SLUG_FUNCTION
previously accepted a function as its value. It now only accepts a dotted path to a function as its value. Such functions must also now take aallow_unicode
kwarg.
Migrating forked apps¶
In release 2.0 the way apps are configured has been substantially refactored to
merge Oscar’s Application
class with Django’s AppConfig
class. For
each app that you have forked, you will need to:
Rename the
config.py
module toapps.py
.Change the
default_app_config
variable in__.init__.py
to point toapps
instead ofconfig
.Update your
AppConfig
subclass in theapps.py
module to either inherit from the parent app’sAppConfig
or use eitheroscar.core.application.OscarConfig
oroscar.core.application.OscarDashboardConfig
.Move any changes you’ve made to the Oscar
Application
subclass in theapp.py
module, to theAppConfig
subclass in theapps.py
module. When moving thename
attribute over, rename it tonamespace
. Your merged app config class should end up having anamespace
(for declaring the URL application namespace) as well asname
(for configuring thedjango.apps.config.AppConfig.name
) attribute.In your project URLconf and in get_urls methods replace the
application
import by finding the app in the Django app registry.
from django.apps import apps
application = apps.get_app_config('your_app_name')
If the urls you’re including don’t define an instance namespace then use
include(application.urls[0])
, which only passes in the list of URL patterns.Note
Because of the way dynamic class loading now works, when forking dashboard apps, the
oscar.apps.dashboard
app also needs to be forked; and the forked dashboard app’s code must live inside the forkedoscar.apps.dashboard
app’s directory.Similarly, when forking
oscar.apps.catalogue.reviews
,oscar.apps.catalogue
needs to be forked as well; and the forkedoscar.apps.catalogue.reviews
app’s code must live inside the forkedoscar.apps.catalogue
app’s directory.
Dependency changes¶
Dropped
mock
as a dependency in favour ofunittests.mock
.Upgraded
bootstrap
to version 3.4.1.Upgraded
jquery
to 3.4.1.Dropped
jquery.inputmask
in favour ofinputmask
and upgraded to 4.0.2.Upgraded
less
to 3.8.1.Upgraded
tinymce
to version 4.8.3.
Deprecated features¶
offer.Range.contains()
is deprecated. Usecontains_product()
instead.catalogue.managers.ProductManager
is deprecated. Usecatalogue.managers.ProductQuerySet.as_manager()
instead.catalogue.managers.BrowsableProductManager
is deprecated. UseProduct.objects.browsable()
instead.catalogue.Product.browsable
is deprecated. UseProduct.objects.browsable()
instead.