summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2007-11-30 06:23:24 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2007-11-30 06:23:24 +0000
commitc81b01e060ad80a5c4df579a96ff737df2d336b3 (patch)
treed34a873e7b5e19f0e91424d4ab28e2f968233d63 /django/core
parentf88babafc58eafece72d3f2f7444336c69196808 (diff)
newforms-admin: Merged from trunk up to [6775].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6777 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/cache/backends/base.py11
-rw-r--r--django/core/cache/backends/locmem.py7
-rw-r--r--django/core/management/__init__.py49
-rw-r--r--django/core/management/base.py13
-rw-r--r--django/core/paginator.py2
5 files changed, 45 insertions, 37 deletions
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py
index cd0d7bd103..ff4223bf86 100644
--- a/django/core/cache/backends/base.py
+++ b/django/core/cache/backends/base.py
@@ -16,7 +16,7 @@ class BaseCache(object):
def add(self, key, value, timeout=None):
"""
- Set a value in the cache if the key does not already exist. If
+ Set a value in the cache if the key does not already exist. If
timeout is given, that timeout will be used for the key; otherwise
the default cache timeout will be used.
"""
@@ -24,14 +24,14 @@ class BaseCache(object):
def get(self, key, default=None):
"""
- Fetch a given key from the cache. If the key does not exist, return
+ Fetch a given key from the cache. If the key does not exist, return
default, which itself defaults to None.
"""
raise NotImplementedError
def set(self, key, value, timeout=None):
"""
- Set a value in the cache. If timeout is given, that timeout will be
+ Set a value in the cache. If timeout is given, that timeout will be
used for the key; otherwise the default cache timeout will be used.
"""
raise NotImplementedError
@@ -44,10 +44,10 @@ class BaseCache(object):
def get_many(self, keys):
"""
- Fetch a bunch of keys from the cache. For certain backends (memcached,
+ Fetch a bunch of keys from the cache. For certain backends (memcached,
pgsql) this can be *much* faster when fetching multiple values.
- Returns a dict mapping each key in keys to its value. If the given
+ Returns a dict mapping each key in keys to its value. If the given
key is missing, it will be missing from the response dict.
"""
d = {}
@@ -64,4 +64,3 @@ class BaseCache(object):
return self.get(key) is not None
__contains__ = has_key
-
diff --git a/django/core/cache/backends/locmem.py b/django/core/cache/backends/locmem.py
index 5998f7bfd5..2d74e2b132 100644
--- a/django/core/cache/backends/locmem.py
+++ b/django/core/cache/backends/locmem.py
@@ -16,8 +16,12 @@ class CacheClass(SimpleCacheClass):
def add(self, key, value, timeout=None):
self._lock.writer_enters()
+ # Python 2.3 and 2.4 don't allow combined try-except-finally blocks.
try:
- SimpleCacheClass.add(self, key, value, timeout)
+ try:
+ super(CacheClass, self).add(key, pickle.dumps(value), timeout)
+ except pickle.PickleError:
+ pass
finally:
self._lock.writer_leaves()
@@ -49,6 +53,7 @@ class CacheClass(SimpleCacheClass):
def set(self, key, value, timeout=None):
self._lock.writer_enters()
+ # Python 2.3 and 2.4 don't allow combined try-except-finally blocks.
try:
try:
super(CacheClass, self).set(key, pickle.dumps(value), timeout)
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index dce2fd493d..fcbc9d1110 100644
--- a/django/core/management/__init__.py
+++ b/django/core/management/__init__.py
@@ -52,7 +52,7 @@ def load_command_class(app_name, name):
return getattr(__import__('%s.management.commands.%s' % (app_name, name),
{}, {}, ['Command']), 'Command')()
-def get_commands(load_user_commands=True, project_directory=None):
+def get_commands():
"""
Returns a dictionary of commands against the application in which
those commands can be found. This works by looking for a
@@ -60,10 +60,10 @@ def get_commands(load_user_commands=True, project_directory=None):
application -- if a commands package exists, all commands in that
package are registered.
- Core commands are always included; user-defined commands will also
- be included if ``load_user_commands`` is True. If a project directory
- is provided, the startproject command will be disabled, and the
- startapp command will be modified to use that directory.
+ Core commands are always included. If a settings module has been
+ specified, user-defined commands will also be included, the
+ startproject command will be disabled, and the startapp command
+ will be modified to use the directory in which that module appears.
The dictionary is in the format {command_name: app_name}. Key-value
pairs from this dictionary can then be used in calls to
@@ -80,16 +80,27 @@ def get_commands(load_user_commands=True, project_directory=None):
if _commands is None:
_commands = dict([(name, 'django.core')
for name in find_commands(__path__[0])])
- if load_user_commands:
- # Get commands from all installed apps.
+ # Get commands from all installed apps.
+ try:
+ from django.conf import settings
+ apps = settings.INSTALLED_APPS
+ except (AttributeError, EnvironmentError):
+ apps = []
+
+ for app_name in apps:
+ try:
+ path = find_management_module(app_name)
+ _commands.update(dict([(name, app_name)
+ for name in find_commands(path)]))
+ except ImportError:
+ pass # No management module - ignore this app
+
+ # Try to determine the project directory
+ try:
from django.conf import settings
- for app_name in settings.INSTALLED_APPS:
- try:
- path = find_management_module(app_name)
- _commands.update(dict([(name, app_name)
- for name in find_commands(path)]))
- except ImportError:
- pass # No management module - ignore this app
+ project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
+ except (AttributeError, EnvironmentError, ImportError):
+ project_directory = None
if project_directory:
# Remove the "startproject" command from self.commands, because
@@ -146,8 +157,6 @@ class ManagementUtility(object):
def __init__(self, argv=None):
self.argv = argv or sys.argv[:]
self.prog_name = os.path.basename(self.argv[0])
- self.project_directory = None
- self.user_commands = False
def main_help_text(self):
"""
@@ -159,8 +168,7 @@ class ManagementUtility(object):
usage.append("Type '%s help <subcommand>' for help on a specific"
" subcommand." % self.prog_name)
usage.append('Available subcommands:')
- commands = get_commands(self.user_commands,
- self.project_directory).keys()
+ commands = get_commands().keys()
commands.sort()
for cmd in commands:
usage.append(' %s' % cmd)
@@ -173,8 +181,7 @@ class ManagementUtility(object):
django-admin.py or manage.py) if it can't be found.
"""
try:
- app_name = get_commands(self.user_commands,
- self.project_directory)[subcommand]
+ app_name = get_commands()[subcommand]
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
klass = app_name
@@ -235,8 +242,6 @@ class ProjectManagementUtility(ManagementUtility):
"""
def __init__(self, argv, project_directory):
super(ProjectManagementUtility, self).__init__(argv)
- self.project_directory = project_directory
- self.user_commands = True
def setup_environ(settings_mod):
"""
diff --git a/django/core/management/base.py b/django/core/management/base.py
index 0c458126e8..31c2849075 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -172,14 +172,13 @@ def copy_helper(style, app_or_project, name, directory, other_name=''):
"""
Copies either a Django application layout template or a Django project
layout template into the specified directory.
-
- * style - A color style object (see django.core.management.color).
- * app_or_project - The string 'app' or 'project'.
- * name - The name of the application or project.
- * directory - The directory to copy the layout template to.
- * other_name - When copying an application layout, this should be the name
- of the project.
"""
+ # style -- A color style object (see django.core.management.color).
+ # app_or_project -- The string 'app' or 'project'.
+ # name -- The name of the application or project.
+ # directory -- The directory to which the layout template should be copied.
+ # other_name -- When copying an application layout, this should be the name
+ # of the project.
import re
import shutil
other = {'project': 'app', 'app': 'project'}[app_or_project]
diff --git a/django/core/paginator.py b/django/core/paginator.py
index b50ca826c4..71a5479fd5 100644
--- a/django/core/paginator.py
+++ b/django/core/paginator.py
@@ -91,7 +91,7 @@ class ObjectPaginator(object):
a template for loop.
"""
if self._page_range is None:
- self._page_range = range(1, self._pages + 1)
+ self._page_range = range(1, self.pages + 1)
return self._page_range
hits = property(_get_hits)