def vslice(value: List, var: int) -> List:
    """
    Filter used to dynamically :tag:`slice` a list.

    :param value: The original list.
    :param var: The end of the slice.

    :return: The sliced list.
    """
    return slice_filter(value, f':{var:d}')
Example #2
0
 def test_slice(self):
     self.assertEqual(slice_filter('abcdefg', '0'), '')
     self.assertEqual(slice_filter('abcdefg', '1'), 'a')
     self.assertEqual(slice_filter('abcdefg', '-1'), 'abcdef')
     self.assertEqual(slice_filter('abcdefg', '1:2'), 'b')
     self.assertEqual(slice_filter('abcdefg', '1:3'), 'bc')
     self.assertEqual(slice_filter('abcdefg', '0::2'), 'aceg')
Example #3
0
 def test_slice(self):
     self.assertEqual(slice_filter('abcdefg', '0'), '')
     self.assertEqual(slice_filter('abcdefg', '1'), 'a')
     self.assertEqual(slice_filter('abcdefg', '-1'), 'abcdef')
     self.assertEqual(slice_filter('abcdefg', '1:2'), 'b')
     self.assertEqual(slice_filter('abcdefg', '1:3'), 'bc')
     self.assertEqual(slice_filter('abcdefg', '0::2'), 'aceg')
def interlinks_for(item, slice=None):
    links = Link.objects.outgoing(item)
    if slice:
        links = slice_filter(links, slice)
    rendered_links = []
    for link in links:
        page = link.keyword.content_object
        if page:
            tpl = select_template([
                'interlink/%s/link.html' % page._meta.app_label,
                'interlink/%s/%s_link.html' %
                (page._meta.app_label, page._meta.model_name),
                'interlink/link.html',
            ])
            context = template.Context(dict(link=link))
            rendered_links.append(tpl.render(context))
    if not rendered_links:
        return ''
    return render_to_string('interlink/links_list.html',
                            dict(links=rendered_links))
Example #5
0
 def test_range_multiple(self):
     self.assertEqual(slice_filter('abcdefg', '1:3'), 'bc')
Example #6
0
 def test_negative_index(self):
     self.assertEqual(slice_filter('abcdefg', '-1'), 'abcdef')
Example #7
0
 def test_zero_length(self):
     self.assertEqual(slice_filter('abcdefg', '0'), '')
Example #8
0
 def test_fail_silently(self):
     obj = object()
     self.assertEqual(slice_filter(obj, "0::2"), obj)
Example #9
0
 def test_range_multiple(self):
     self.assertEqual(slice_filter("abcdefg", "1:3"), "bc")
Example #10
0
 def test_negative_index(self):
     self.assertEqual(slice_filter("abcdefg", "-1"), "abcdef")
Example #11
0
 def test_zero_length(self):
     self.assertEqual(slice_filter('abcdefg', '0'), '')
Example #12
0
 def ref_number(self):
     return slice_filter(self.type.type, ':3').upper() + '-' + "%03d" % self.id
Example #13
0
def slicelines(txt, arg):
    """Like django's slice template tag but converts the (text) argument
    to a list of lines first."""
    return '\n'.join(slice_filter(txt.split('\n'), arg))
Example #14
0
def context_length(value, _slice):
    if len(value) > _slice:
        value = slice_filter(value, _slice) + " ..."
        return value

    return value
Example #15
0
 def test_fail_silently(self):
     obj = object()
     self.assertEqual(slice_filter(obj, '0::2'), obj)
Example #16
0
 def test_index_integer(self):
     self.assertEqual(slice_filter('abcdefg', 1), 'a')
Example #17
0
 def test_index_integer(self):
     self.assertEqual(slice_filter("abcdefg", 1), "a")
Example #18
0
 def test_index(self):
     self.assertEqual(slice_filter('abcdefg', '1'), 'a')
Example #19
0
 def test_range(self):
     self.assertEqual(slice_filter("abcdefg", "1:2"), "b")
Example #20
0
 def test_index_integer(self):
     self.assertEqual(slice_filter('abcdefg', 1), 'a')
Example #21
0
 def test_range_step(self):
     self.assertEqual(slice_filter("abcdefg", "0::2"), "aceg")
Example #22
0
 def test_negative_index(self):
     self.assertEqual(slice_filter('abcdefg', '-1'), 'abcdef')
Example #23
0
def vslice(value, var):
    return slice_filter(value, ':%d' % var)
Example #24
0
 def test_range(self):
     self.assertEqual(slice_filter('abcdefg', '1:2'), 'b')
Example #25
0
 def test_index(self):
     self.assertEqual(slice_filter('abcdefg', '1'), 'a')
Example #26
0
 def test_range_multiple(self):
     self.assertEqual(slice_filter('abcdefg', '1:3'), 'bc')
Example #27
0
 def test_range(self):
     self.assertEqual(slice_filter('abcdefg', '1:2'), 'b')
Example #28
0
 def test_range_step(self):
     self.assertEqual(slice_filter('abcdefg', '0::2'), 'aceg')
Example #29
0
 def test_range_step(self):
     self.assertEqual(slice_filter('abcdefg', '0::2'), 'aceg')
Example #30
0
 def test_zero_length(self):
     self.assertEqual(slice_filter("abcdefg", "0"), "")
Example #31
0
 def test_index(self):
     self.assertEqual(slice_filter("abcdefg", "1"), "a")
Example #32
0
    def item_description(self, item):
        return slice_filter(item.body, '50')

    # def item_link(self, item):
    #     return item.get_absolute_url()