prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  On Century Detail pages, sometimes unpublished sources are listed
  Visiting century/3863 while not logged in, there's a link to source/672452. When I click on it, I get a 403 Access Denied error. We need to ensure that links to sources that are inaccessible to a user are never displayed.
  
  This bug occurs on both staging and production.
  
  </issue>
  <code>
  [start of django/cantusdb_project/main_app/views/century.py]
  1 from django.views.generic import DetailView
  2 from main_app.models import Century
  3 
  4 class CenturyDetailView(DetailView):
  5     model = Century
  6     context_object_name = "century"
  7     template_name = "century_detail.html"
  8
  [end of django/cantusdb_project/main_app/views/century.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/django/cantusdb_project/main_app/views/century.py b/django/cantusdb_project/main_app/views/century.py
  --- a/django/cantusdb_project/main_app/views/century.py
  +++ b/django/cantusdb_project/main_app/views/century.py
  @@ -1,7 +1,20 @@
   from django.views.generic import DetailView
  -from main_app.models import Century
  +from main_app.models import Century, Source
  +from typing import Any
   
   class CenturyDetailView(DetailView):
       model = Century
       context_object_name = "century"
       template_name = "century_detail.html"
  +
  +    def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
  +        context = super().get_context_data(**kwargs)
  +        century = self.get_object()
  +        user = self.request.user
  +        display_unpublished = user.is_authenticated
  +        sources = Source.objects.filter(century=century)
  +        if not display_unpublished:
  +            sources = sources.filter(published=True)
  +        sources=sources.only("title", "id")
  +        context["sources"] = sources
  +        return context
  \ No newline at end of file
  
verification_info: {"golden_diff": "diff --git a/django/cantusdb_project/main_app/views/century.py b/django/cantusdb_project/main_app/views/century.py\n--- a/django/cantusdb_project/main_app/views/century.py\n+++ b/django/cantusdb_project/main_app/views/century.py\n@@ -1,7 +1,20 @@\n from django.views.generic import DetailView\n-from main_app.models import Century\n+from main_app.models import Century, Source\n+from typing import Any\n \n class CenturyDetailView(DetailView):\n     model = Century\n     context_object_name = \"century\"\n     template_name = \"century_detail.html\"\n+\n+    def get_context_data(self, **kwargs: Any) -> dict[str, Any]:\n+        context = super().get_context_data(**kwargs)\n+        century = self.get_object()\n+        user = self.request.user\n+        display_unpublished = user.is_authenticated\n+        sources = Source.objects.filter(century=century)\n+        if not display_unpublished:\n+            sources = sources.filter(published=True)\n+        sources=sources.only(\"title\", \"id\")\n+        context[\"sources\"] = sources\n+        return context\n\\ No newline at end of file\n", "issue": "On Century Detail pages, sometimes unpublished sources are listed\nVisiting century/3863 while not logged in, there's a link to source/672452. When I click on it, I get a 403 Access Denied error. We need to ensure that links to sources that are inaccessible to a user are never displayed.\r\n\r\nThis bug occurs on both staging and production.\n", "before_files": [{"content": "from django.views.generic import DetailView\nfrom main_app.models import Century\n\nclass CenturyDetailView(DetailView):\n    model = Century\n    context_object_name = \"century\"\n    template_name = \"century_detail.html\"\n", "path": "django/cantusdb_project/main_app/views/century.py"}]}