prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Custom link in group does not render Jinja2 code
  <!--
      NOTE: This form is only for reproducible bugs. If you need assistance with
      NetBox installation, or if you have a general question, DO NOT open an
      issue. Instead, post to our mailing list:
  
          https://groups.google.com/forum/#!forum/netbox-discuss
  
      Please describe the environment in which you are running NetBox. Be sure
      that you are running an unmodified instance of the latest stable release
      before submitting a bug report.
  -->
  ### Environment
  * Python version:  3.6.8
  * NetBox version:  2.6.11
  
  <!--
      Describe in detail the exact steps that someone else can take to reproduce
      this bug using the current stable release of NetBox (or the current beta
      release where applicable). Begin with the creation of any necessary
      database objects and call out every operation being performed explicitly.
      If reporting a bug in the REST API, be sure to reconstruct the raw HTTP
      request(s) being made: Don't rely on a wrapper like pynetbox.
  -->
  ### Steps to Reproduce
  1. Create a custom link and add it to a group. Make the name use Jinja style code - example {% if True %} Custom Link 1{% endif %}
  2. Open a device and look at the custom link
  
  <!-- What did you expect to happen? -->
  ### Expected Behavior
  Expected the link to use the Jinja2 code and show "Custom Link 1" as name.
  
  <!-- What happened instead? -->
  ### Observed Behavior
  The Jinja code is shown as the name. So the name is "{% if True %} Custom Link 1{% endif %}" instead of "Custom Link 1". The link itself is also not rendering Jinja code.
  
  This seems to come from #3461 and due to the `text_rendered` and `link_rendered` not being used in the format statement on https://github.com/netbox-community/netbox/blob/b5455ed882c47273064933f0120b0e368af93a1f/netbox/extras/templatetags/custom_links.py#L72
  
  I did a quick check and changed 
  ```try:
                  text_rendered = render_jinja2(cl.text, context)
                  if text_rendered:
                      link_target = ' target="_blank"' if cl.new_window else ''
                      links_rendered.append(
                          GROUP_LINK.format(cl.url, link_target, cl.text)
                      )
  ```
  to
  
  ```try:
                  text_rendered = render_jinja2(cl.text, context)
                  if text_rendered:
                      link_target = ' target="_blank"' if cl.new_window else ''
                      link_rendered = render_jinja2(cl.url, context)
                      links_rendered.append(
                          GROUP_LINK.format(link_rendered, link_target, text_rendered)
                      )
  ```
  
  This made it work as expected again.
  
  </issue>
  <code>
  [start of netbox/extras/templatetags/custom_links.py]
  1 from collections import OrderedDict
  2 
  3 from django import template
  4 from django.contrib.contenttypes.models import ContentType
  5 from django.utils.safestring import mark_safe
  6 
  7 from extras.models import CustomLink
  8 from utilities.utils import render_jinja2
  9 
  10 
  11 register = template.Library()
  12 
  13 LINK_BUTTON = '<a href="{}"{} class="btn btn-sm btn-{}">{}</a>\n'
  14 GROUP_BUTTON = '<div class="btn-group">\n' \
  15                '<button type="button" class="btn btn-sm btn-{} dropdown-toggle" data-toggle="dropdown">\n' \
  16                '{} <span class="caret"></span>\n' \
  17                '</button>\n' \
  18                '<ul class="dropdown-menu pull-right">\n' \
  19                '{}</ul></div>'
  20 GROUP_LINK = '<li><a href="{}"{}>{}</a></li>\n'
  21 
  22 
  23 @register.simple_tag()
  24 def custom_links(obj):
  25     """
  26     Render all applicable links for the given object.
  27     """
  28     content_type = ContentType.objects.get_for_model(obj)
  29     custom_links = CustomLink.objects.filter(content_type=content_type)
  30     if not custom_links:
  31         return ''
  32 
  33     context = {
  34         'obj': obj,
  35     }
  36     template_code = ''
  37     group_names = OrderedDict()
  38 
  39     for cl in custom_links:
  40 
  41         # Organize custom links by group
  42         if cl.group_name and cl.group_name in group_names:
  43             group_names[cl.group_name].append(cl)
  44         elif cl.group_name:
  45             group_names[cl.group_name] = [cl]
  46 
  47         # Add non-grouped links
  48         else:
  49             try:
  50                 text_rendered = render_jinja2(cl.text, context)
  51                 if text_rendered:
  52                     link_rendered = render_jinja2(cl.url, context)
  53                     link_target = ' target="_blank"' if cl.new_window else ''
  54                     template_code += LINK_BUTTON.format(
  55                         link_rendered, link_target, cl.button_class, text_rendered
  56                     )
  57             except Exception as e:
  58                 template_code += '<a class="btn btn-sm btn-default" disabled="disabled" title="{}">' \
  59                                  '<i class="fa fa-warning"></i> {}</a>\n'.format(e, cl.name)
  60 
  61     # Add grouped links to template
  62     for group, links in group_names.items():
  63 
  64         links_rendered = []
  65 
  66         for cl in links:
  67             try:
  68                 text_rendered = render_jinja2(cl.text, context)
  69                 if text_rendered:
  70                     link_target = ' target="_blank"' if cl.new_window else ''
  71                     links_rendered.append(
  72                         GROUP_LINK.format(cl.url, link_target, cl.text)
  73                     )
  74             except Exception as e:
  75                 links_rendered.append(
  76                     '<li><a disabled="disabled" title="{}"><span class="text-muted">'
  77                     '<i class="fa fa-warning"></i> {}</span></a></li>'.format(e, cl.name)
  78                 )
  79 
  80         if links_rendered:
  81             template_code += GROUP_BUTTON.format(
  82                 links[0].button_class, group, ''.join(links_rendered)
  83             )
  84 
  85     return mark_safe(template_code)
  86
  [end of netbox/extras/templatetags/custom_links.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/netbox/extras/templatetags/custom_links.py b/netbox/extras/templatetags/custom_links.py
  --- a/netbox/extras/templatetags/custom_links.py
  +++ b/netbox/extras/templatetags/custom_links.py
  @@ -68,8 +68,9 @@
                   text_rendered = render_jinja2(cl.text, context)
                   if text_rendered:
                       link_target = ' target="_blank"' if cl.new_window else ''
  +                    link_rendered = render_jinja2(cl.url, context)
                       links_rendered.append(
  -                        GROUP_LINK.format(cl.url, link_target, cl.text)
  +                        GROUP_LINK.format(link_rendered, link_target, text_rendered)
                       )
               except Exception as e:
                   links_rendered.append(
  
verification_info: {"golden_diff": "diff --git a/netbox/extras/templatetags/custom_links.py b/netbox/extras/templatetags/custom_links.py\n--- a/netbox/extras/templatetags/custom_links.py\n+++ b/netbox/extras/templatetags/custom_links.py\n@@ -68,8 +68,9 @@\n                 text_rendered = render_jinja2(cl.text, context)\n                 if text_rendered:\n                     link_target = ' target=\"_blank\"' if cl.new_window else ''\n+                    link_rendered = render_jinja2(cl.url, context)\n                     links_rendered.append(\n-                        GROUP_LINK.format(cl.url, link_target, cl.text)\n+                        GROUP_LINK.format(link_rendered, link_target, text_rendered)\n                     )\n             except Exception as e:\n                 links_rendered.append(\n", "issue": "Custom link in group does not render Jinja2 code\n<!--\r\n    NOTE: This form is only for reproducible bugs. If you need assistance with\r\n    NetBox installation, or if you have a general question, DO NOT open an\r\n    issue. Instead, post to our mailing list:\r\n\r\n        https://groups.google.com/forum/#!forum/netbox-discuss\r\n\r\n    Please describe the environment in which you are running NetBox. Be sure\r\n    that you are running an unmodified instance of the latest stable release\r\n    before submitting a bug report.\r\n-->\r\n### Environment\r\n* Python version:  3.6.8\r\n* NetBox version:  2.6.11\r\n\r\n<!--\r\n    Describe in detail the exact steps that someone else can take to reproduce\r\n    this bug using the current stable release of NetBox (or the current beta\r\n    release where applicable). Begin with the creation of any necessary\r\n    database objects and call out every operation being performed explicitly.\r\n    If reporting a bug in the REST API, be sure to reconstruct the raw HTTP\r\n    request(s) being made: Don't rely on a wrapper like pynetbox.\r\n-->\r\n### Steps to Reproduce\r\n1. Create a custom link and add it to a group. Make the name use Jinja style code - example {% if True %} Custom Link 1{% endif %}\r\n2. Open a device and look at the custom link\r\n\r\n<!-- What did you expect to happen? -->\r\n### Expected Behavior\r\nExpected the link to use the Jinja2 code and show \"Custom Link 1\" as name.\r\n\r\n<!-- What happened instead? -->\r\n### Observed Behavior\r\nThe Jinja code is shown as the name. So the name is \"{% if True %} Custom Link 1{% endif %}\" instead of \"Custom Link 1\". The link itself is also not rendering Jinja code.\r\n\r\nThis seems to come from #3461 and due to the `text_rendered` and `link_rendered` not being used in the format statement on https://github.com/netbox-community/netbox/blob/b5455ed882c47273064933f0120b0e368af93a1f/netbox/extras/templatetags/custom_links.py#L72\r\n\r\nI did a quick check and changed \r\n```try:\r\n                text_rendered = render_jinja2(cl.text, context)\r\n                if text_rendered:\r\n                    link_target = ' target=\"_blank\"' if cl.new_window else ''\r\n                    links_rendered.append(\r\n                        GROUP_LINK.format(cl.url, link_target, cl.text)\r\n                    )\r\n```\r\nto\r\n\r\n```try:\r\n                text_rendered = render_jinja2(cl.text, context)\r\n                if text_rendered:\r\n                    link_target = ' target=\"_blank\"' if cl.new_window else ''\r\n                    link_rendered = render_jinja2(cl.url, context)\r\n                    links_rendered.append(\r\n                        GROUP_LINK.format(link_rendered, link_target, text_rendered)\r\n                    )\r\n```\r\n\r\nThis made it work as expected again.\n", "before_files": [{"content": "from collections import OrderedDict\n\nfrom django import template\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.utils.safestring import mark_safe\n\nfrom extras.models import CustomLink\nfrom utilities.utils import render_jinja2\n\n\nregister = template.Library()\n\nLINK_BUTTON = '<a href=\"{}\"{} class=\"btn btn-sm btn-{}\">{}</a>\\n'\nGROUP_BUTTON = '<div class=\"btn-group\">\\n' \\\n               '<button type=\"button\" class=\"btn btn-sm btn-{} dropdown-toggle\" data-toggle=\"dropdown\">\\n' \\\n               '{} <span class=\"caret\"></span>\\n' \\\n               '</button>\\n' \\\n               '<ul class=\"dropdown-menu pull-right\">\\n' \\\n               '{}</ul></div>'\nGROUP_LINK = '<li><a href=\"{}\"{}>{}</a></li>\\n'\n\n\n@register.simple_tag()\ndef custom_links(obj):\n    \"\"\"\n    Render all applicable links for the given object.\n    \"\"\"\n    content_type = ContentType.objects.get_for_model(obj)\n    custom_links = CustomLink.objects.filter(content_type=content_type)\n    if not custom_links:\n        return ''\n\n    context = {\n        'obj': obj,\n    }\n    template_code = ''\n    group_names = OrderedDict()\n\n    for cl in custom_links:\n\n        # Organize custom links by group\n        if cl.group_name and cl.group_name in group_names:\n            group_names[cl.group_name].append(cl)\n        elif cl.group_name:\n            group_names[cl.group_name] = [cl]\n\n        # Add non-grouped links\n        else:\n            try:\n                text_rendered = render_jinja2(cl.text, context)\n                if text_rendered:\n                    link_rendered = render_jinja2(cl.url, context)\n                    link_target = ' target=\"_blank\"' if cl.new_window else ''\n                    template_code += LINK_BUTTON.format(\n                        link_rendered, link_target, cl.button_class, text_rendered\n                    )\n            except Exception as e:\n                template_code += '<a class=\"btn btn-sm btn-default\" disabled=\"disabled\" title=\"{}\">' \\\n                                 '<i class=\"fa fa-warning\"></i> {}</a>\\n'.format(e, cl.name)\n\n    # Add grouped links to template\n    for group, links in group_names.items():\n\n        links_rendered = []\n\n        for cl in links:\n            try:\n                text_rendered = render_jinja2(cl.text, context)\n                if text_rendered:\n                    link_target = ' target=\"_blank\"' if cl.new_window else ''\n                    links_rendered.append(\n                        GROUP_LINK.format(cl.url, link_target, cl.text)\n                    )\n            except Exception as e:\n                links_rendered.append(\n                    '<li><a disabled=\"disabled\" title=\"{}\"><span class=\"text-muted\">'\n                    '<i class=\"fa fa-warning\"></i> {}</span></a></li>'.format(e, cl.name)\n                )\n\n        if links_rendered:\n            template_code += GROUP_BUTTON.format(\n                links[0].button_class, group, ''.join(links_rendered)\n            )\n\n    return mark_safe(template_code)\n", "path": "netbox/extras/templatetags/custom_links.py"}]}