Commit Graph

10218 Commits

Author SHA1 Message Date
Ramiro Morales 5782c94f23 Added generation of SQLite FK DDL in initial migrations.
SQLite accepts the relevant standard SQL (although by default it doesn't
enforce the constraint), and the 'traditional' creation backend helper
generate it, so this allows us to:

- Maintain the status quo
- Improve readability of the SQL code generated for that backend.

Also, we will need this for when we fix Refs #14204.
2013-12-28 18:00:16 -03:00
Claude Paroz 6d66ba5948 Fixed #21242 -- Allowed more IANA schemes in URLValidator
Thanks Sascha Peilicke for the report and initial patch, and
Tim Graham for the review.
2013-12-28 21:25:32 +01:00
Aymeric Augustin 9f13c33281 Removed the only_installed argument of Apps.get_models.
Refs #15903, #15866, #15850.
2013-12-28 20:54:26 +01:00
Aymeric Augustin ba7206cd81 Changed get_model to raise an exception on errors.
Returning None on errors required unpythonic error checking and was
inconsistent with get_app_config.

get_model was a private API until the previous commit, but given that it
was certainly used in third party software, the change is explained in
the release notes.

Applied the same change to get_registered_model, which is a new private
API introduced during the recent refactoring.
2013-12-28 20:53:00 +01:00
Aymeric Augustin 54790e669d Simplified Apps.get_model and added AppConfig.get_model.
Documented them as public APIs.
2013-12-28 20:43:29 +01:00
Aymeric Augustin 81354b82bf Stopped calling apps.get_model with only_installed=False.
ContentTypes are only created for installed applications, and I could
make a case for not returning a model that isn't installed any more.
The check for stale ContentTypes in update_contenttypes doesn't use
model_class.

ModelSignal actually needs get_registered_model since the lookup happens
at import time. I took this opportunity to perform a small refactoring.
2013-12-28 20:42:58 +01:00
Aymeric Augustin bbdf01e00a Populated non-master app registries.
This removes the gap between the master app registry and ad-hoc app
registries created by the migration framework, specifically in terms
of behavior of the get_model[s] methods.

This commit contains a stealth feature that I'd rather not describe.
2013-12-28 20:37:42 +01:00
ijl 71a03e01aa Fixed #20346 -- Made cache middleware vary on the full URL.
Previously, only the URL path was included in the cache key.

Thanks jamey for the suggestion.
2013-12-28 11:20:18 -05:00
Florian Apolloner 280c1a65cc Worked around a bug in python 3.3.3. Refs #21093 2013-12-28 15:25:16 +01:00
Ramiro Morales 6a6136141b Implemented #10164 for new schema migration code.
Made it use 'AUTOINCREMENT' suffix for PK creation. This way it doeesn't
regress when compared with the 'traditional' DB backend creation
infrastructure.

Refs #10164.
2013-12-28 11:21:01 -03:00
Florian Apolloner f28ea02308 Fixed #21093 -- Ensured that mails are not base64 encoded on python 3.3.3+.
Thanks to Arfrever for the report and Aymeric for the review.
2013-12-28 12:42:33 +01:00
Aymeric Augustin c81fae6b95 Used app_label instead of appname.
The last component of the dotted path to the application module is
consistently referenced as the application "label". For instance it's
AppConfig.label. appname could be confused with AppConfig.name, which is
the full dotted path.
2013-12-28 09:53:02 +01:00
Aymeric Augustin a7add2f296 Migrated built-in AppCommands to use handle_app_config. 2013-12-28 09:43:06 +01:00
Aymeric Augustin bb8ec71f61 Updated the AppCommand API to support apps without a models module. 2013-12-28 09:42:59 +01:00
Aymeric Augustin aff57793b4 Simplified the implementation of register_model.
register_model is called exactly once in the entire Django code base, at the
bottom of ModelBase.__new__:

    new_class._meta.apps.register_model(new_class._meta.app_label, new_class)

ModelBase.__new__ exits prematurely 120 lines earlier (sigh) if a model with
the same name is already registered:

    if new_class._meta.apps.get_registered_model(new_class._meta.app_label, name):
        return

(This isn't the exact code, but it's equivalent.)

apps.register_model and apps.get_registered_model are essentially a setter and
a getter for apps.all_models, and apps.register_model is the only setter. As a
consequence, new_class._meta.apps.all_models cannot change in-between.

Considering that name == new_class.__name__, we can conclude that
register_model(app_label, model) is always called with such arguments that
get_registered_model(app_label, model.__name__) returns None.

Considering that model._meta.model_name == model.__name__.lower(), and looking
at the implementation of register_model and get_registered_model, this proves
that self.all_models[app_label] doesn't contain model._meta.model_name in
register_model, allowing us to simplify the implementation.
2013-12-28 09:34:46 +01:00
Ramiro Morales 61cfcec5b7 Merge pull request #2120 from ramiro/schema-creation-quoting
Fixed #21692 -- Quote table name when creating it.
2013-12-27 15:40:52 -08:00
Aymeric Augustin 14bcbd9937 Avoided %r formatting on possibly unicode strings.
The u prefix looks bad on Python 2.
2013-12-27 23:19:23 +01:00
Ramiro Morales 3efd1b8b93 Fixed #21692 -- Quote table name when creating it. 2013-12-27 18:43:52 -03:00
Aymeric Augustin efddae252c Refactored dumpdata with app configs instead of models modules. 2013-12-27 21:25:35 +01:00
Aymeric Augustin 2504a50cc2 Created a constant for the migrations module name.
Mostly for consistency with MODELS_MODULE_NAME; it's unlikely to change.
2013-12-27 15:36:19 +01:00
Florian Apolloner f00243f36d Don't try to load app directory templates from apps with a path (eg eggs) 2013-12-27 11:42:24 +01:00
Florian Apolloner 6aa1a31660 Properly app_template_dirs when INSTALLED_APPS change. 2013-12-27 11:17:25 +01:00
Aymeric Augustin 6e3ca6507c Used app_config.verbose_name instead of app_label|capfirst.
An admin view performed the capitalization in the template, unlike all others.

