Streamline Benefit and Condition name and description handling
This commit was triggered by a recursion problem mentioned here:
8199da2100 (commitcomment-7387486)
It now unifies handling for name and description across both conditions
and benefits:
* Declaring a name property is required for any proxy class. A few
classes had a description declared, but no name. But given that the
description is the more verbose version, and is allowed to include
HTML, it makes sense to still require a name. The declared
descriptions in the models that only had one property are better
suited for @name anyway.
* It drops the max_unaffected_items logic for Benefits. That was only
applied if calling via the non-proxy class, and feels more like it
should be a description anyway.
* __str__ always returns self.name. Anything more complex with that
means we might run into problems with the python_2_unicode_compatible
decorator.
I also added tests for the changes, and verified the tests fail without
my changes.
This fixes two issues:
1) The code didn't take into account that self.format will be ignored by
Django if USE_L10N=True, unless a format was specified when constructing
the Widget. Remedied by moving the code to render because the current
language is determined at request time, not at object construction time,
and looking up the correct format there.
2) The code couldn't handle date formats that include dots, like
31.12.2014.
Fixes #1440.
create_range method doesn't ignore existing ranges again
The functionality to have it fetch an existing range instead of loudly
complaining when a range already exists has been added as part of #1053.
But @codeinthehole and I agree that a method called create_range
shouldn't silently ignore an existing range, and can't think of a use
case anymore.
* Removed unused _save method. It's not called anywhere.
* Simplified comment and logic for display_order
* Reordered imports
* Used items() instead of six.iteritems() because create_range does not
get complex kwargs
* Removed a duplicate test
* Test for the correct exception
We only needed it because Django 1.4 shipped with a pretty old version
of six. Support for that has been removed, and Django 1.5 ships with six
1.6.1, which is more current than we required.
This nicely avoids an issue with django-extra-views pinning a six
version which caused the sandbox build to fail:
https://travis-ci.org/tangentlabs/django-oscar/jobs/32223978#L971
A custom app needs to inherit from Oscar's app config. This ensures the
correct app label, and that any startup code (receivers, etc.) is
executed.
Per the camp ground rule, the fork_app command has been slightly
refactored.
I think the Oscar upgrade/forking process for forked apps will get
simpler with the new migrations. One probably will be able to just fake
an initial migration, or something like that. But for now, copying
them across as we did before should be a safe bet.
The test suite brings it's own stock record model for testing. Django
1.7 requires that we only import models from apps in INSTALLED_APPS, so
we need to use it to avoid clashes.
Add support for methods on User model when checking permissions
The ``permissions_required`` decorator, and hence
``Application.permissions_map`` and
``Application.default_permissions``, now
handle both methods and properties on the User model. Previously, it
wasn't supported, but a docstring showed ``is_anonymous`` as an example,
which is a method.
Drop upper_charge logic for weight based shipping methods
Previously, weight based shipping methods accepted an upper charge
field. When no weight band matched the baskets weight, this was
returned. I am not aware of a single retailer who calculates shipping
charges like that. It's impossible to pick a sensible value for a
retailer, as there's no upper limit to the amount of items ordered, and
any shipping charges would have to cover costs for that.
This (possible backwards incompatible) change means subclassing and
customising shipping methods becomes much easier. Now that shipping
methods are stateless, we can instantiate at compile time and assign
them to the repository instance.
This commit also renames internal methods of the shipping repository
in as the 'prime' notion is no longer valid (as we're not injecting a
basket into each method).
It now takes the shipping charge rather than the method. This makes
sense as the shipping charge has normally been calculated before we need
the order total so there is no point in calculating it twice.
OSCAR_SLUG_FUNCTION: Support string notation to set slugifier
Importing things in settings is discouraged. But until now,
OSCAR_SLUG_FUNCTION could only be set as a callable, which requires
importing. It's now been updated to use the import_string function.
This completes the move away from partner wrappers to strategies. All
the methods for determining price and availability information have now
been removed from the partner classes.
The helper policy class ("DelegateToStockRecord") have been removed too
as they no longer have methods to call on the stockrecord.
We ship some apps, e.g. search, without models.py. I think that
means it is not a valid Django app for Django < 1.7. But either way,
Django 1.7 definitely allows apps without models.py, so we need to
ensure we do the right thing.
This makes it easier to customise Oscar. You can run this command to
quickly create local versions of an app that you want to customise. The
command creates the appropriate folder, __init__.py and models.py. The
only step requiring human intervention is to modify INSTALLED_APPS to
include the new app package.
Replace CsvUnicodeWriter with Python 3 compatible UnicodeCSVWriter
This required extending the UnicodeCSVWriter to be able to deal with
file-like objects as well. This is used to create downloadable CSV files
in memory.