Skip to content

Commit

Permalink
Merged recent trunk changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Sep 25, 2012
2 parents 29d1abb + 1f84b04 commit 531e771
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 111 deletions.
30 changes: 16 additions & 14 deletions django/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,28 @@ def _setup(self, name):
% (name, ENVIRONMENT_VARIABLE))

self._wrapped = Settings(settings_module)

self._configure_logging()

def __getattr__(self, name):
if self._wrapped is empty:
self._setup(name)
return getattr(self._wrapped, name)

def _configure_logging(self):
"""
Setup logging from LOGGING_CONFIG and LOGGING settings.
"""
if self.LOGGING_CONFIG:
# First find the logging configuration function ...
logging_config_path, logging_config_func_name = self.LOGGING_CONFIG.rsplit('.', 1)
logging_config_module = importlib.import_module(logging_config_path)
logging_config_func = getattr(logging_config_module, logging_config_func_name)

# Backwards-compatibility shim for #16288 fix
compat_patch_logging_config(self.LOGGING)

# ... then invoke it with the logging settings
logging_config_func(self.LOGGING)

def configure(self, default_settings=global_settings, **options):
"""
Expand Down Expand Up @@ -133,19 +148,6 @@ def __init__(self, settings_module):
os.environ['TZ'] = self.TIME_ZONE
time.tzset()

# Settings are configured, so we can set up the logger if required
if self.LOGGING_CONFIG:
# First find the logging configuration function ...
logging_config_path, logging_config_func_name = self.LOGGING_CONFIG.rsplit('.', 1)
logging_config_module = importlib.import_module(logging_config_path)
logging_config_func = getattr(logging_config_module, logging_config_func_name)

# Backwards-compatibility shim for #16288 fix
compat_patch_logging_config(self.LOGGING)

# ... then invoke it with the logging settings
logging_config_func(self.LOGGING)


class UserSettingsHolder(BaseSettings):
"""
Expand Down
2 changes: 1 addition & 1 deletion django/contrib/admin/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{% if change %}{% if not is_popup %}
<ul class="object-tools">
{% block object-tools-items %}
<li><a href="{% url opts|admin_urlname:'history' original.pk %}" class="historylink">{% trans "History" %}</a></li>
<li><a href="{% url opts|admin_urlname:'history' original.pk|admin_urlquote %}" class="historylink">{% trans "History" %}</a></li>
{% if has_absolute_url %}<li><a href="{% url 'admin:view_on_site' content_type_id original.pk %}" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
{% endblock %}
</ul>
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/admin/templates/admin/submit_line.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% load i18n %}
{% load i18n admin_urls %}
<div class="submit-row">
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" {{ onclick_attrib }}/>{% endif %}
{% if show_delete_link %}<p class="deletelink-box"><a href="delete/" class="deletelink">{% trans "Delete" %}</a></p>{% endif %}
{% if show_delete_link %}<p class="deletelink-box"><a href="{% url opts|admin_urlname:'delete' original.pk|admin_urlquote %}" class="deletelink">{% trans "Delete" %}</a></p>{% endif %}
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" {{ onclick_attrib }}/>{%endif%}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" {{ onclick_attrib }} />{% endif %}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" {{ onclick_attrib }}/>{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" {{ onclick_attrib }}/>{% endif %}
</div>
6 changes: 5 additions & 1 deletion django/contrib/admin/templatetags/admin_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def submit_row(context):
change = context['change']
is_popup = context['is_popup']
save_as = context['save_as']
return {
ctx = {
'opts': opts,
'onclick_attrib': (opts.get_ordered_objects() and change
and 'onclick="submitOrderForm();"' or ''),
'show_delete_link': (not is_popup and context['has_delete_permission']
Expand All @@ -40,6 +41,9 @@ def submit_row(context):
'is_popup': is_popup,
'show_save': True
}
if context.get('original') is not None:
ctx['original'] = context['original']
return ctx

@register.filter
def cell_count(inline_admin_form):
Expand Down
6 changes: 3 additions & 3 deletions django/contrib/admin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def prepare_lookup_value(key, value):
def quote(s):
"""
Ensure that primary key values do not confuse the admin URLs by escaping
any '/', '_' and ':' characters. Similar to urllib.quote, except that the
quoting is slightly different so that it doesn't get automatically
unquoted by the Web browser.
any '/', '_' and ':' and similarly problematic characters.
Similar to urllib.quote, except that the quoting is slightly different so
that it doesn't get automatically unquoted by the Web browser.
"""
if not isinstance(s, six.string_types):
return s
Expand Down
7 changes: 6 additions & 1 deletion django/contrib/admin/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.core.exceptions import SuspiciousOperation, ImproperlyConfigured
from django.core.paginator import InvalidPage
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models.fields import FieldDoesNotExist
from django.utils.datastructures import SortedDict
Expand Down Expand Up @@ -376,4 +377,8 @@ def construct_search(field_name):
return qs

def url_for_result(self, result):
return "%s/" % quote(getattr(result, self.pk_attname))
pk = getattr(result, self.pk_attname)
return reverse('admin:%s_%s_change' % (self.opts.app_label,
self.opts.module_name),
args=(quote(pk),),
current_app=self.model_admin.admin_site.name)
12 changes: 5 additions & 7 deletions django/contrib/formtools/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.contrib.formtools import preview, utils
from django.contrib.formtools.wizard import FormWizard
from django.test import TestCase
from django.test.html import parse_html
from django.test.utils import override_settings
from django.utils import unittest

Expand Down Expand Up @@ -218,7 +219,6 @@ def __init__(self, POST=None):
)
class WizardTests(TestCase):
urls = 'django.contrib.formtools.tests.urls'
input_re = re.compile('name="([^"]+)" value="([^"]+)"')
wizard_step_data = (
{
'0-name': 'Pony',
Expand Down Expand Up @@ -409,14 +409,13 @@ def grab_field_data(self, response):
"""
Pull the appropriate field data from the context to pass to the next wizard step
"""
previous_fields = response.context['previous_fields']
previous_fields = parse_html(response.context['previous_fields'])
fields = {'wizard_step': response.context['step0']}

def grab(m):
fields[m.group(1)] = m.group(2)
return ''
for input_field in previous_fields:
input_attrs = dict(input_field.attributes)
fields[input_attrs["name"]] = input_attrs["value"]

self.input_re.sub(grab, previous_fields)
return fields

def check_wizard_step(self, response, step_no):
Expand All @@ -428,7 +427,6 @@ def check_wizard_step(self, response, step_no):
"""
step_count = len(self.wizard_step_data)

self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Step %d of %d' % (step_no, step_count))

data = self.grab_field_data(response)
Expand Down
5 changes: 4 additions & 1 deletion django/contrib/formtools/tests/wizard/cookiestorage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from django.test import TestCase
from django.core import signing
from django.core.exceptions import SuspiciousOperation
Expand Down Expand Up @@ -41,4 +43,5 @@ def test_reset_cookie(self):
storage.init_data()
storage.update_response(response)
unsigned_cookie_data = cookie_signer.unsign(response.cookies[storage.prefix].value)
self.assertEqual(unsigned_cookie_data, '{"step_files":{},"step":null,"extra_data":{},"step_data":{}}')
self.assertEqual(json.loads(unsigned_cookie_data),
{"step_files": {}, "step": None, "extra_data": {}, "step_data": {}})
2 changes: 1 addition & 1 deletion django/contrib/gis/gdal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from django.contrib.gis.gdal.srs import SpatialReference, CoordTransform
from django.contrib.gis.gdal.geometries import OGRGeometry
HAS_GDAL = True
except ImportError:
except Exception:
HAS_GDAL = False

try:
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ cache is multi-process and thread-safe. To use it, set

The cache :setting:`LOCATION <CACHES-LOCATION>` is used to identify individual
memory stores. If you only have one locmem cache, you can omit the
:setting:`LOCATION <CACHES-LOCATION>`; however, if you have more that one local
:setting:`LOCATION <CACHES-LOCATION>`; however, if you have more than one local
memory cache, you will need to assign a name to at least one of them in
order to keep them separate.

Expand Down
30 changes: 0 additions & 30 deletions docs/topics/logging.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,36 +345,6 @@ This logging configuration does the following things:
printed to the console; ``ERROR`` and ``CRITICAL``
messages will also be output via email.

.. admonition:: Custom handlers and circular imports

If your ``settings.py`` specifies a custom handler class and the file
defining that class also imports ``settings.py`` a circular import will
occur.

For example, if ``settings.py`` contains the following config for
:setting:`LOGGING`::

LOGGING = {
'version': 1,
'handlers': {
'custom_handler': {
'level': 'INFO',
'class': 'myproject.logconfig.MyHandler',
}
}
}

and ``myproject/logconfig.py`` has the following line before the
``MyHandler`` definition::

from django.conf import settings

then the ``dictconfig`` module will raise an exception like the following::

ValueError: Unable to configure handler 'custom_handler':
Unable to configure handler 'custom_handler':
'module' object has no attribute 'logconfig'

.. _formatter documentation: http://docs.python.org/library/logging.html#formatter-objects

Custom logging configuration
Expand Down
10 changes: 7 additions & 3 deletions tests/regressiontests/admin_changelist/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.contrib.admin.options import IncorrectLookupParameters
from django.contrib.admin.views.main import ChangeList, SEARCH_VAR, ALL_VAR
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.template import Context, Template
from django.test import TestCase
from django.test.client import RequestFactory
Expand Down Expand Up @@ -65,7 +66,8 @@ def test_result_list_empty_changelist_value(self):
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
context = Context({'cl': cl})
table_output = template.render(context)
row_html = '<tbody><tr class="row1"><th><a href="%d/">name</a></th><td class="nowrap">(None)</td></tr></tbody>' % new_child.id
link = reverse('admin:admin_changelist_child_change', args=(new_child.id,))
row_html = '<tbody><tr class="row1"><th><a href="%s">name</a></th><td class="nowrap">(None)</td></tr></tbody>' % link
self.assertFalse(table_output.find(row_html) == -1,
'Failed to find expected row element: %s' % table_output)

Expand All @@ -87,7 +89,8 @@ def test_result_list_html(self):
template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
context = Context({'cl': cl})
table_output = template.render(context)
row_html = '<tbody><tr class="row1"><th><a href="%d/">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' % new_child.id
link = reverse('admin:admin_changelist_child_change', args=(new_child.id,))
row_html = '<tbody><tr class="row1"><th><a href="%s">name</a></th><td class="nowrap">Parent object</td></tr></tbody>' % link
self.assertFalse(table_output.find(row_html) == -1,
'Failed to find expected row element: %s' % table_output)

Expand Down Expand Up @@ -425,7 +428,8 @@ def test_dynamic_list_display_links(self):
request = self._mocked_authenticated_request('/child/', superuser)
response = m.changelist_view(request)
for i in range(1, 10):
self.assertContains(response, '<a href="%s/">%s</a>' % (i, i))
link = reverse('admin:admin_changelist_child_change', args=(i,))
self.assertContains(response, '<a href="%s">%s</a>' % (link, i))

list_display = m.get_list_display(request)
list_display_links = m.get_list_display_links(request, list_display)
Expand Down
7 changes: 0 additions & 7 deletions tests/regressiontests/admin_custom_urls/fixtures/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,5 @@
"fields": {
"description": "An action with a name suspected of being a XSS attempt"
}
},
{
"pk": "The name of an action",
"model": "admin_custom_urls.action",
"fields": {
"description": "A generic action"
}
}
]
16 changes: 3 additions & 13 deletions tests/regressiontests/admin_custom_urls/tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import, unicode_literals

from django.contrib.admin.util import quote
from django.core.urlresolvers import reverse
from django.template.response import TemplateResponse
from django.test import TestCase
Expand Down Expand Up @@ -67,27 +68,16 @@ def testAdminUrlsNoClash(self):

# Ditto, but use reverse() to build the URL
url = reverse('admin:%s_action_change' % Action._meta.app_label,
args=('add',))
args=(quote('add'),))
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Change action')

# Should correctly get the change_view for the model instance with the
# funny-looking PK (the one wth a 'path/to/html/document.html' value)
url = reverse('admin:%s_action_change' % Action._meta.app_label,
args=("path/to/html/document.html",))
args=(quote("path/to/html/document.html"),))
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Change action')
self.assertContains(response, 'value="path/to/html/document.html"')

def testChangeViewHistoryButton(self):
url = reverse('admin:%s_action_change' % Action._meta.app_label,
args=('The name of an action',))
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
expected_link = reverse('admin:%s_action_history' %
Action._meta.app_label,
args=('The name of an action',))
self.assertContains(response, '<a href="%s" class="historylink"' %
expected_link)
Loading

0 comments on commit 531e771

Please sign in to comment.