2
2
from __future__ import absolute_import , unicode_literals
3
3
from django .db .models .fields import FieldDoesNotExist
4
4
from django .utils .datastructures import SortedDict
5
- from django .utils .safestring import SafeData
6
5
from django_tables2 .templatetags .django_tables2 import title
7
6
from django_tables2 .utils import A , AttributeDict , OrderBy , OrderByTuple
8
7
from itertools import islice
@@ -116,9 +115,6 @@ class Column(object): # pylint: disable=R0902
116
115
117
116
:type: `unicode`
118
117
119
- This should not defined in title case, but rather natural case. It is
120
- converted to title case for use in column headers.
121
-
122
118
123
119
.. attribute:: visible
124
120
@@ -188,9 +184,7 @@ def header(self):
188
184
"""
189
185
The value used for the column heading (e.g. inside the ``<th>`` tag).
190
186
191
- By default this titlises the `~.Column.verbose_name`. If
192
- `~.Column.verbose_name` is an instance of `~.safestring.SafeData`, it's
193
- used unmodified.
187
+ By default this returns `~.Column.verbose_name`.
194
188
195
189
:returns: `unicode` or `None`
196
190
@@ -203,12 +197,7 @@ def header(self):
203
197
accessing that first) when this property doesn't return something
204
198
useful.
205
199
"""
206
- if self .verbose_name :
207
- if isinstance (self .verbose_name , SafeData ):
208
- # If the author has used mark_safe, we're going to assume the
209
- # author wants the value used verbatim.
210
- return self .verbose_name
211
- return title (self .verbose_name )
200
+ return self .verbose_name
212
201
213
202
def render (self , value ):
214
203
"""
@@ -350,13 +339,7 @@ def header(self):
350
339
if column_header :
351
340
return column_header
352
341
# fall back to automatic best guess
353
- verbose_name = self .verbose_name # avoid calculating multiple times
354
- if isinstance (verbose_name , SafeData ):
355
- # If the verbose_name has come from a model field, it's possible
356
- # that the author used mark_safe to include HTML in the value. If
357
- # this is the case, we leave it verbatim.
358
- return verbose_name
359
- return title (verbose_name )
342
+ return self .verbose_name
360
343
361
344
@property
362
345
def order_by (self ):
@@ -453,25 +436,22 @@ def orderable(self):
453
436
@property
454
437
def verbose_name (self ):
455
438
"""
456
- Return the verbose name for this column, or fallback to prettified
439
+ Return the verbose name for this column, or fallback to the titlised
457
440
column name.
458
441
459
442
If the table is using queryset data, then use the corresponding model
460
443
field's `~.db.Field.verbose_name`. If it's traversing a relationship,
461
444
then get the last field in the accessor (i.e. stop when the
462
445
relationship turns from ORM relationships to object attributes [e.g.
463
446
person.upper should stop at person]).
464
-
465
- If the model field's `~.db.Field.verbose_name` is a
466
- `~.safestring.SafeData`, it's used unmodified.
467
447
"""
468
448
# Favor an explicit defined verbose_name
469
449
if self .column .verbose_name :
470
450
return self .column .verbose_name
471
451
472
452
# This is our reasonable fallback, should the next section not result
473
453
# in anything useful.
474
- name = self .name .replace ('_' , ' ' )
454
+ name = title ( self .name .replace ('_' , ' ' ) )
475
455
476
456
# Try to use a tmodel field's verbose_name
477
457
if hasattr (self .table .data , 'queryset' ):
0 commit comments