Commit Graph

10323 Commits

Author SHA1 Message Date
Aymeric Augustin f630373b92 Fixed #21711 -- Enforced unicity of model names. 2014-01-05 20:52:53 +01:00
Florian Apolloner 3bc6b18cb9 Fixed selenium failure.
This fixes (at least according to tests on the ci itself)
admin_widgets.tests.RelatedFieldWidgetSeleniumFirefoxTests.test_foreign_key_using_to_field

(http://ci.djangoproject.com/job/Django/database=mysql_gis,python=python2.7/3792/testReport/junit/admin_widgets.tests/RelatedFieldWidgetSeleniumFirefoxTests/test_foreign_key_using_to_field/)

The cause for this issue seems to be that wait_page_loaded was executed before click fired
and as such no profile got saved (again just an educated guess, but with this fix I can no
longer reproduce it -- fingers crossed).
2014-01-03 11:29:37 +01:00
Florian Apolloner 7d0a519032 Revert "Fixed #21227 -- Added workaround for selenium test failures"
This reverts commit 08c9ab5a0f.
2014-01-03 00:44:49 +01:00
Florian Apolloner b1a399b864 Removed unneeded import. 2014-01-03 00:42:03 +01:00
Florian Apolloner ed2828f0a0 Fixed a few flaky selenium tests.
Many thanks go to David Burns (@AutomatedTester) for helping me understand
css selectors and pointing me towards the correct selenium methods.
2014-01-03 00:36:50 +01:00
Claude Paroz aaf5b3e7aa Moved django.setup() to ManagementUtility
In get_commands, setup() might already have been called, for example
when the management command is called through call_command. Moving
setup() to ManagementUtility so as it is only called when the command
is run from command line.
2014-01-02 20:47:40 +01:00
Aymeric Augustin 30a42a4fc3 Adjusted previous commit for Python 3. 2014-01-01 19:12:46 +01:00
Alex Gaynor 791142e8b3 Several small whitespace fixes for styleguide/flake8 violations 2014-01-01 09:37:52 -08:00
Aymeric Augustin 0ce945a671 Fixed #21018 -- Reversed precedence order for management commands. 2014-01-01 18:11:15 +01:00
Aymeric Augustin f17d00278e Wiped get_commands() cache when INSTALLED_APPS changes.
Refs #21018, #21688.
2014-01-01 18:11:09 +01:00
Preston Timmons 18d962f2e6 Fixed #21206 -- Fixed test discovery without labels
Added test to verify an empty label performs discovery on the current
working directory.
2014-01-01 12:40:16 +01:00
Claude Paroz fbbe7ca30c Readded field unadvertantly removed in fedfd5030 2014-01-01 12:07:43 +01:00
Aymeric Augustin 6edd5b0793 Fixed a few issues in previous commit. 2014-01-01 11:52:56 +01:00
Aymeric Augustin fecfd50300 Properly assigned app_label to GIS test models.
Used abstract inheritance to cut down on code repetition.
2014-01-01 11:01:46 +01:00
Loic Bistuer 4befb3015c Fixed #21581 -- Fixed a number of issues with collectstatic.
When STATIC_ROOT wasn't set, collectstatic --clear would delete
every files within the current directory and its descendants.

This patch makes the following changes:

Prevent collectstatic from running if STATIC_ROOT isn't set.

Fixed an issue that prevented collectstatic from displaying the
destination directory.

Changed the warning header to notify when the command is run
in dry-run mode.
2013-12-31 14:58:49 -05:00
Claude Paroz b8e3373f45 Fixed #21714 -- Moved logging configuration to global setup()
Thanks Aymeric Augustin for the report and the review.
2013-12-31 18:35:00 +01:00
Aymeric Augustin 1d23d766ab Renamed AppConfig.setup to ready.
Thanks Jannis and Marc for the feedback.

Fixed #21717.
2013-12-31 18:04:54 +01:00
Aymeric Augustin 63137a8304 Enforced unicity of app labels.
Fixed #21679.
2013-12-31 18:04:54 +01:00
Aymeric Augustin c40209dcc0 Made it possible to change an application's label in its configuration.
Fixed #21683.
2013-12-31 17:30:58 +01:00
Aymeric Augustin 5dfec4e23b Checked unicity of app config names when populating the app registry.
This check will miss duplicates until the check for duplicate labels is
added.

Refs #21679.
2013-12-31 17:29:04 +01:00
Aymeric Augustin 553500133c Removed an obsolete unicity check.
It doesn't account for app configs.

Refs #21679.
2013-12-31 17:29:04 +01:00
Claude Paroz d0eeddd6fc Fixed #21716 -- Only passed arguments supported by ogrinspect
Thanks Marco Badan for the report.
2013-12-31 16:26:44 +01:00
Aymeric Augustin 75220d3b5d Small style cleanup. 2013-12-31 16:24:40 +01:00
Aymeric Augustin f46603f830 Fleshed out release notes for app loading.
Fixed #21715.
2013-12-31 15:27:25 +01:00
Aymeric Augustin 80004c7cc0 Turned django.db.models.app_cache_ready back into a method.
Thanks Anssi for noticing this mistake in a refactoring.
2013-12-31 15:27:25 +01:00
Aymeric Augustin a95f74e707 Oops. 2013-12-31 13:16:51 +01:00
Aymeric Augustin 6b172a6d6d Called django.setup() explicitly in management commands.
This avoids duplicating code.
2013-12-31 13:11:05 +01:00
Thomas Schreiber 7b119c1c77 only attempt to create the postgis extension when it does not already exist 2013-12-31 11:34:03 +01:00
Aymeric Augustin bfcc686d22 Removed the only_with_models_module argument of get_model[s].
Now that the refactorings are complete, it isn't particularly useful any
more, nor very well named. Let's keep the API as simple as possible.

Fixed #21689.
2013-12-30 23:59:34 +01:00
Florian Apolloner df075c7489 Merge pull request #2126 from apollo13/email_bytes
Many thanks to @bitdancer and @aaugustin for answering my stupid questions about (mail)encodings and pointing me in the right direction.
2013-12-30 14:58:49 -08:00
Florian Apolloner bfe9052831 Decode mails using the message encoding. 2013-12-30 23:54:12 +01:00
Florian Apolloner c988745cca Changed console and filebackend to use msg.as_bytes to output the data as it would get send via smtp. 2013-12-30 23:46:05 +01:00
Aymeric Augustin 1c242a297b Merged Apps.populate_apps() and populate_models().
After the recent series of refactorings, there's no reason to keep
two distinct methods.

Refs #21681.
2013-12-30 23:18:22 +01:00
Aymeric Augustin 966de84973 Removed postponing in Apps.populate_models.
To the best of my understanding, since populate_models() is now called
as soon as Django starts, it cannot be called while a models module is
being imported, and that removes the need for postponing.

(If hell breaks loose we'll revert this commit.)

Refs #21681.
2013-12-30 23:01:00 +01:00
Aymeric Augustin 80d74097b4 Stopped populating the app registry as a side effect.
Since it triggers imports, it shouldn't be done lightly.

This commit adds a public API for doing it explicitly, django.setup(),
and does it automatically when using manage.py and wsgi.py.
2013-12-30 22:11:17 +01:00
Aymeric Augustin 7ed20e0153 Populated Apps instances immediately by default. 2013-12-30 22:11:17 +01:00
Aymeric Augustin e187caa3af Added AppConfig.setup() to run setup code. 2013-12-30 22:11:16 +01:00
Aymeric Augustin 0d2c8ff2be Populated the app registry earlier at startup.
Refs #1796, #21676.
2013-12-30 22:11:16 +01:00
Aymeric Augustin d6dc88cbc1 Avoided leaking state on exceptions in populate_models(). 2013-12-30 22:10:04 +01:00
Aymeric Augustin 5892a83b18 Stopped calling get_models() for a side effect. 2013-12-29 21:48:58 +01:00
Aymeric Augustin 34a215d506 Deprecated the app argument of apps.get_models.
Use app_config.get_models() instead.
2013-12-29 21:48:58 +01:00
Aymeric Augustin e5bcd1d455 Changed get_validation_errors to use an app config. 2013-12-29 21:48:58 +01:00
Aymeric Augustin 856aaaf2b1 Changed get_migratable_models to use an app config. 2013-12-29 21:25:28 +01:00
Aymeric Augustin 1d4bcb86ea Changed sql_* to use an app config instead of a models module. 2013-12-29 21:25:28 +01:00
Aymeric Augustin 8cfcd801c4 Fixed stupid error in 21f22f95. 2013-12-29 20:57:03 +01:00
Aymeric Augustin 368d90e261 Removed unused import. 2013-12-29 20:45:34 +01:00
Aymeric Augustin d1eb362afb Removed obsolete docstring. 2013-12-29 20:45:25 +01:00
Aymeric Augustin 21f22f9544 Added Apps.clear_cache().
This avoid leaking implementation details to tests that swap models.
2013-12-29 20:43:10 +01:00
Aymeric Augustin 82aadbb5d5 Fixed a typo.
Thanks Simon.
2013-12-29 20:35:58 +01:00
Aymeric Augustin 7b88a96553 Added AppConfig.get_models(). 2013-12-29 20:31:59 +01:00
Florian Apolloner 98b52ae201 Cleared global templatetags module cache.
TOOOOO MUCH GLOBAL STATE (you didn't see that).
2013-12-29 19:17:25 +01:00
Aymeric Augustin 20d487c27b Replaced Options.object_name.lower() by Options.model_name.
Thanks Simon for the suggestion.

Also removed inappropriate lowercasing of app labels in migrations.
Unlike model names, they are case sensitive.
2013-12-29 18:48:37 +01:00
Aymeric Augustin 308960b92a Cleared get_models cache when swapping User model.
Thanks Florian for isolating the shortest way to reproduce this issue:

./runtests.py \
    django.contrib.auth.tests.test_context_processors.AuthContextProcessorTests.test_perms_attrs \
    django.contrib.auth.tests.test_auth_backends.ChangedBackendSettingsTest.test_changed_backend_settings \
    django.contrib.auth.tests.test_auth_backends.CustomUserModelBackendAuthenticateTest.test_authenticate \
    django.contrib.auth.tests.test_basic.BasicTestCase.test_createsuperuser_management_command
2013-12-29 18:25:22 +01:00
Aymeric Augustin 00110904ac Refactored the migration signals to use app configs.
De-aliased pre/post_syncdb to pre/post_migrate to increase
backwards-compatibility.
2013-12-29 17:53:42 +01:00
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
Florian Apolloner 5dfd824d38 Introduced as_bytes for SafeMIMEText (and other SafeMIME-classes).
This is to provide a consistent interface (namely bytes) for the smtp
backend which after all sends bytes over the wire; encoding with as_string
yields different results since mails as unicode are not really specified.

as_string stays for backwardscompatibilty mostly and some debug outputs.
But keep in mind that the output doesn't match as_bytes!
2013-12-28 18:35:17 +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