prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Expand/improve document part of event endpoint
  <!--
  
  Please add the appropriate label for what change should be made:
  docs: changes to the documentation)
  refactor: refactoring production code, eg. renaming a variable or rewriting a function
  test: adding missing tests, refactoring tests; no production code change
  chore: updating poetry etc; no production code change
  
  -->
  
  ### Describe the change
  Change the current URL or add a URL to a link to the actual document (that is, one that ends with `/[name].pdf`).
  
  ### Motivation
  It's very nice for the app to be able to just fetch files directly.
  Also, I don't think the current URL is even necessary because you also have the PK with which you can create the URL.
  
  ### Current implementation
  There is a URL that leads to the file, but only after a redirect to `cdn`.
  
  </issue>
  <code>
  [start of website/documents/api/v2/serializers/document.py]
  1 from rest_framework.fields import SerializerMethodField
  2 from rest_framework.reverse import reverse
  3 
  4 from documents.models import Document
  5 from thaliawebsite.api.v2.serializers.cleaned_model_serializer import (
  6     CleanedModelSerializer,
  7 )
  8 
  9 
  10 class DocumentSerializer(CleanedModelSerializer):
  11     class Meta:
  12         model = Document
  13         fields = ("pk", "name", "url", "category", "members_only")
  14 
  15     url = SerializerMethodField("_url")
  16 
  17     def _url(self, instance):
  18         return self.context["request"].build_absolute_uri(
  19             reverse("documents:document", kwargs={"pk": instance.pk})
  20         )
  21
  [end of website/documents/api/v2/serializers/document.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/website/documents/api/v2/serializers/document.py b/website/documents/api/v2/serializers/document.py
  --- a/website/documents/api/v2/serializers/document.py
  +++ b/website/documents/api/v2/serializers/document.py
  @@ -1,10 +1,10 @@
   from rest_framework.fields import SerializerMethodField
  -from rest_framework.reverse import reverse
   
   from documents.models import Document
   from thaliawebsite.api.v2.serializers.cleaned_model_serializer import (
       CleanedModelSerializer,
   )
  +from utils.media.services import get_media_url
   
   
   class DocumentSerializer(CleanedModelSerializer):
  @@ -15,6 +15,12 @@
       url = SerializerMethodField("_url")
   
       def _url(self, instance):
  -        return self.context["request"].build_absolute_uri(
  -            reverse("documents:document", kwargs={"pk": instance.pk})
  -        )
  +        if instance.members_only and (
  +            not self.context["request"].user.is_authenticated
  +            or not self.context["request"].member.has_active_membership()
  +        ):
  +            return self.context["request"].build_absolute_uri(
  +                instance.get_absolute_url()
  +            )
  +
  +        return get_media_url(instance.file, absolute_url=True)
  
verification_info: {"golden_diff": "diff --git a/website/documents/api/v2/serializers/document.py b/website/documents/api/v2/serializers/document.py\n--- a/website/documents/api/v2/serializers/document.py\n+++ b/website/documents/api/v2/serializers/document.py\n@@ -1,10 +1,10 @@\n from rest_framework.fields import SerializerMethodField\n-from rest_framework.reverse import reverse\n \n from documents.models import Document\n from thaliawebsite.api.v2.serializers.cleaned_model_serializer import (\n     CleanedModelSerializer,\n )\n+from utils.media.services import get_media_url\n \n \n class DocumentSerializer(CleanedModelSerializer):\n@@ -15,6 +15,12 @@\n     url = SerializerMethodField(\"_url\")\n \n     def _url(self, instance):\n-        return self.context[\"request\"].build_absolute_uri(\n-            reverse(\"documents:document\", kwargs={\"pk\": instance.pk})\n-        )\n+        if instance.members_only and (\n+            not self.context[\"request\"].user.is_authenticated\n+            or not self.context[\"request\"].member.has_active_membership()\n+        ):\n+            return self.context[\"request\"].build_absolute_uri(\n+                instance.get_absolute_url()\n+            )\n+\n+        return get_media_url(instance.file, absolute_url=True)\n", "issue": "Expand/improve document part of event endpoint\n<!--\r\n\r\nPlease add the appropriate label for what change should be made:\r\ndocs: changes to the documentation)\r\nrefactor: refactoring production code, eg. renaming a variable or rewriting a function\r\ntest: adding missing tests, refactoring tests; no production code change\r\nchore: updating poetry etc; no production code change\r\n\r\n-->\r\n\r\n### Describe the change\r\nChange the current URL or add a URL to a link to the actual document (that is, one that ends with `/[name].pdf`).\r\n\r\n### Motivation\r\nIt's very nice for the app to be able to just fetch files directly.\r\nAlso, I don't think the current URL is even necessary because you also have the PK with which you can create the URL.\r\n\r\n### Current implementation\r\nThere is a URL that leads to the file, but only after a redirect to `cdn`.\n", "before_files": [{"content": "from rest_framework.fields import SerializerMethodField\nfrom rest_framework.reverse import reverse\n\nfrom documents.models import Document\nfrom thaliawebsite.api.v2.serializers.cleaned_model_serializer import (\n    CleanedModelSerializer,\n)\n\n\nclass DocumentSerializer(CleanedModelSerializer):\n    class Meta:\n        model = Document\n        fields = (\"pk\", \"name\", \"url\", \"category\", \"members_only\")\n\n    url = SerializerMethodField(\"_url\")\n\n    def _url(self, instance):\n        return self.context[\"request\"].build_absolute_uri(\n            reverse(\"documents:document\", kwargs={\"pk\": instance.pk})\n        )\n", "path": "website/documents/api/v2/serializers/document.py"}]}