diff --git a/AUTHORS b/AUTHORS
index e52fb46b47..4d57503bf8 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -104,7 +104,6 @@ answer newbie questions, and generally made Django that much better:
mattycakes@gmail.com
Jason McBrayer
michael.mcewan@gmail.com
- mir@noris.de
mmarshall
Eric Moritz
Robin Munn
@@ -121,11 +120,14 @@ answer newbie questions, and generally made Django that much better:
plisk
Daniel Poelzleithner
J. Rademaker
+ Michael Radziej
Brian Ray
rhettg@gmail.com
Oliver Rutherfurd
Ivan Sagalaev (Maniac)
David Schein
+ Pete Shinners
+ SmileyChris
sopel
Thomas Steinacher
Radek Švarz
@@ -138,6 +140,7 @@ answer newbie questions, and generally made Django that much better:
Amit Upadhyay
Geert Vanderkelen
Milton Waddams
+ Dan Watson
Rachel Willmer
wojtek
ye7cakf02@sneakemail.com
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 56a4ccb48a..c382d7bf96 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -301,4 +301,9 @@ AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
# TESTING #
###########
-TEST_RUNNER='django.test.simple.run_tests'
+# The name of the method to use to invoke the test suite
+TEST_RUNNER = 'django.test.simple.run_tests'
+
+# The name of the database to use for testing purposes.
+# If None, a name of 'test_' + DATABASE_NAME will be assumed
+TEST_DATABASE_NAME = None
diff --git a/django/contrib/admin/views/doc.py b/django/contrib/admin/views/doc.py
index b724cc5485..435d76f276 100644
--- a/django/contrib/admin/views/doc.py
+++ b/django/contrib/admin/views/doc.py
@@ -328,13 +328,17 @@ def extract_views_from_urlpatterns(urlpatterns, base=''):
"""
views = []
for p in urlpatterns:
- if hasattr(p, 'get_callback'):
+ if hasattr(p, '_get_callback'):
try:
- views.append((p.get_callback(), base + p.regex.pattern))
+ views.append((p._get_callback(), base + p.regex.pattern))
except ViewDoesNotExist:
continue
elif hasattr(p, '_get_url_patterns'):
- views.extend(extract_views_from_urlpatterns(p.url_patterns, base + p.regex.pattern))
+ try:
+ patterns = p.url_patterns
+ except ImportError:
+ continue
+ views.extend(extract_views_from_urlpatterns(patterns, base + p.regex.pattern))
else:
raise TypeError, _("%s does not appear to be a urlpattern object") % p
return views
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index 4077237993..eb5713ba57 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -33,7 +33,7 @@ class Permission(models.Model):
Permissions are set globally per type of object, not per specific object instance. It is possible to say "Mary may change news stories," but it's not currently possible to say "Mary may change news stories, but only the ones she created herself" or "Mary may only change news stories that have a certain status or publication date."
- Three basic permissions -- add, create and delete -- are automatically created for each Django model.
+ Three basic permissions -- add, change and delete -- are automatically created for each Django model.
"""
name = models.CharField(_('name'), maxlength=50)
content_type = models.ForeignKey(ContentType)
diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
new file mode 100644
index 0000000000..2c76e13c22
--- /dev/null
+++ b/django/contrib/sitemaps/__init__.py
@@ -0,0 +1,90 @@
+from django.core import urlresolvers
+import urllib
+
+PING_URL = "http://www.google.com/webmasters/sitemaps/ping"
+
+class SitemapNotFound(Exception):
+ pass
+
+def ping_google(sitemap_url=None, ping_url=PING_URL):
+ """
+ Alerts Google that the sitemap for the current site has been updated.
+ If sitemap_url is provided, it should be an absolute path to the sitemap
+ for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
+ function will attempt to deduce it by using urlresolvers.reverse().
+ """
+ if sitemap_url is None:
+ try:
+ # First, try to get the "index" sitemap URL.
+ sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.index')
+ except urlresolvers.NoReverseMatch:
+ try:
+ # Next, try for the "global" sitemap URL.
+ sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap')
+ except urlresolvers.NoReverseMatch:
+ pass
+
+ if sitemap_url is None:
+ raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")
+
+ from django.contrib.sites.models import Site
+ current_site = Site.objects.get_current()
+ url = "%s%s" % (current_site.domain, sitemap)
+ params = urllib.urlencode({'sitemap':url})
+ urllib.urlopen("%s?%s" % (ping_url, params))
+
+class Sitemap:
+ def __get(self, name, obj, default=None):
+ try:
+ attr = getattr(self, name)
+ except AttributeError:
+ return default
+ if callable(attr):
+ return attr(obj)
+ return attr
+
+ def items(self):
+ return []
+
+ def location(self, obj):
+ return obj.get_absolute_url()
+
+ def get_urls(self):
+ from django.contrib.sites.models import Site
+ current_site = Site.objects.get_current()
+ urls = []
+ for item in self.items():
+ loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
+ url_info = {
+ 'location': loc,
+ 'lastmod': self.__get('lastmod', item, None),
+ 'changefreq': self.__get('changefreq', item, None),
+ 'priority': self.__get('priority', item, None)
+ }
+ urls.append(url_info)
+ return urls
+
+class FlatPageSitemap(Sitemap):
+ def items(self):
+ from django.contrib.sites.models import Site
+ current_site = Site.objects.get_current()
+ return current_site.flatpage_set.all()
+
+class GenericSitemap(Sitemap):
+ priority = None
+ changefreq = None
+
+ def __init__(self, info_dict, priority=None, changefreq=None):
+ self.queryset = info_dict['queryset']
+ self.date_field = info_dict.get('date_field', None)
+ self.priority = priority
+ self.changefreq = changefreq
+
+ def items(self):
+ # Make sure to return a clone; we don't want premature evaluation.
+ return self.queryset.filter()
+
+ def lastmod(self, item):
+ if self.date_field is not None:
+ return getattr(item, self.date_field)
+ return None
diff --git a/django/contrib/sitemaps/templates/sitemap.xml b/django/contrib/sitemaps/templates/sitemap.xml
new file mode 100644
index 0000000000..3ee4f914f7
--- /dev/null
+++ b/django/contrib/sitemaps/templates/sitemap.xml
@@ -0,0 +1,11 @@
+
+
+{% for url in urlset %}
+
+ {{ url.location|escape }}
+ {% if url.lastmod %}{{ url.lastmod|date:"Y-m-d" }}{% endif %}
+ {% if url.changefreq %}{{ url.changefreq }}{% endif %}
+ {% if url.priority %}{{ url.priority }}{% endif %}
+
+{% endfor %}
+
diff --git a/django/contrib/sitemaps/templates/sitemap_index.xml b/django/contrib/sitemaps/templates/sitemap_index.xml
new file mode 100644
index 0000000000..e9d722ac7f
--- /dev/null
+++ b/django/contrib/sitemaps/templates/sitemap_index.xml
@@ -0,0 +1,8 @@
+
+
+{% for location in sitemaps %}
+
+ {{ location|escape }}
+
+{% endfor %}
+
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
new file mode 100644
index 0000000000..576e3d0bb8
--- /dev/null
+++ b/django/contrib/sitemaps/views.py
@@ -0,0 +1,30 @@
+from django.http import HttpResponse, Http404
+from django.template import loader
+from django.contrib.sites.models import Site
+from django.core import urlresolvers
+
+def index(request, sitemaps):
+ current_site = Site.objects.get_current()
+ sites = []
+ protocol = request.is_secure() and 'https' or 'http'
+ for section in sitemaps.keys():
+ sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap', kwargs={'section': section})
+ sites.append('%s://%s%s' % (protocol, current_site.domain, sitemap_url))
+ xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
+ return HttpResponse(xml, mimetype='application/xml')
+
+def sitemap(request, sitemaps, section=None):
+ maps, urls = [], []
+ if section is not None:
+ if not sitemaps.has_key(section):
+ raise Http404("No sitemap available for section: %r" % section)
+ maps.append(sitemaps[section])
+ else:
+ maps = sitemaps.values()
+ for site in maps:
+ if callable(site):
+ urls.extend(site().get_urls())
+ else:
+ urls.extend(site.get_urls())
+ xml = loader.render_to_string('sitemap.xml', {'urlset': urls})
+ return HttpResponse(xml, mimetype='application/xml')
diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index e939c0c6e7..fb293c7c13 100644
--- a/django/core/serializers/base.py
+++ b/django/core/serializers/base.py
@@ -11,7 +11,7 @@ from django.db import models
class SerializationError(Exception):
"""Something bad happened during serialization."""
pass
-
+
class DeserializationError(Exception):
"""Something bad happened during deserialization."""
pass
@@ -20,15 +20,15 @@ class Serializer(object):
"""
Abstract serializer base class.
"""
-
+
def serialize(self, queryset, **options):
"""
Serialize a queryset.
"""
self.options = options
-
+
self.stream = options.get("stream", StringIO())
-
+
self.start_serialization()
for obj in queryset:
self.start_object(obj)
@@ -44,61 +44,65 @@ class Serializer(object):
self.end_object(obj)
self.end_serialization()
return self.getvalue()
-
+
def get_string_value(self, obj, field):
"""
Convert a field's value to a string.
"""
if isinstance(field, models.DateTimeField):
- value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S")
+ value = getattr(obj, field.name)
+ if value is None:
+ value = ''
+ else:
+ value = value.strftime("%Y-%m-%d %H:%M:%S")
elif isinstance(field, models.FileField):
value = getattr(obj, "get_%s_url" % field.name, lambda: None)()
else:
value = field.flatten_data(follow=None, obj=obj).get(field.name, "")
return str(value)
-
+
def start_serialization(self):
"""
Called when serializing of the queryset starts.
"""
raise NotImplementedError
-
+
def end_serialization(self):
"""
Called when serializing of the queryset ends.
"""
pass
-
+
def start_object(self, obj):
"""
Called when serializing of an object starts.
"""
raise NotImplementedError
-
+
def end_object(self, obj):
"""
Called when serializing of an object ends.
"""
pass
-
+
def handle_field(self, obj, field):
"""
Called to handle each individual (non-relational) field on an object.
"""
raise NotImplementedError
-
+
def handle_fk_field(self, obj, field):
"""
Called to handle a ForeignKey field.
"""
raise NotImplementedError
-
+
def handle_m2m_field(self, obj, field):
"""
Called to handle a ManyToManyField.
"""
raise NotImplementedError
-
+
def getvalue(self):
"""
Return the fully serialized queryset.
@@ -109,7 +113,7 @@ class Deserializer(object):
"""
Abstract base deserializer class.
"""
-
+
def __init__(self, stream_or_string, **options):
"""
Init this serializer given a stream or a string
@@ -123,39 +127,39 @@ class Deserializer(object):
# deserialization starts (otherwise subclass calls to get_model()
# and friends might fail...)
models.get_apps()
-
+
def __iter__(self):
return self
-
+
def next(self):
"""Iteration iterface -- return the next item in the stream"""
raise NotImplementedError
-
+
class DeserializedObject(object):
"""
A deserialzed model.
-
+
Basically a container for holding the pre-saved deserialized data along
with the many-to-many data saved with the object.
-
+
Call ``save()`` to save the object (with the many-to-many data) to the
database; call ``save(save_m2m=False)`` to save just the object fields
(and not touch the many-to-many stuff.)
"""
-
+
def __init__(self, obj, m2m_data=None):
self.object = obj
self.m2m_data = m2m_data
-
+
def __repr__(self):
return "" % str(self.object)
-
+
def save(self, save_m2m=True):
self.object.save()
if self.m2m_data and save_m2m:
for accessor_name, object_list in self.m2m_data.items():
setattr(self.object, accessor_name, object_list)
-
- # prevent a second (possibly accidental) call to save() from saving
+
+ # prevent a second (possibly accidental) call to save() from saving
# the m2m data twice.
self.m2m_data = None
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 68452e1363..a3e8f0d584 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -62,7 +62,10 @@ class DatabaseWrapper(local):
self.connection.rollback()
def close(self):
- if self.connection is not None:
+ from django.conf import settings
+ # If database is in memory, closing the connection destroys the database.
+ # To prevent accidental data loss, ignore close requests on an in-memory db.
+ if self.connection is not None and settings.DATABASE_NAME != ":memory:":
self.connection.close()
self.connection = None
diff --git a/django/db/backends/util.py b/django/db/backends/util.py
index 74d33f42ca..88318941c8 100644
--- a/django/db/backends/util.py
+++ b/django/db/backends/util.py
@@ -98,7 +98,7 @@ def rev_typecast_boolean(obj, d):
def _dict_helper(desc, row):
"Returns a dictionary for the given cursor.description and result row."
- return dict([(desc[col[0]][0], col[1]) for col in enumerate(row)])
+ return dict(zip([col[0] for col in desc], row))
def dictfetchone(cursor):
"Returns a row from the cursor as a dict"
diff --git a/django/template/__init__.py b/django/template/__init__.py
index ba7ca4c02b..fa75f6c2f5 100644
--- a/django/template/__init__.py
+++ b/django/template/__init__.py
@@ -137,13 +137,14 @@ class StringOrigin(Origin):
return self.source
class Template(object):
- def __init__(self, template_string, origin=None):
+ def __init__(self, template_string, origin=None, name=''):
"Compilation stage"
if settings.TEMPLATE_DEBUG and origin == None:
origin = StringOrigin(template_string)
# Could do some crazy stack-frame stuff to record where this string
# came from...
self.nodelist = compile_string(template_string, origin)
+ self.name = name
def __iter__(self):
for node in self.nodelist:
@@ -434,7 +435,7 @@ class TokenParser(object):
while i < len(subject) and subject[i] != subject[p]:
i += 1
if i >= len(subject):
- raise TemplateSyntaxError, "Searching for value. Unexpected end of string in column %d: %s" % subject
+ raise TemplateSyntaxError, "Searching for value. Unexpected end of string in column %d: %s" % (i, subject)
i += 1
res = subject[p:i]
while i < len(subject) and subject[i] in (' ', '\t'):
@@ -548,9 +549,12 @@ class FilterExpression(object):
obj = resolve_variable(self.var, context)
except VariableDoesNotExist:
if ignore_failures:
- return None
+ obj = None
else:
- return settings.TEMPLATE_STRING_IF_INVALID
+ if settings.TEMPLATE_STRING_IF_INVALID:
+ return settings.TEMPLATE_STRING_IF_INVALID
+ else:
+ obj = settings.TEMPLATE_STRING_IF_INVALID
for func, args in self.filters:
arg_vals = []
for lookup, arg in args:
@@ -614,11 +618,7 @@ def resolve_variable(path, context):
(The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.')
"""
- if path == 'False':
- current = False
- elif path == 'True':
- current = True
- elif path[0].isdigit():
+ if path[0].isdigit():
number_type = '.' in path and float or int
try:
current = number_type(path)
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 0a4fe33d82..691b40f332 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -86,7 +86,7 @@ class ForNode(Node):
parentloop = {}
context.push()
try:
- values = self.sequence.resolve(context)
+ values = self.sequence.resolve(context, True)
except VariableDoesNotExist:
values = []
if values is None:
@@ -212,13 +212,13 @@ class RegroupNode(Node):
self.var_name = var_name
def render(self, context):
- obj_list = self.target.resolve(context)
- if obj_list == '': # target_var wasn't found in context; fail silently
+ obj_list = self.target.resolve(context, True)
+ if obj_list == None: # target_var wasn't found in context; fail silently
context[self.var_name] = []
return ''
output = [] # list of dictionaries in the format {'grouper': 'key', 'list': [list of contents]}
for obj in obj_list:
- grouper = self.expression.resolve(Context({'var': obj}))
+ grouper = self.expression.resolve(Context({'var': obj}), True)
# TODO: Is this a sensible way to determine equality?
if output and repr(output[-1]['grouper']) == repr(grouper):
output[-1]['list'].append(obj)
@@ -251,7 +251,7 @@ class SsiNode(Node):
output = ''
if self.parsed:
try:
- t = Template(output)
+ t = Template(output, name=self.filepath)
return t.render(context)
except TemplateSyntaxError, e:
if settings.DEBUG:
diff --git a/django/template/loader.py b/django/template/loader.py
index 60f24554f1..03e6f8d49d 100644
--- a/django/template/loader.py
+++ b/django/template/loader.py
@@ -76,14 +76,16 @@ def get_template(template_name):
Returns a compiled Template object for the given template name,
handling template inheritance recursively.
"""
- return get_template_from_string(*find_template_source(template_name))
+ source, origin = find_template_source(template_name)
+ template = get_template_from_string(source, origin, template_name)
+ return template
-def get_template_from_string(source, origin=None):
+def get_template_from_string(source, origin=None, name=None):
"""
Returns a compiled Template object for the given template code,
handling template inheritance recursively.
"""
- return Template(source, origin)
+ return Template(source, origin, name)
def render_to_string(template_name, dictionary=None, context_instance=None):
"""
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index 7f22f207b6..e329b1bb36 100644
--- a/django/template/loader_tags.py
+++ b/django/template/loader_tags.py
@@ -51,13 +51,13 @@ class ExtendsNode(Node):
error_msg += " Got this from the %r variable." % self.parent_name_expr #TODO nice repr.
raise TemplateSyntaxError, error_msg
if hasattr(parent, 'render'):
- return parent
+ return parent # parent is a Template object
try:
source, origin = find_template_source(parent, self.template_dirs)
except TemplateDoesNotExist:
raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
else:
- return get_template_from_string(source, origin)
+ return get_template_from_string(source, origin, parent)
def render(self, context):
compiled_parent = self.get_parent(context)
diff --git a/django/test/client.py b/django/test/client.py
index 871f6cfb9b..3dfe764a38 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -1,10 +1,9 @@
from cStringIO import StringIO
-from django.contrib.admin.views.decorators import LOGIN_FORM_KEY, _encode_post_data
from django.core.handlers.base import BaseHandler
from django.core.handlers.wsgi import WSGIRequest
from django.dispatch import dispatcher
from django.http import urlencode, SimpleCookie
-from django.template import signals
+from django.test import signals
from django.utils.functional import curry
class ClientHandler(BaseHandler):
@@ -96,7 +95,7 @@ class Client:
HTML rendered to the end-user.
"""
def __init__(self, **defaults):
- self.handler = TestHandler()
+ self.handler = ClientHandler()
self.defaults = defaults
self.cookie = SimpleCookie()
@@ -126,7 +125,7 @@ class Client:
data = {}
on_template_render = curry(store_rendered_templates, data)
dispatcher.connect(on_template_render, signal=signals.template_rendered)
-
+
response = self.handler(environ)
# Add any rendered template detail to the response
@@ -180,29 +179,38 @@ class Client:
def login(self, path, username, password, **extra):
"""
A specialized sequence of GET and POST to log into a view that
- is protected by @login_required or a similar access decorator.
+ is protected by a @login_required access decorator.
- path should be the URL of the login page, or of any page that
- is login protected.
+ path should be the URL of the page that is login protected.
- Returns True if login was successful; False if otherwise.
+ Returns the response from GETting the requested URL after
+ login is complete. Returns False if login process failed.
"""
- # First, GET the login page.
- # This is required to establish the session.
+ # First, GET the page that is login protected.
+ # This page will redirect to the login page.
response = self.get(path)
+ if response.status_code != 302:
+ return False
+
+ login_path, data = response['Location'].split('?')
+ next = data.split('=')[1]
+
+ # Second, GET the login page; required to set up cookies
+ response = self.get(login_path, **extra)
if response.status_code != 200:
return False
-
- # Set up the block of form data required by the login page.
+
+ # Last, POST the login data.
form_data = {
'username': username,
'password': password,
- 'this_is_the_login_form': 1,
- 'post_data': _encode_post_data({LOGIN_FORM_KEY: 1})
+ 'next' : next,
}
- response = self.post(path, data=form_data, **extra)
-
- # login page should give response 200 (if you requested the login
- # page specifically), or 302 (if you requested a login
- # protected page, to which the login can redirect).
- return response.status_code in (200,302)
+ response = self.post(login_path, data=form_data, **extra)
+
+ # Login page should 302 redirect to the originally requested page
+ if response.status_code != 302 or response['Location'] != path:
+ return False
+
+ # Since we are logged in, request the actual page again
+ return self.get(path)
diff --git a/django/test/signals.py b/django/test/signals.py
new file mode 100644
index 0000000000..40748ff4fe
--- /dev/null
+++ b/django/test/signals.py
@@ -0,0 +1 @@
+template_rendered = object()
\ No newline at end of file
diff --git a/django/test/simple.py b/django/test/simple.py
index e72f693459..043787414e 100644
--- a/django/test/simple.py
+++ b/django/test/simple.py
@@ -1,6 +1,7 @@
import unittest, doctest
from django.conf import settings
from django.core import management
+from django.test.utils import setup_test_environment, teardown_test_environment
from django.test.utils import create_test_db, destroy_test_db
from django.test.testcases import OutputChecker, DocTestRunner
@@ -51,6 +52,7 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
the module. A list of 'extra' tests may also be provided; these tests
will be added to the test suite.
"""
+ setup_test_environment()
settings.DEBUG = False
suite = unittest.TestSuite()
@@ -61,7 +63,10 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
for test in extra_tests:
suite.addTest(test)
- old_name = create_test_db(verbosity)
+ old_name = settings.DATABASE_NAME
+ create_test_db(verbosity)
management.syncdb(verbosity, interactive=False)
unittest.TextTestRunner(verbosity=verbosity).run(suite)
destroy_test_db(old_name, verbosity)
+
+ teardown_test_environment()
diff --git a/django/test/utils.py b/django/test/utils.py
index dd48d95aea..039a6dd7a2 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -1,11 +1,40 @@
import sys, time
from django.conf import settings
from django.db import connection, transaction, backend
+from django.dispatch import dispatcher
+from django.test import signals
+from django.template import Template
# The prefix to put on the default database name when creating
# the test database.
TEST_DATABASE_PREFIX = 'test_'
+def instrumented_test_render(self, context):
+ """An instrumented Template render method, providing a signal
+ that can be intercepted by the test system Client
+
+ """
+ dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context)
+ return self.nodelist.render(context)
+
+def setup_test_environment():
+ """Perform any global pre-test setup. This involves:
+
+ - Installing the instrumented test renderer
+
+ """
+ Template.original_render = Template.render
+ Template.render = instrumented_test_render
+
+def teardown_test_environment():
+ """Perform any global post-test teardown. This involves:
+
+ - Restoring the original test renderer
+
+ """
+ Template.render = Template.original_render
+ del Template.original_render
+
def _set_autocommit(connection):
"Make sure a connection is in autocommit mode."
if hasattr(connection.connection, "autocommit"):
@@ -21,7 +50,10 @@ def create_test_db(verbosity=1, autoclobber=False):
if settings.DATABASE_ENGINE == "sqlite3":
TEST_DATABASE_NAME = ":memory:"
else:
- TEST_DATABASE_NAME = TEST_DATABASE_PREFIX + settings.DATABASE_NAME
+ if settings.TEST_DATABASE_NAME:
+ TEST_DATABASE_NAME = settings.TEST_DATABASE_NAME
+ else:
+ TEST_DATABASE_NAME = TEST_DATABASE_PREFIX + settings.DATABASE_NAME
# Create the test database and connect to it. We need to autocommit
# if the database supports it because PostgreSQL doesn't allow
@@ -50,14 +82,11 @@ def create_test_db(verbosity=1, autoclobber=False):
sys.exit(1)
connection.close()
- old_database_name = settings.DATABASE_NAME
settings.DATABASE_NAME = TEST_DATABASE_NAME
# Get a cursor (even though we don't need one yet). This has
# the side effect of initializing the test database.
cursor = connection.cursor()
-
- return old_database_name
def destroy_test_db(old_database_name, verbosity=1):
# Unless we're using SQLite, remove the test database to clean up after
@@ -66,13 +95,13 @@ def destroy_test_db(old_database_name, verbosity=1):
# connected to it.
if verbosity >= 1:
print "Destroying test database..."
+ connection.close()
+ TEST_DATABASE_NAME = settings.DATABASE_NAME
+ settings.DATABASE_NAME = old_database_name
+
if settings.DATABASE_ENGINE != "sqlite3":
- connection.close()
- TEST_DATABASE_NAME = settings.DATABASE_NAME
- settings.DATABASE_NAME = old_database_name
cursor = connection.cursor()
_set_autocommit(connection)
time.sleep(1) # To avoid "database is being accessed by other users" errors.
cursor.execute("DROP DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME))
connection.close()
-
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 632e804f26..6aef313d35 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -187,17 +187,23 @@ class MultiValueDict(dict):
"Returns a copy of this object."
return self.__deepcopy__()
- def update(self, other_dict):
- "update() extends rather than replaces existing key lists."
- if isinstance(other_dict, MultiValueDict):
- for key, value_list in other_dict.lists():
- self.setlistdefault(key, []).extend(value_list)
- else:
- try:
- for key, value in other_dict.items():
- self.setlistdefault(key, []).append(value)
- except TypeError:
- raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
+ def update(self, *args, **kwargs):
+ "update() extends rather than replaces existing key lists. Also accepts keyword args."
+ if len(args) > 1:
+ raise TypeError, "update expected at most 1 arguments, got %d", len(args)
+ if args:
+ other_dict = args[0]
+ if isinstance(other_dict, MultiValueDict):
+ for key, value_list in other_dict.lists():
+ self.setlistdefault(key, []).extend(value_list)
+ else:
+ try:
+ for key, value in other_dict.items():
+ self.setlistdefault(key, []).append(value)
+ except TypeError:
+ raise ValueError, "MultiValueDict.update() takes either a MultiValueDict or dictionary"
+ for key, value in kwargs.iteritems():
+ self.setlistdefault(key, []).append(value)
class DotExpandedDict(dict):
"""
diff --git a/django/views/debug.py b/django/views/debug.py
index 6934360afd..6178bdb83b 100644
--- a/django/views/debug.py
+++ b/django/views/debug.py
@@ -115,7 +115,7 @@ def technical_500_response(request, exc_type, exc_value, tb):
'function': '?',
'lineno': '?',
}]
- t = Template(TECHNICAL_500_TEMPLATE)
+ t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template')
c = Context({
'exception_type': exc_type.__name__,
'exception_value': exc_value,
@@ -141,7 +141,7 @@ def technical_404_response(request, exception):
# tried exists but is an empty list. The URLconf must've been empty.
return empty_urlconf(request)
- t = Template(TECHNICAL_404_TEMPLATE)
+ t = Template(TECHNICAL_404_TEMPLATE, name='Technical 404 template')
c = Context({
'root_urlconf': settings.ROOT_URLCONF,
'urlpatterns': tried,
@@ -154,7 +154,7 @@ def technical_404_response(request, exception):
def empty_urlconf(request):
"Create an empty URLconf 404 error response."
- t = Template(EMPTY_URLCONF_TEMPLATE)
+ t = Template(EMPTY_URLCONF_TEMPLATE, name='Empty URLConf template')
c = Context({
'project_name': settings.SETTINGS_MODULE.split('.')[0]
})
@@ -189,7 +189,7 @@ TECHNICAL_500_TEMPLATE = """
- {{ exception_type }} at {{ request.path }}
+ {{ exception_type }} at {{ request.path|escape }}