Opened 7 years ago
Closed 7 years ago
#29432 closed Cleanup/optimization (fixed)
Allow passing an integer to the slice template filter
| Reported by: | Maxim Danilov | Owned by: | nobody |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
or it should be:
def slice_filter(value, arg):
arg = '%s' % arg
.......
thats helped to use slice filter in loops with forloop.counter together.
Change History (4)
comment:1 by , 7 years ago
| Summary: | templatefilter slice needs @stringfilter decorator. → templatefilter slice needs @stringfilter decorator for 'arg' variable. |
|---|
comment:2 by , 7 years ago
comment:3 by , 7 years ago
| Has patch: | set |
|---|---|
| Keywords: | templatefilter removed |
| Summary: | templatefilter slice needs @stringfilter decorator for 'arg' variable. → Allow passing an integer to the slice template filter |
| Triage Stage: | Unreviewed → Ready for checkin |
| Type: | Bug → Cleanup/optimization |
| Version: | → master |
Note:
See TracTickets
for help on using tickets.
Can you give the example code for the use case? Adding
@stringfilterresults in a test failure:====================================================================== FAIL: test_fail_silently (template_tests.filter_tests.test_slice.FunctionTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/opt/python3.6.4/lib/python3.6/unittest/case.py", line 59, in testPartExecutor yield File "/opt/python3.6.4/lib/python3.6/unittest/case.py", line 605, in run testMethod() File "/home/tim/code/django/tests/template_tests/filter_tests/test_slice.py", line 43, in test_fail_silently self.assertEqual(slice_filter(obj, '0::2'), obj) File "/opt/python3.6.4/lib/python3.6/unittest/case.py", line 829, in assertEqual assertion_func(first, second, msg=msg) File "/opt/python3.6.4/lib/python3.6/unittest/case.py", line 822, in _baseAssertEqual raise self.failureException(msg) AssertionError: '<betojc t07be774>' != <object object at 0x7fb7ea737b40>