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 Maxim Danilov, 7 years ago

Summary: templatefilter slice needs @stringfilter decorator.templatefilter slice needs @stringfilter decorator for 'arg' variable.

comment:2 by Tim Graham, 7 years ago

Can you give the example code for the use case? Adding @stringfilter results 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>

comment:3 by Tim Graham, 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: UnreviewedReady for checkin
Type: BugCleanup/optimization
Version: master

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: newclosed

In b4fd9b5a:

Fixed #29432 -- Allowed passing an integer to the slice template filter.

Note: See TracTickets for help on using tickets.
Back to Top