Fix tests, remove py264 testenv, update docs

This commit is contained in:
Bradley Ayers 2013-01-09 08:56:36 +10:00
parent ef3db2f579
commit b6cc33a9f7
5 changed files with 20 additions and 39 deletions

View File

@ -63,6 +63,12 @@ globally, use::
Change log
==========
v0.14.0
-------
- ``querystring`` and ``seturlparam`` template tags now require the request to
be in the context (backwards incompatible) -- #127
v0.13.0
-------

View File

@ -18,8 +18,8 @@ import tokenize
register = template.Library()
kwarg_re = re.compile(r"(?:(.+)=)?(.+)")
context_proccessor_error_msg = (
"django-tables2 requires django.core.context_processors.request "
context_processor_error_msg = (
"{%% %s %%} requires django.core.context_processors.request "
"to be in your settings.TEMPLATE_CONTEXT_PROCESSORS in order for "
"the included template tags to function correctly."
)
@ -53,7 +53,8 @@ class SetUrlParamNode(Node):
def render(self, context):
if not 'request' in context:
raise ImproperlyConfigured(context_proccessor_error_msg)
raise ImproperlyConfigured(context_processor_error_msg
% 'set_url_param')
params = dict(context['request'].GET)
for key, newvalue in self.changes.items():
newvalue = newvalue.resolve(context)
@ -106,7 +107,8 @@ class QuerystringNode(Node):
def render(self, context):
if not 'request' in context:
raise ImproperlyConfigured(context_proccessor_error_msg)
raise ImproperlyConfigured(context_processor_error_msg
% 'querystring')
params = dict(context['request'].GET)
for key, value in self.updates.iteritems():
key = key.resolve(context)

View File

@ -631,6 +631,9 @@ we want to update the ``sort`` parameter:
{% querystring key="robots" %} # ?search=robots&page=5
{% endwith %}
This tag requires the ``django.core.context_processors.request`` context
processor, see :ref:`template-tags.render_table`.
Template filters
================

View File

@ -172,7 +172,8 @@ def render_table_supports_queryset():
for name in ("Mackay", "Brisbane", "Maryborough"):
Region.objects.create(name=name)
template = Template('{% load django_tables2 %}{% render_table qs %}')
html = template.render(Context({'qs': Region.objects.all()}))
html = template.render(Context({'qs': Region.objects.all(),
'request': build_request('/')}))
root = parse(html)
assert [e.text for e in root.findall('.//thead/tr/th/a')] == ["ID", "Name", "Mayor"]
td = [[unicode(td.text) for td in tr.findall('td')] for tr in root.findall('.//tbody/tr')]
@ -273,9 +274,6 @@ def as_html_db_queries():
@templates.test
def render_table_db_queries():
render = lambda **kw: (Template('{% load django_tables2 %}{% render_table table %}')
.render(Context(kw)))
with database():
Person.objects.create(first_name="brad", last_name="ayers")
Person.objects.create(first_name="stevie", last_name="armstrong")
@ -285,18 +283,15 @@ def render_table_db_queries():
model = Person
per_page = 1
with queries(count=2):
# one query to check if there's anything to display: .count()
# one query for page records: .all()[start:end]
render(table=PersonTable(Person.objects.all()))
with queries(count=2):
# one query for pagination: .count()
# one query for page records: .all()[start:end]
request = build_request('/')
table = PersonTable(Person.objects.all())
RequestConfig(request).configure(table)
render(table=table, request=request)
# render
(Template('{% load django_tables2 %}{% render_table table %}')
.render(Context({'table': table, 'request': request})))
@templates.test

25
tox.ini
View File

@ -67,31 +67,6 @@ deps =
{[tools]testing}
{[django]1.2.x}
; -- python 2.6.4 -------------------------------------------------------------
; Django >=1.5 does not support 2.6.4
[testenv:py264-dj14]
basepython = python2.6.4
deps =
{[tools]testing}
{[django]1.4.x}
[testenv:py264-dj13]
basepython = python2.6.4
deps =
{[tools]testing}
{[django]1.3.x}
[testenv:py264-dj12]
basepython = python2.6.4
commands =
python {envbindir}/coverage run setup.py test []
coverage html
deps =
{[tools]testing}
{[django]1.2.x}
; -- python 2.6 ---------------------------------------------------------------
[testenv:py26-dj]