visible=True, sortable=None):
if not (accessor is None or isinstance(accessor, basestring) or
callable(accessor)):
- raise TypeError('accessor must be a string or callable, not %s' %
+ raise TypeError(u'accessor must be a string or callable, not %s' %
accessor.__class__.__name__)
if callable(accessor) and default is not None:
raise TypeError('accessor must be string when default is used, not'
'type': 'checkbox',
})
attrs.update(self.header_attrs)
- return mark_safe('<input %s/>' % attrs.as_html())
+ return mark_safe(u'<input %s/>' % attrs.as_html())
def render(self, value, bound_column):
attrs = AttributeDict({
'value': value
})
attrs.update(self.attrs)
- return mark_safe('<input %s/>' % attrs.as_html())
+ return mark_safe(u'<input %s/>' % attrs.as_html())
class LinkColumn(Column):
self.attrs = attrs or {}
def render(self, value, record, bound_column):
- params = {} # args for reverse()
+ # The following params + if statements create the arguments required to
+ # pass to Django's reverse() function.
+ params = {}
if self.viewname:
params['viewname'] = (self.viewname.resolve(record)
if isinstance(self.viewname, A)
if isinstance(value, A):
params['current_app'][key] = value.resolve(record)
url = reverse(**params)
- html = '<a href="{url}" {attrs}>{value}</a>'.format(
+ html = u'<a href="{url}" {attrs}>{value}</a>'.format(
url=reverse(**params),
attrs=AttributeDict(self.attrs).as_html(),
value=value
elif isinstance(index, basestring):
return self._columns[index]
else:
- raise TypeError('row indices must be integers or str, not %s' %
+ raise TypeError(u'row indices must be integers or str, not %s' %
index.__class__.__name__)
_, table_var_name = token.contents.split()
except ValueError:
raise (template.TemplateSyntaxError,
- '%r tag requires a single argument' % token.contents.split()[0])
+ u'%r tag requires a single argument'
+ % token.contents.split()[0])
return RenderTableNode(table_var_name)
:rtype: :class:`~django.utils.safestring.SafeUnicode` object
"""
- return mark_safe(' '.join(['%s="%s"' % (k, escape(v))
+ return mark_safe(' '.join([u'%s="%s"' % (k, escape(v))
for k, v in self.iteritems()]))
# built documents.
#
# The short X.Y version.
-version = '0.4.2'
+version = '0.4.3'
# The full version, including alpha/beta/rc tags.
-release = '0.4.2'
+release = '0.4.3'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
setup(
name='django-tables',
- version='0.4.2',
+ version='0.4.3',
description='Table framework for Django',
author='Bradley Ayers',
INSTALLED_APPS = [
'tests.testapp',
'django_tables',
- ]
+ ],
+ ROOT_URLCONF = 'tests.testapp.urls',
)
+# -*- coding: utf-8 -*-
"""Test the core table functionality."""
from attest import Tests, Assert
+from django.test.client import RequestFactory
+from django.template import Context, Template
import django_tables as tables
-from django_tables import utils
+from django_tables import utils, A
columns = Tests()
class SimpleTable(tables.Table):
name = tables.Column()
-
+
class Meta:
sortable = False
Assert(SimpleTable([]).columns['name'].sortable) is False
Assert(SimpleTable([]).columns['name'].sortable) is True
+@columns.test
+def link_column():
+ """Test LinkColumn"""
+ # test unicode values + headings
+ class UnicodeTable(tables.Table):
+ first_name = tables.LinkColumn('person', args=[A('pk')])
+ last_name = tables.LinkColumn('person', args=[A('pk')], verbose_name=u'äÚ¨´ˆÁ˜¨ˆ˜˘Ú…Ò˚ˆπ∆ˆ´')
+
+ dataset = [
+ {'pk': 1, 'first_name': u'Brädley', 'last_name': u'∆yers'},
+ {'pk': 2, 'first_name': u'Chr…s', 'last_name': u'DÒble'},
+ ]
+
+ table = UnicodeTable(dataset)
+ request = RequestFactory().get('/some-url/')
+ template = Template('{% load django_tables %}{% render_table table %}')
+ html = template.render(Context({'request': request, 'table': table}))
+
+ Assert(u'Brädley' in html)
+ Assert(u'∆yers' in html)
+ Assert(u'Chr…s' in html)
+ Assert(u'DÒble' in html)
+
+
--- /dev/null
+from django.conf.urls.defaults import patterns, include, url
+from . import views
+
+
+urlpatterns = patterns('',
+ url(r'^people/(\d+)/$', views.person, name='person'),
+ url(r'^occupations/(\d+)/$', views.occupation, name='occupation'),
+)
--- /dev/null
+from django.shortcuts import get_object_or_404
+from django.http import HttpResponse
+from .models import Person, Occupation
+
+
+def person(request, pk):
+ """A really simple view to provide an endpoint for the 'person' URL."""
+ person = get_object_or_404(Person, pk=pk)
+ return HttpResponse('Person: %s' % person)
+
+
+def occupation(request, pk):
+ """
+ Another really simple view to provide an endpoint for the 'occupation' URL.
+ """
+ occupation = get_object_or_404(Occupation, pk=pk)
+ return HttpResponse('Occupation: %s' % occupation)