Refs #10436.
2013-12-26 22:58:37 +01:00
Aymeric Augustin b355e98a50 Normalized exceptions raised by AppConfig.create.
It raises ImportError whenever an entry in INSTALLED_APPS points
(directly or indirectly via AppConfig.name) to a non-existing module
and ImproperlyConfigured in all other cases.

Catching ImportError and re-raising ImproperlyConfigured tends to make
circular imports more difficult to diagnose.
2013-12-26 19:25:09 +01:00
Aymeric Augustin ce1bc2c94b Made the AppConfig API marginally more consistent.
Eliminated the app_ prefix that was more confusing than useful.
2013-12-26 19:25:09 +01:00
Aymeric Augustin fec5330c79 Made unset_installed_apps reset the app registry state.
Previously the _apps/models_loaded flags could remain set to False if
set_installed_apps exited with an exception, which is going to happen as
soon as we add tests for invalid values of INSTALLED_APPS.
2013-12-26 19:21:02 +01:00
Preston Timmons aef019de61 Fixed #21206 -- No longer run discovery if the test label doesn't point to a package or directory.
Thanks thepapermen for the report and Carl Meyer for the review.
2013-12-26 11:26:24 -05:00
Aymeric Augustin 52325b0a04 Turned apps.ready into a property. Added tests. 2013-12-26 15:04:58 +01:00
Aymeric Augustin 922430177c Beefed up the comments for AppConfig.all_models. 2013-12-26 14:12:30 +01:00
Aymeric Augustin 8f04f53dd8 Removed a few gratuitous lambdas. 2013-12-26 14:03:50 +01:00
Tim Graham 4e7aa573ec Added missing newline in previous commit. 2013-12-26 07:52:31 -05:00
Jon Lønne 398642fd9b Fixed #21627 -- Added unicode_literals to changepassword command.
Fixed a crash when executing changepassword command when the user object
representation contained non-ASCII characters.
2013-12-26 07:35:50 -05:00
Alex Gaynor 029acbe544 Merge pull request #2114 from levigross/master
Removed redundant line
2013-12-25 14:40:30 -08:00
Levi Gross cb488c5c35
Removed redundant line 2013-12-25 17:22:13 -05:00
Aymeric Augustin 08bb238eae Merge pull request #2105 from funkybob/cleanup_get_post
Used @cached_property for request.GET and COOKIES
2013-12-25 12:34:06 -08:00
Alex Gaynor dbe2fb632d Added a missing import and removed an unneeded import 2013-12-24 08:35:13 -08:00
Jonas Gastal 96967f642f Typo fix for exception message. 2013-12-24 14:26:50 -02:00
Aymeric Augustin f326720a73 Documented the Apps and AppConfig APIs. 2013-12-24 17:20:11 +01:00
Claude Paroz 9267fb88ef Added more spatial predicates for prepared geometries
GEOS 3.3 added crosses, disjoint, overlaps, touches and within
predicates on prepared geometries.
2013-12-24 16:53:09 +01:00
Claude Paroz d17404aa90 Dropped support for GEOS < 3.1 2013-12-24 15:57:13 +01:00
Claude Paroz 542198c1d0 Fixed #21662 -- Kept parent reference in prepared geometry
Thanks Robert Scott for the report.
2013-12-24 15:25:48 +01:00
Aymeric Augustin 1716b7ce5a Renamed AppCache to Apps.
Also renamed app_cache to apps and "app cache" to "app registry".

Deprecated AppCache.app_cache_ready() in favor of Apps.ready().
2013-12-24 12:25:17 +01:00
Curtis d7a4b156d9 Use cached_property for request.GET and request.COOKIES 2013-12-24 21:57:57 +11:00
Aymeric Augustin e9e522a8e7 Invalidated get_models cache in a few more places. 2013-12-24 11:09:24 +01:00
Aymeric Augustin 82a35e24d4 Replaced ad-hoc caching of get_models with lru_cache.
Invalidate properly the cache whenever all_models or app_configs change.
This fixes some isolation issues in the test suite.
2013-12-24 10:56:50 +01:00
Aymeric Augustin 2ec8e3443b Fixed override_settings when set_available_apps raises an exception.
Previously, this would corrupt the settings, because __exit__ isn't
called when __enter__raises an exception.
2013-12-24 00:12:09 +01:00
Aymeric Augustin 137a3d7c77 Avoided loading repeatedly the same models module. 2013-12-23 22:21:23 +01:00
Aymeric Augustin e32095616c Imported override_settings from its new location. 2013-12-23 21:37:56 +01:00
Aymeric Augustin da16bb30ff Dropped AppCache._empty, _with_app and _without_app.
It's now easier to achieve the same effect with modify_settings or
override_settings.
2013-12-23 21:37:56 +01:00
Aymeric Augustin 5241763c81 Added modify_settings to alter settings containing lists of values. 2013-12-23 21:37:43 +01:00