prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  La licence est absente lors de la visualisation d'une partie du tutoriel
  Quand on navigue partout dans un tutoriel, on a normalement la licence de celui en haut à droite. Sauf lorsqu'on regarde une partie ([celle-ci](http://beta.zestedesavoir.com/tutoriels/335/creez-des-applications-pour-android/425/annexes/) par exemple).
  
  
  </issue>
  <code>
  [start of zds/utils/templatetags/topbar.py]
  1 # coding: utf-8
  2 
  3 from collections import OrderedDict
  4 from django import template
  5 from django.conf import settings
  6 import itertools
  7 from zds.forum.models import Forum, Topic
  8 from zds.tutorial.models import Tutorial
  9 from zds.utils.models import CategorySubCategory, Tag
  10 
  11 
  12 register = template.Library()
  13 
  14 
  15 @register.filter('top_categories')
  16 def top_categories(user):
  17     cats = {}
  18 
  19     forums_pub = Forum.objects.filter(group__isnull=True).select_related("category").all()
  20     if user and user.is_authenticated():
  21         forums_prv = Forum\
  22             .objects\
  23             .filter(group__isnull=False, group__in=user.groups.all())\
  24             .select_related("category").all()
  25         forums = list(forums_pub | forums_prv)
  26     else:
  27         forums = list(forums_pub)
  28 
  29     for forum in forums:
  30         key = forum.category.title
  31         if key in cats:
  32             cats[key].append(forum)
  33         else:
  34             cats[key] = [forum]
  35 
  36     tgs = Topic.objects\
  37         .values('tags', 'pk')\
  38         .distinct()\
  39         .filter(forum__in=forums, tags__isnull=False)
  40 
  41     cts = {}
  42     for key, group in itertools.groupby(tgs, lambda item: item["tags"]):
  43         for thing in group:
  44             if key in cts:
  45                 cts[key] += 1
  46             else:
  47                 cts[key] = 1
  48 
  49     cpt = 0
  50     top_tag = []
  51     sort_list = reversed(sorted(cts.iteritems(), key=lambda k_v: (k_v[1], k_v[0])))
  52     for key, value in sort_list:
  53         top_tag.append(key)
  54         cpt += 1
  55         if cpt >= settings.ZDS_APP['forum']['top_tag_max']:
  56             break
  57 
  58     tags = Tag.objects.filter(pk__in=top_tag)
  59 
  60     return {"tags": tags, "categories": cats}
  61 
  62 
  63 @register.filter('top_categories_tuto')
  64 def top_categories_tuto(user):
  65     """
  66         Get all the categories and their related subcategories
  67         associed with an existing tutorial. The result is sorted
  68         by alphabetic order.
  69     """
  70 
  71     # Ordered dict is use to keep order
  72     cats = OrderedDict()
  73 
  74     subcats_tutos = Tutorial.objects.values('subcategory').filter(sha_public__isnull=False).all()
  75     catsubcats = CategorySubCategory.objects \
  76         .filter(is_main=True)\
  77         .filter(subcategory__in=subcats_tutos)\
  78         .order_by('category__position', 'subcategory__title')\
  79         .select_related('subcategory', 'category')\
  80         .values('category__title', 'subcategory__title', 'subcategory__slug')\
  81         .all()
  82 
  83     for csc in catsubcats:
  84         key = csc['category__title']
  85 
  86         if key in cats:
  87             cats[key].append((csc['subcategory__title'], csc['subcategory__slug']))
  88         else:
  89             cats[key] = [(csc['subcategory__title'], csc['subcategory__slug'])]
  90 
  91     return cats
  92 
  93 
  94 @register.filter('auth_forum')
  95 def auth_forum(forum, user):
  96     return forum.can_read(user)
  97
  [end of zds/utils/templatetags/topbar.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/zds/utils/templatetags/topbar.py b/zds/utils/templatetags/topbar.py
  --- a/zds/utils/templatetags/topbar.py
  +++ b/zds/utils/templatetags/topbar.py
  @@ -1,9 +1,12 @@
   # coding: utf-8
   
   from collections import OrderedDict
  +import itertools
  +
   from django import template
   from django.conf import settings
  -import itertools
  +
  +from zds.article.models import Article
   from zds.forum.models import Forum, Topic
   from zds.tutorial.models import Tutorial
   from zds.utils.models import CategorySubCategory, Tag
  @@ -91,6 +94,37 @@
       return cats
   
   
  +@register.filter('top_categories_article')
  +def top_categories_article(user):
  +    """
  +        Get all the categories and their related subcategories
  +        associed with an existing articles. The result is sorted
  +        by alphabetic order.
  +    """
  +
  +    # Ordered dict is use to keep order
  +    cats = OrderedDict()
  +
  +    subcats_articles = Article.objects.values('subcategory').filter(sha_public__isnull=False).all()
  +    catsubcats = CategorySubCategory.objects \
  +        .filter(is_main=True)\
  +        .filter(subcategory__in=subcats_articles)\
  +        .order_by('category__position', 'subcategory__title')\
  +        .select_related('subcategory', 'category')\
  +        .values('category__title', 'subcategory__title', 'subcategory__slug')\
  +        .all()
  +
  +    for csc in catsubcats:
  +        key = csc['category__title']
  +
  +        if key in cats:
  +            cats[key].append((csc['subcategory__title'], csc['subcategory__slug']))
  +        else:
  +            cats[key] = [(csc['subcategory__title'], csc['subcategory__slug'])]
  +
  +    return cats
  +
  +
   @register.filter('auth_forum')
   def auth_forum(forum, user):
       return forum.can_read(user)
  
verification_info: {"golden_diff": "diff --git a/zds/utils/templatetags/topbar.py b/zds/utils/templatetags/topbar.py\n--- a/zds/utils/templatetags/topbar.py\n+++ b/zds/utils/templatetags/topbar.py\n@@ -1,9 +1,12 @@\n # coding: utf-8\n \n from collections import OrderedDict\n+import itertools\n+\n from django import template\n from django.conf import settings\n-import itertools\n+\n+from zds.article.models import Article\n from zds.forum.models import Forum, Topic\n from zds.tutorial.models import Tutorial\n from zds.utils.models import CategorySubCategory, Tag\n@@ -91,6 +94,37 @@\n     return cats\n \n \n+@register.filter('top_categories_article')\n+def top_categories_article(user):\n+    \"\"\"\n+        Get all the categories and their related subcategories\n+        associed with an existing articles. The result is sorted\n+        by alphabetic order.\n+    \"\"\"\n+\n+    # Ordered dict is use to keep order\n+    cats = OrderedDict()\n+\n+    subcats_articles = Article.objects.values('subcategory').filter(sha_public__isnull=False).all()\n+    catsubcats = CategorySubCategory.objects \\\n+        .filter(is_main=True)\\\n+        .filter(subcategory__in=subcats_articles)\\\n+        .order_by('category__position', 'subcategory__title')\\\n+        .select_related('subcategory', 'category')\\\n+        .values('category__title', 'subcategory__title', 'subcategory__slug')\\\n+        .all()\n+\n+    for csc in catsubcats:\n+        key = csc['category__title']\n+\n+        if key in cats:\n+            cats[key].append((csc['subcategory__title'], csc['subcategory__slug']))\n+        else:\n+            cats[key] = [(csc['subcategory__title'], csc['subcategory__slug'])]\n+\n+    return cats\n+\n+\n @register.filter('auth_forum')\n def auth_forum(forum, user):\n     return forum.can_read(user)\n", "issue": "La licence est absente lors de la visualisation d'une partie du tutoriel\nQuand on navigue partout dans un tutoriel, on a normalement la licence de celui en haut \u00e0 droite. Sauf lorsqu'on regarde une partie ([celle-ci](http://beta.zestedesavoir.com/tutoriels/335/creez-des-applications-pour-android/425/annexes/) par exemple).\n\n", "before_files": [{"content": "# coding: utf-8\n\nfrom collections import OrderedDict\nfrom django import template\nfrom django.conf import settings\nimport itertools\nfrom zds.forum.models import Forum, Topic\nfrom zds.tutorial.models import Tutorial\nfrom zds.utils.models import CategorySubCategory, Tag\n\n\nregister = template.Library()\n\n\n@register.filter('top_categories')\ndef top_categories(user):\n    cats = {}\n\n    forums_pub = Forum.objects.filter(group__isnull=True).select_related(\"category\").all()\n    if user and user.is_authenticated():\n        forums_prv = Forum\\\n            .objects\\\n            .filter(group__isnull=False, group__in=user.groups.all())\\\n            .select_related(\"category\").all()\n        forums = list(forums_pub | forums_prv)\n    else:\n        forums = list(forums_pub)\n\n    for forum in forums:\n        key = forum.category.title\n        if key in cats:\n            cats[key].append(forum)\n        else:\n            cats[key] = [forum]\n\n    tgs = Topic.objects\\\n        .values('tags', 'pk')\\\n        .distinct()\\\n        .filter(forum__in=forums, tags__isnull=False)\n\n    cts = {}\n    for key, group in itertools.groupby(tgs, lambda item: item[\"tags\"]):\n        for thing in group:\n            if key in cts:\n                cts[key] += 1\n            else:\n                cts[key] = 1\n\n    cpt = 0\n    top_tag = []\n    sort_list = reversed(sorted(cts.iteritems(), key=lambda k_v: (k_v[1], k_v[0])))\n    for key, value in sort_list:\n        top_tag.append(key)\n        cpt += 1\n        if cpt >= settings.ZDS_APP['forum']['top_tag_max']:\n            break\n\n    tags = Tag.objects.filter(pk__in=top_tag)\n\n    return {\"tags\": tags, \"categories\": cats}\n\n\n@register.filter('top_categories_tuto')\ndef top_categories_tuto(user):\n    \"\"\"\n        Get all the categories and their related subcategories\n        associed with an existing tutorial. The result is sorted\n        by alphabetic order.\n    \"\"\"\n\n    # Ordered dict is use to keep order\n    cats = OrderedDict()\n\n    subcats_tutos = Tutorial.objects.values('subcategory').filter(sha_public__isnull=False).all()\n    catsubcats = CategorySubCategory.objects \\\n        .filter(is_main=True)\\\n        .filter(subcategory__in=subcats_tutos)\\\n        .order_by('category__position', 'subcategory__title')\\\n        .select_related('subcategory', 'category')\\\n        .values('category__title', 'subcategory__title', 'subcategory__slug')\\\n        .all()\n\n    for csc in catsubcats:\n        key = csc['category__title']\n\n        if key in cats:\n            cats[key].append((csc['subcategory__title'], csc['subcategory__slug']))\n        else:\n            cats[key] = [(csc['subcategory__title'], csc['subcategory__slug'])]\n\n    return cats\n\n\n@register.filter('auth_forum')\ndef auth_forum(forum, user):\n    return forum.can_read(user)\n", "path": "zds/utils/templatetags/topbar.py"}]}