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_publicfield to theProductmodel that is used to exclude products from thebrowsablequeryset. Abrowsable_dashboardqueryset 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.OrderStatusChangemodel 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_TAXsetting 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_attributesmethod 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_THUMBNAILERsetting can be used to customise thumbnail generation. Support is included for Sorl and Easy Thumbnails. The default is'oscar.core.thumbnails.SorlThumbnail'.Added
oscar_thumbnailtemplate tag (toimage_tags) to generate thumbnails in templates. All uses of Sorl’sthumbnailtemplate tag in the shipped templates have been replaced withoscar_thumbnail.sorl-thumbnailhas 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.Optionobjects 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.txttocustomer/emails/commtype_product_alert_confirmation_subject.txtcustomer/alerts/emails/confirmation_body.txttocustomer/emails/commtype_product_alert_confirmation_body.txtcustomer/alerts/emails/alert_subject.txttocustomer/emails/commtype_product_alert_subject.txtcustomer/alerts/emails/alert_body.txttocustomer/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.SetPasswordFormandcustomer.forms.PasswordChangeFormhave been removed. Usedjango.contrib.auth.forms.SetPasswordFormanddjango.contrib.auth.forms.PasswordChangeForminstead.The
views.decorators.staff_member_requireddecorator has been removed. Usepermissions_required(['is_staff']instead.The
UserAddress.num_ordersproperty has been removed. Usenum_orders_as_shipping_addressandnum_orders_as_billing_addressinstead.Support has been removed for the dynamic loading of formset classes that were moved in previous releases. Projects must update their
get_classcalls to use the new paths. The paths that have changed are as follows:Old path
New path
Affected classes
basket.formsbasket.formsetsBaseBasketLineFormSetBasketLineFormSetBaseSavedLineFormSetSavedLineFormSetdashboard.catalogue.formsdashboard.catalogue.formsetsBaseStockRecordFormSetStockRecordFormSetBaseProductCategoryFormSetProductCategoryFormSetBaseProductImageFormSetProductImageFormSetBaseProductRecommendationFormSetProductRecommendationFormSetProductAttributesFormSetwishlists.formswishlists.formsetsLineFormset
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 acodeargument 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_slugifiernow usesoscar.core.utils.cautious_slugifyto handle Unicode characters in slugs whenOSCAR_SLUG_ALLOW_UNICODEisFalse.Fixed input validation for
dashboard.offers.forms.BenefitFormwhen arangewas 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_byfield oncatalogue.reviews.SortReviewsFormwas made optional and the logic inProductReviewListadjusted so that the form fields don’t have to be rendered manually because of form errors.Added a
datetime_filterstag library that provides atimedeltatemplate filter for rendering time deltas in human readable format.OSCAR_OFFER_ROUNDING_FUNCTIONpreviously 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_FIELDSconstant tocatalogue.Categoryto restrict which fields are fetched from the database when performing category comparison queries.Significantly improved the database efficiency of the
category_treetemplate 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_parenttoFalse.Renamed the modules containing the Django app config classes for Oscar apps (apart from the
oscarapp), fromconfigtoapps.Removed the
appmodules 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
applicationvariable, 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
urlsproperty. 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_APPSsetting with that of the forked app.Changed the calling signature for the
oscar_fork_appmanagement command. Theapp_labelargument is the Django app label of the app to be forked.target_pathis the directory into which the new app shall be copied.new_app_subpackageis 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_subpackageis omitted, then the package of the app being forked will be used instead.Removed the
promotionsapp. The app is now available in a separate package - django_oscar_promotions.OSCAR_MAIN_TEMPLATE_DIRsetting has been removed and existing templates updated with the full path. See #1378, #2250. Please update your templates accordingly.OSCAR_SLUG_FUNCTIONpreviously 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_unicodekwarg.
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.pymodule toapps.py.Change the
default_app_configvariable in__.init__.pyto point toappsinstead ofconfig.Update your
AppConfigsubclass in theapps.pymodule to either inherit from the parent app’sAppConfigor use eitheroscar.core.application.OscarConfigoroscar.core.application.OscarDashboardConfig.Move any changes you’ve made to the Oscar
Applicationsubclass in theapp.pymodule, to theAppConfigsubclass in theapps.pymodule. When moving thenameattribute 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
applicationimport 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.dashboardapp also needs to be forked; and the forked dashboard app’s code must live inside the forkedoscar.apps.dashboardapp’s directory.Similarly, when forking
oscar.apps.catalogue.reviews,oscar.apps.catalogueneeds to be forked as well; and the forkedoscar.apps.catalogue.reviewsapp’s code must live inside the forkedoscar.apps.catalogueapp’s directory.
Dependency changes¶
Dropped
mockas a dependency in favour ofunittests.mock.Upgraded
bootstrapto version 3.4.1.Upgraded
jqueryto 3.4.1.Dropped
jquery.inputmaskin favour ofinputmaskand upgraded to 4.0.2.Upgraded
lessto 3.8.1.Upgraded
tinymceto version 4.8.3.
Deprecated features¶
offer.Range.contains()is deprecated. Usecontains_product()instead.catalogue.managers.ProductManageris deprecated. Usecatalogue.managers.ProductQuerySet.as_manager()instead.catalogue.managers.BrowsableProductManageris deprecated. UseProduct.objects.browsable()instead.catalogue.Product.browsableis deprecated. UseProduct.objects.browsable()instead.