[Python-modules-commits] [python-django-extensions] 01/18: Import python-django-extensions_1.6.7.orig.tar.gz
Michael Fladischer
fladi at moszumanska.debian.org
Wed May 18 13:34:09 UTC 2016
This is an automated email from the git hooks/post-receive script.
fladi pushed a commit to branch master
in repository python-django-extensions.
commit cd6e080fa705fcd290cf62d0ea7a9c2823a4544d
Author: Michael Fladischer <fladi at debian.org>
Date: Mon May 16 17:18:15 2016 +0200
Import python-django-extensions_1.6.7.orig.tar.gz
---
.gitignore | 2 +
CHANGELOG.md | 44 +++++++++++++++++
django_extensions/__init__.py | 2 +-
django_extensions/compat.py | 57 +++++++++-------------
django_extensions/db/fields/__init__.py | 17 ++++++-
django_extensions/jobs/daily/cache_cleanup.py | 4 +-
.../management/commands/admin_generator.py | 4 +-
.../management/commands/describe_form.py | 2 +-
.../management/commands/dumpscript.py | 10 ++--
.../management/commands/pipchecker.py | 6 ++-
.../management/commands/runprofileserver.py | 21 +++-----
django_extensions/management/modelviz.py | 13 +++--
django_extensions/management/shells.py | 10 +++-
docs/command_extensions.rst | 3 ++
docs/conf.py | 2 +-
docs/runserver_plus.rst | 27 +++++++++-
docs/shell_plus.rst | 6 +++
17 files changed, 161 insertions(+), 69 deletions(-)
diff --git a/.gitignore b/.gitignore
index 12dd2a5..b53881f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,3 +13,5 @@ venv*
.idea/
.coverage
.cache/
+django-sample-app*/
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a50eae..aa2158b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,50 @@
Changelog
=========
+1.6.7
+-----
+
+Changes:
+ - Fix: describe_form, fix No module named 'django.db.models.loading' error
+ - Improvement: shell_plus, Add a setting to prefix all models in an application #887
+ - Improvement: pipchecker, check for requirements-{dev,prod}.txt as well
+ - Docs: pipchecker, update documentation
+
+1.6.6
+-----
+
+Changes:
+ - Fix: admin_generator, fix for using all apps in Django <1.7
+ - Fix: dump_script, fix for using all apps in Django <1.7
+ - Fix: UniqueFieldMixin, resolve get_fields_with_model deprecation Django 1.10
+ - Fix: runprofileserver, Fix call grind format to enable source code navigation in qcachegrind.
+ - Docs: runserver_plus, add a little note about the debugger PIN.
+
+
+1.6.5
+-----
+
+Bumped version number since PyPi returns 500 errors while uploading packages :(
+
+
+1.6.4
+-----
+
+Changes:
+ - Fix: jobs cache_cleanup, use `caches` instead of deprecated `get_cache`
+ - Fix: ModificationDateTimeField, missing default value for `update_modified`
+ - Fix: modelviz, use get_model_compat and look up missing app_label
+ - Fix: modelviz, use get_models_for_app instead of get_models_compat
+ - Fix: dumpscript, use `list_app_labels` instead of `get_apps` when no app_labels are given
+ - Improvement: compat.py, move code from try to else block for Django 1.7+
+ - Docstring: get_models_for_app, clearify argument
+
+
+1.6.3
+-----
+
+Bumped version number for incomplete PyPi uplaod
+
1.6.2
-----
diff --git a/django_extensions/__init__.py b/django_extensions/__init__.py
index 85e2f28..2500de0 100644
--- a/django_extensions/__init__.py
+++ b/django_extensions/__init__.py
@@ -1,5 +1,5 @@
# coding=utf-8
-VERSION = (1, 6, 3)
+VERSION = (1, 6, 7)
# Dynamically calculate the version based on VERSION tuple
if len(VERSION) > 2 and VERSION[2] is not None:
diff --git a/django_extensions/compat.py b/django_extensions/compat.py
index 62e2259..aef2cac 100644
--- a/django_extensions/compat.py
+++ b/django_extensions/compat.py
@@ -45,58 +45,64 @@ def list_apps():
try:
# django >= 1.7, to support AppConfig
from django.apps import apps
- return [app.name for app in apps.get_app_configs()]
except ImportError:
# old way
return list(settings.INSTALLED_APPS)
+ else:
+ return [app.name for app in apps.get_app_configs()]
def list_app_labels():
try:
# django >= 1.7, to support AppConfig
from django.apps import apps
- return [app.label for app in apps.get_app_configs()]
except ImportError:
# old way
return [app.rsplit(".")[-1] for app in settings.INSTALLED_APPS]
+ else:
+ return [app.label for app in apps.get_app_configs()]
def get_app(app_label):
try:
# django >= 1.7
from django.apps import apps
- return apps.get_app_config(app_label).models_module
except ImportError:
from django.db import models
return models.get_app(app_label)
+ else:
+ return apps.get_app_config(app_label).models_module
def get_apps():
try:
# django >= 1.7, to support AppConfig
from django.apps import apps
- return [app.models_module for app in apps.get_app_configs() if app.models_module]
except ImportError:
from django.db import models
return models.get_apps()
+ else:
+ return [app.models_module for app in apps.get_app_configs() if app.models_module]
def get_apps_from_cache():
try:
from django.apps import apps
- return [app.models_module for app in apps.get_app_configs() if app.models_module]
except ImportError:
from django.db.models.loading import cache
return cache.get_apps()
+ else:
+ return [app.models_module for app in apps.get_app_configs() if app.models_module]
def get_models_from_cache(app):
try:
from django.apps import apps
- return apps.get_models(app)
except ImportError:
from django.db.models.loading import cache
return cache.get_models(app)
+ else:
+ return apps.get_models(app)
def get_app_models(app_labels=None):
@@ -104,10 +110,11 @@ def get_app_models(app_labels=None):
try:
# django >= 1.7, to support AppConfig
from django.apps import apps
- return apps.get_models(include_auto_created=True)
except ImportError:
from django.db import models
return models.get_models(include_auto_created=True)
+ else:
+ return apps.get_models(include_auto_created=True)
if not isinstance(app_labels, (list, tuple, set)):
app_labels = [app_labels]
@@ -116,10 +123,6 @@ def get_app_models(app_labels=None):
try:
# django >= 1.7, to support AppConfig
from django.apps import apps
-
- for app_label in app_labels:
- app_config = apps.get_app_config(app_label)
- app_models.extend(app_config.get_models(include_auto_created=True))
except ImportError:
from django.db import models
@@ -130,6 +133,10 @@ def get_app_models(app_labels=None):
for app in app_list:
app_models.extend(models.get_models(app, include_auto_created=True))
+ else:
+ for app_label in app_labels:
+ app_config = apps.get_app_config(app_label)
+ app_models.extend(app_config.get_models(include_auto_created=True))
return app_models
@@ -139,32 +146,23 @@ def get_model_compat(app_label, model_name):
try:
# django >= 1.7
from django.apps import apps
- return apps.get_model(app_label, model_name)
except ImportError:
from django.db.models import get_model
return get_model(app_label, model_name)
-
-
-def get_models_compat(app_label):
- """Get models on multiple Django versions."""
- try:
- # django >= 1.7
- from django.apps import apps
- return apps.get_app_config(app_label).get_models()
- except ImportError:
- from django.db.models import get_models
- return get_models(app_label)
+ else:
+ return apps.get_model(app_label, model_name)
def get_models_for_app(app_label):
- """Returns the models in the given app."""
+ """Returns the models in the given app for an app label."""
try:
# django >= 1.7
from django.apps import apps
- return apps.get_app_config(app_label).get_models()
except ImportError:
from django.db.models import get_app, get_models
return get_models(get_app(app_label))
+ else:
+ return apps.get_app_config(app_label).get_models()
def load_tag_library(libname):
@@ -199,15 +197,6 @@ def add_to_builtins_compat(name):
engines['django'].engine.builtins.append(name)
-def get_model(path):
- if django.VERSION < (1, 7):
- from django.db.models.loading import get_model
- return get_model(*path.split('.', 1))
- else:
- from django.apps import apps
- return apps.get_model(*path.split('.', 1))
-
-
class ProxyParser(object):
"""Faux parser object that will ferry our arguments into options."""
diff --git a/django_extensions/db/fields/__init__.py b/django_extensions/db/fields/__init__.py
index a84ee36..438f78c 100644
--- a/django_extensions/db/fields/__init__.py
+++ b/django_extensions/db/fields/__init__.py
@@ -46,8 +46,21 @@ class UniqueFieldMixin(object):
if not isinstance(getattr(self, attrname), bool):
raise ValueError("'{}' argument must be True or False".format(attrname))
+ @staticmethod
+ def _get_fields(model_cls):
+ if hasattr(model_cls._meta, 'get_fields'):
+ # verbosity due to replacement of deprecated model_cls._meta.get_fields_with_model(),
+ # as explained here: https://docs.djangoproject.com/en/1.9/ref/models/meta/#migrating-from-the-old-api
+ return [
+ (f, f.model if f.model != model_cls else None) for f in model_cls._meta.get_fields()
+ if not f.is_relation or f.one_to_one or (f.many_to_one and f.related_model)
+ ]
+ else:
+ # prior to 1.9
+ return model_cls._meta.get_fields_with_model()
+
def get_queryset(self, model_cls, slug_field):
- for field, model in model_cls._meta.get_fields_with_model():
+ for field, model in self._get_fields(model_cls):
if model and field == slug_field:
return model._default_manager.all()
return model_cls._default_manager.all()
@@ -410,7 +423,7 @@ class ModificationDateTimeField(CreationDateTimeField):
return name, path, args, kwargs
def pre_save(self, model_instance, add):
- if not model_instance.update_modified:
+ if not getattr(model_instance, 'update_modified', True):
return model_instance.modified
return super(ModificationDateTimeField, self).pre_save(model_instance, add)
diff --git a/django_extensions/jobs/daily/cache_cleanup.py b/django_extensions/jobs/daily/cache_cleanup.py
index ddb9d8d..9880ca1 100644
--- a/django_extensions/jobs/daily/cache_cleanup.py
+++ b/django_extensions/jobs/daily/cache_cleanup.py
@@ -35,12 +35,12 @@ class Job(DailyJob):
transaction.commit_unless_managed(using=using)
if hasattr(settings, 'CACHES') and timezone:
- from django.core.cache import get_cache
+ from django.core.cache import caches
from django.db import router, connections
for cache_name, cache_options in six.iteritems(settings.CACHES):
if cache_options['BACKEND'].endswith("DatabaseCache"):
- cache = get_cache(cache_name)
+ cache = caches[cache_name]
db = router.db_for_write(cache.cache_model_class)
with atomic(using=db):
cursor = connections[db].cursor()
diff --git a/django_extensions/management/commands/admin_generator.py b/django_extensions/management/commands/admin_generator.py
index c566f2a..5786fbe 100644
--- a/django_extensions/management/commands/admin_generator.py
+++ b/django_extensions/management/commands/admin_generator.py
@@ -21,7 +21,7 @@ import sys
from django.conf import settings
from django.db import models
-from django_extensions.compat import get_apps, get_models_compat
+from django_extensions.compat import get_apps, get_models_for_app
from django_extensions.management.color import color_style
from django_extensions.management.utils import signalcommand
from django_extensions.compat import CompatibilityLabelCommand as LabelCommand
@@ -89,7 +89,7 @@ class AdminApp(UnicodeMixin):
self.options = options
def __iter__(self):
- for model in get_models_compat(self.app):
+ for model in get_models_for_app(self.app):
admin_model = AdminModel(model, **self.options)
for model_re in self.model_res:
diff --git a/django_extensions/management/commands/describe_form.py b/django_extensions/management/commands/describe_form.py
index 6d1ae12..9b29eac 100644
--- a/django_extensions/management/commands/describe_form.py
+++ b/django_extensions/management/commands/describe_form.py
@@ -3,6 +3,7 @@ from django.core.management.base import CommandError
from django_extensions.management.utils import signalcommand
from django_extensions.compat import CompatibilityLabelCommand as LabelCommand
+from django_extensions.compat import get_model_compat as get_model
try:
from django.utils.encoding import force_text
@@ -26,7 +27,6 @@ def describe_form(label, fields=None):
"""
Returns a string describing a form based on the model
"""
- from django.db.models.loading import get_model
try:
app_name, model_name = label.split('.')[-2:]
except (IndexError, ValueError):
diff --git a/django_extensions/management/commands/dumpscript.py b/django_extensions/management/commands/dumpscript.py
index 848d1e0..b0124ad 100644
--- a/django_extensions/management/commands/dumpscript.py
+++ b/django_extensions/management/commands/dumpscript.py
@@ -43,7 +43,7 @@ from django.db.models import (
from django_extensions.management.utils import signalcommand
from django_extensions.compat import (
- get_apps, get_model_compat, get_models_compat, get_models_for_app
+ list_app_labels, get_model_compat, get_models_for_app
)
from django_extensions.compat import CompatibilityBaseCommand as BaseCommand
@@ -132,8 +132,8 @@ def get_models(app_labels):
# If no app labels are given, return all
if not app_labels:
- for app in get_apps():
- models += [m for m in get_models_compat(app)
+ for app_label in list_app_labels():
+ models += [m for m in get_models_for_app(app_label)
if m not in EXCLUDED_MODELS]
return models
@@ -506,7 +506,7 @@ class Script(Code):
# Queue and process the required models
for model_class in self._queue_models(self.models, context=self.context):
- msg = 'Processing model: %s\n' % model_class.model.__name__
+ msg = 'Processing model: %s.%s\n' % (model_class.model.__module__, model_class.model.__name__)
self.stderr.write(msg)
code.append(" # " + msg)
code.append(model_class.import_lines)
@@ -515,7 +515,7 @@ class Script(Code):
# Process left over foreign keys from cyclic models
for model in self.models:
- msg = 'Re-processing model: %s\n' % model.model.__name__
+ msg = 'Re-processing model: %s.%s\n' % (model.model.__module__, model.model.__name__)
self.stderr.write(msg)
code.append(" # " + msg)
for instance in model.instances:
diff --git a/django_extensions/management/commands/pipchecker.py b/django_extensions/management/commands/pipchecker.py
index dc7881c..7d3f7b3 100644
--- a/django_extensions/management/commands/pipchecker.py
+++ b/django_extensions/management/commands/pipchecker.py
@@ -61,8 +61,12 @@ class Command(BaseCommand):
req_files = ["requirements/{0}".format(f) for f in os.listdir("requirements")
if os.path.isfile(os.path.join("requirements", f)) and
f.lower().endswith(".txt")]
+ elif os.path.exists("requirements-dev.txt"):
+ req_files = ["requirements-dev.txt"]
+ elif os.path.exists("requirements-prod.txt"):
+ req_files = ["requirements-prod.txt"]
else:
- raise CommandError("Requirements not found")
+ raise CommandError("Requirements file(s) not found")
try:
from pip.download import PipSession
diff --git a/django_extensions/management/commands/runprofileserver.py b/django_extensions/management/commands/runprofileserver.py
index 488717f..f08b81e 100644
--- a/django_extensions/management/commands/runprofileserver.py
+++ b/django_extensions/management/commands/runprofileserver.py
@@ -26,15 +26,6 @@ except ImportError as e:
USE_STATICFILES = False
-def label(code):
- if isinstance(code, str):
- return '~', 0, code # built-in functions ('~' sorts at the end)
- else:
- return '%s %s:%d' % (code.co_name,
- code.co_filename,
- code.co_firstlineno)
-
-
class KCacheGrind(object):
def __init__(self, profiler):
self.data = profiler.getstats()
@@ -59,10 +50,10 @@ class KCacheGrind(object):
code = entry.code
if isinstance(code, str):
- out_file.write('fi=~\n')
+ out_file.write('fn=%s\n' % code)
else:
- out_file.write('fi=%s\n' % (code.co_filename,))
- out_file.write('fn=%s\n' % (label(code),))
+ out_file.write('fl=%s\n' % code.co_filename)
+ out_file.write('fn=%s\n' % code.co_name)
inlinetime = int(entry.inlinetime * 1000)
if isinstance(code, str):
@@ -88,12 +79,12 @@ class KCacheGrind(object):
def _subentry(self, lineno, subentry):
out_file = self.out_file
code = subentry.code
- out_file.write('cfn=%s\n' % (label(code),))
if isinstance(code, str):
- out_file.write('cfi=~\n')
+ out_file.write('cfn=%s\n' % code)
out_file.write('calls=%d 0\n' % (subentry.callcount,))
else:
- out_file.write('cfi=%s\n' % (code.co_filename,))
+ out_file.write('cfl=%s\n' % code.co_filename)
+ out_file.write('cfn=%s\n' % code.co_name)
out_file.write('calls=%d %d\n' % (subentry.callcount, code.co_firstlineno))
totaltime = int(subentry.totaltime * 1000)
diff --git a/django_extensions/management/modelviz.py b/django_extensions/management/modelviz.py
index e80ad93..8bc96ae 100644
--- a/django_extensions/management/modelviz.py
+++ b/django_extensions/management/modelviz.py
@@ -31,7 +31,9 @@ try:
except ImportError:
from django.contrib.contenttypes.generic import GenericRelation
-from django_extensions.compat import get_app, get_models_compat, list_app_labels, get_model
+from django_extensions.compat import (
+ get_app, get_model_compat, get_models_for_app, list_app_labels
+)
__version__ = "1.0"
@@ -126,7 +128,7 @@ def generate_graph_data(app_labels, **kwargs):
'models': []
})
- appmodels = list(get_models_compat(app_label))
+ appmodels = list(get_models_for_app(app_label))
abstract_models = []
for appmodel in appmodels:
abstract_models = abstract_models + [abstract_model for abstract_model in appmodel.__bases__ if hasattr(abstract_model, '_meta') and abstract_model._meta.abstract]
@@ -238,7 +240,12 @@ def generate_graph_data(app_labels, **kwargs):
if field.rel.to == 'self':
target_model = field.model
else:
- target_model = get_model(field.rel.to)
+ if '.' in field.rel.to:
+ app_label, model_name = field.rel.to.split('.', 1)
+ else:
+ app_label = field.model._meta.app_label
+ model_name = field.rel.to
+ target_model = get_model_compat(app_label, model_name)
else:
target_model = field.rel.to
diff --git a/django_extensions/management/shells.py b/django_extensions/management/shells.py
index 8bdeaf6..f191c8d 100644
--- a/django_extensions/management/shells.py
+++ b/django_extensions/management/shells.py
@@ -123,6 +123,7 @@ def import_objects(options, style):
quiet_load = options.get('quiet_load')
model_aliases = getattr(settings, 'SHELL_PLUS_MODEL_ALIASES', {})
+ app_prefixes = getattr(settings, 'SHELL_PLUS_APP_PREFIXES', {})
# Perform pre-imports before any other imports
SHELL_PLUS_PRE_IMPORTS = getattr(settings, 'SHELL_PLUS_PRE_IMPORTS', {})
@@ -173,6 +174,7 @@ def import_objects(options, style):
# Some weird model naming scheme like in Sentry.
app_name = app_mod
app_aliases = model_aliases.get(app_name, {})
+ prefix = app_prefixes.get(app_name)
model_labels = []
for model_name in sorted(models):
@@ -182,7 +184,13 @@ def import_objects(options, style):
if "%s.%s" % (app_name, model_name) in dont_load:
continue
- alias = app_aliases.get(model_name, model_name)
+ alias = app_aliases.get(model_name)
+
+ if not alias and prefix:
+ alias = "%s_%s" % (prefix, model_name)
+ else:
+ alias = model_name
+
imported_objects[alias] = imported_object
if model_name == alias:
model_labels.append(model_name)
diff --git a/docs/command_extensions.rst b/docs/command_extensions.rst
index ba6e1ad..aaf375e 100644
--- a/docs/command_extensions.rst
+++ b/docs/command_extensions.rst
@@ -53,6 +53,9 @@ Current Command Extensions
* *passwd* - Makes it easy to reset a user's password.
+* *pipchecker* - Scan pip requirement file(s)s for out-of-date packages. Similar to
+ ``pip list -o`` which used installed packages (in virtualenv) instead of requirements file(s).
+
* `print_settings`_ - Similar to ``diffsettings`` but shows *selected*
active Django settings or *all* if no args passed.
diff --git a/docs/conf.py b/docs/conf.py
index d4607ec..c25a196 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -47,7 +47,7 @@ copyright = u'Copyright (C) 2008-2015 Michael Trier, Bas van Oostveen and contri
# The short X.Y version.
version = '1.6'
# The full version, including alpha/beta/rc tags.
-release = '1.6.3'
+release = '1.6.7'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
diff --git a/docs/runserver_plus.rst b/docs/runserver_plus.rst
index 3114cbe..98b1f47 100644
--- a/docs/runserver_plus.rst
+++ b/docs/runserver_plus.rst
@@ -199,7 +199,32 @@ This can be set two ways, in the django settings file:
or as a commad line argument:
$ python manage.py runserver_plus --reloader-interval 5
-
+
+
+Debugger PIN
+------------
+
+.. epigraph::
+ The following text about the debugger PIN is taken verbatim from the Werkzeug documentation.
+
+ -- http://werkzeug.pocoo.org/docs/0.11/debug/#debugger-pin
+
+Starting with Werkzeug 0.11 the debugger is additionally protected by a PIN. This is a security helper to
+make it less likely for the debugger to be exploited in production as it has happened to people to keep the
+debugger active. The PIN based authentication is enabled by default.
+
+When the debugger comes up, on first usage it will prompt for a PIN that is printed to the command line.
+The PIN is generated in a stable way that is specific to the project. In some situations it might be not possible
+to generate a stable PIN between restarts in which case an explicit PIN can be provided through the environment
+variable WERKZEUG_DEBUG_PIN. This can be set to a number and will become the PIN. This variable can also be set
+to the value off to disable the PIN check entirely.
+
+If the PIN is entered too many times incorrectly the server needs to be restarted.
+
+This feature is not supposed to entirely secure the debugger. It’s intended to make it harder for an attacker to
+exploit the debugger. Never enable the debugger in production.
+
+
.. _gh625: https://github.com/django-extensions/django-extensions/issues/625
.. _Werkzeug: http://werkzeug.pocoo.org/
.. _Watchdog: https://pypi.python.org/pypi/watchdog
diff --git a/docs/shell_plus.rst b/docs/shell_plus.rst
index b8b4e14..c64ed03 100644
--- a/docs/shell_plus.rst
+++ b/docs/shell_plus.rst
@@ -51,6 +51,12 @@ Note: These settings are only used inside shell_plus and will not affect your en
::
+ # Prefix all automatically loaded models in the app blog with myblog.
+ SHELL_PLUS_APP_PREFIXES = {'blog': 'myblog',}
+ }
+
+::
+
# Dont load the 'sites' app, and skip the model 'pictures' in the app 'blog'
SHELL_PLUS_DONT_LOAD = ['sites', 'blog.pictures']
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-django-extensions.git
More information about the Python-modules-commits
mailing list