prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  in text commenting links to first chapter lead back to the project view
  ...so I am back to the timeline and the tiles
  
  There are two links doing that: "back to chapter" in paragraph detail view and "previous chapter" in second chapter.
  
  </issue>
  <code>
  [start of meinberlin/apps/documents/views.py]
  1 from django.http import Http404
  2 from django.urls import reverse
  3 from django.utils.translation import ugettext_lazy as _
  4 from django.views import generic
  5 
  6 from adhocracy4.dashboard import mixins as dashboard_mixins
  7 from adhocracy4.projects.mixins import DisplayProjectOrModuleMixin
  8 from adhocracy4.projects.mixins import ProjectMixin
  9 from adhocracy4.rules import mixins as rules_mixins
  10 from meinberlin.apps.exports.views import DashboardExportView
  11 
  12 from . import models
  13 
  14 
  15 class DocumentDashboardView(ProjectMixin,
  16                             dashboard_mixins.DashboardBaseMixin,
  17                             dashboard_mixins.DashboardComponentMixin,
  18                             generic.TemplateView):
  19     template_name = 'meinberlin_documents/document_dashboard.html'
  20     permission_required = 'a4projects.change_project'
  21 
  22     def get_permission_object(self):
  23         return self.project
  24 
  25 
  26 class ChapterDetailView(ProjectMixin,
  27                         rules_mixins.PermissionRequiredMixin,
  28                         generic.DetailView,
  29                         DisplayProjectOrModuleMixin):
  30     model = models.Chapter
  31     permission_required = 'meinberlin_documents.view_chapter'
  32     get_context_from_object = True
  33 
  34     def get_context_data(self, **kwargs):
  35         context = super(ChapterDetailView, self).get_context_data(**kwargs)
  36         context['chapter_list'] = self.chapter_list
  37         return context
  38 
  39     @property
  40     def chapter_list(self):
  41         return models.Chapter.objects.filter(module=self.module)
  42 
  43 
  44 class DocumentDetailView(ChapterDetailView):
  45     get_context_from_object = False
  46 
  47     def get_object(self):
  48         first_chapter = models.Chapter.objects \
  49             .filter(module=self.module) \
  50             .first()
  51 
  52         if not first_chapter:
  53             raise Http404(_('Document has no chapters defined.'))
  54         return first_chapter
  55 
  56 
  57 class ParagraphDetailView(ProjectMixin,
  58                           rules_mixins.PermissionRequiredMixin,
  59                           generic.DetailView):
  60     model = models.Paragraph
  61     permission_required = 'meinberlin_documents.view_paragraph'
  62 
  63 
  64 class DocumentDashboardExportView(DashboardExportView):
  65     template_name = 'meinberlin_exports/export_dashboard.html'
  66 
  67     def get_context_data(self, **kwargs):
  68         context = super().get_context_data(**kwargs)
  69         context['comment_export'] = reverse(
  70             'a4dashboard:document-comment-export',
  71             kwargs={'module_slug': self.module.slug})
  72         return context
  73
  [end of meinberlin/apps/documents/views.py]
  [start of meinberlin/apps/documents/models.py]
  1 from ckeditor_uploader.fields import RichTextUploadingField
  2 from django.contrib.contenttypes.fields import GenericRelation
  3 from django.db import models
  4 from django.urls import reverse
  5 from django.utils.functional import cached_property
  6 
  7 from adhocracy4 import transforms
  8 from adhocracy4.comments import models as comment_models
  9 from adhocracy4.models import base
  10 from adhocracy4.modules import models as module_models
  11 
  12 
  13 class Chapter(module_models.Item):
  14     name = models.CharField(max_length=120)
  15     comments = GenericRelation(comment_models.Comment,
  16                                related_query_name='chapter',
  17                                object_id_field='object_pk')
  18     weight = models.PositiveIntegerField(default=0)
  19 
  20     class Meta:
  21         ordering = ('weight',)
  22 
  23     def __str__(self):
  24         return "{}_chapter_{}".format(str(self.module), self.pk)
  25 
  26     def get_absolute_url(self):
  27         return reverse('meinberlin_documents:chapter-detail',
  28                        args=[str(self.pk)])
  29 
  30     @cached_property
  31     def prev(self):
  32         return Chapter.objects\
  33             .filter(module=self.module)\
  34             .filter(weight__lt=self.weight)\
  35             .order_by('-weight')\
  36             .first()
  37 
  38     @cached_property
  39     def next(self):
  40         return Chapter.objects\
  41             .filter(module=self.module)\
  42             .filter(weight__gt=self.weight)\
  43             .order_by('weight')\
  44             .first()
  45 
  46 
  47 class Paragraph(base.TimeStampedModel):
  48     name = models.CharField(max_length=120, blank=True)
  49     text = RichTextUploadingField(config_name='image-editor')
  50     weight = models.PositiveIntegerField()
  51     chapter = models.ForeignKey(Chapter,
  52                                 on_delete=models.CASCADE,
  53                                 related_name='paragraphs')
  54     comments = GenericRelation(comment_models.Comment,
  55                                related_query_name='paragraph',
  56                                object_id_field='object_pk')
  57 
  58     class Meta:
  59         ordering = ('weight',)
  60 
  61     def __str__(self):
  62         return "{}_paragraph_{}".format(str(self.chapter), self.weight)
  63 
  64     def save(self, *args, **kwargs):
  65         self.text = transforms.clean_html_field(
  66             self.text, 'image-editor')
  67         super().save(*args, **kwargs)
  68 
  69     def get_absolute_url(self):
  70         return reverse('meinberlin_documents:paragraph-detail',
  71                        args=[str(self.pk)])
  72 
  73     @property
  74     def creator(self):
  75         return self.chapter.creator
  76 
  77     @property
  78     def project(self):
  79         return self.module.project
  80 
  81     @property
  82     def module(self):
  83         return self.chapter.module
  84
  [end of meinberlin/apps/documents/models.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/meinberlin/apps/documents/models.py b/meinberlin/apps/documents/models.py
  --- a/meinberlin/apps/documents/models.py
  +++ b/meinberlin/apps/documents/models.py
  @@ -24,6 +24,12 @@
           return "{}_chapter_{}".format(str(self.module), self.pk)
   
       def get_absolute_url(self):
  +        if (self.project.display_timeline
  +                and not self.module.is_in_module_cluster):
  +            return ('{}?initialSlide={}'
  +                    .format(reverse('meinberlin_documents:chapter-detail',
  +                                    args=[str(self.pk)]),
  +                            self.module.get_timeline_index))
           return reverse('meinberlin_documents:chapter-detail',
                          args=[str(self.pk)])
   
  diff --git a/meinberlin/apps/documents/views.py b/meinberlin/apps/documents/views.py
  --- a/meinberlin/apps/documents/views.py
  +++ b/meinberlin/apps/documents/views.py
  @@ -1,5 +1,6 @@
   from django.http import Http404
   from django.urls import reverse
  +from django.utils.functional import cached_property
   from django.utils.translation import ugettext_lazy as _
   from django.views import generic
   
  @@ -32,7 +33,7 @@
       get_context_from_object = True
   
       def get_context_data(self, **kwargs):
  -        context = super(ChapterDetailView, self).get_context_data(**kwargs)
  +        context = super().get_context_data(**kwargs)
           context['chapter_list'] = self.chapter_list
           return context
   
  @@ -40,6 +41,15 @@
       def chapter_list(self):
           return models.Chapter.objects.filter(module=self.module)
   
  +    @cached_property
  +    def extends(self):
  +        if self.url_name == 'module-detail':
  +            return 'a4modules/module_detail.html'
  +        if self.url_name == 'chapter-detail':
  +            if self.module.is_in_module_cluster:
  +                return 'a4modules/module_detail.html'
  +        return 'a4projects/project_detail.html'
  +
   
   class DocumentDetailView(ChapterDetailView):
       get_context_from_object = False
  
verification_info: {"golden_diff": "diff --git a/meinberlin/apps/documents/models.py b/meinberlin/apps/documents/models.py\n--- a/meinberlin/apps/documents/models.py\n+++ b/meinberlin/apps/documents/models.py\n@@ -24,6 +24,12 @@\n         return \"{}_chapter_{}\".format(str(self.module), self.pk)\n \n     def get_absolute_url(self):\n+        if (self.project.display_timeline\n+                and not self.module.is_in_module_cluster):\n+            return ('{}?initialSlide={}'\n+                    .format(reverse('meinberlin_documents:chapter-detail',\n+                                    args=[str(self.pk)]),\n+                            self.module.get_timeline_index))\n         return reverse('meinberlin_documents:chapter-detail',\n                        args=[str(self.pk)])\n \ndiff --git a/meinberlin/apps/documents/views.py b/meinberlin/apps/documents/views.py\n--- a/meinberlin/apps/documents/views.py\n+++ b/meinberlin/apps/documents/views.py\n@@ -1,5 +1,6 @@\n from django.http import Http404\n from django.urls import reverse\n+from django.utils.functional import cached_property\n from django.utils.translation import ugettext_lazy as _\n from django.views import generic\n \n@@ -32,7 +33,7 @@\n     get_context_from_object = True\n \n     def get_context_data(self, **kwargs):\n-        context = super(ChapterDetailView, self).get_context_data(**kwargs)\n+        context = super().get_context_data(**kwargs)\n         context['chapter_list'] = self.chapter_list\n         return context\n \n@@ -40,6 +41,15 @@\n     def chapter_list(self):\n         return models.Chapter.objects.filter(module=self.module)\n \n+    @cached_property\n+    def extends(self):\n+        if self.url_name == 'module-detail':\n+            return 'a4modules/module_detail.html'\n+        if self.url_name == 'chapter-detail':\n+            if self.module.is_in_module_cluster:\n+                return 'a4modules/module_detail.html'\n+        return 'a4projects/project_detail.html'\n+\n \n class DocumentDetailView(ChapterDetailView):\n     get_context_from_object = False\n", "issue": "in text commenting links to first chapter lead back to the project view\n...so I am back to the timeline and the tiles\r\n\r\nThere are two links doing that: \"back to chapter\" in paragraph detail view and \"previous chapter\" in second chapter.\n", "before_files": [{"content": "from django.http import Http404\nfrom django.urls import reverse\nfrom django.utils.translation import ugettext_lazy as _\nfrom django.views import generic\n\nfrom adhocracy4.dashboard import mixins as dashboard_mixins\nfrom adhocracy4.projects.mixins import DisplayProjectOrModuleMixin\nfrom adhocracy4.projects.mixins import ProjectMixin\nfrom adhocracy4.rules import mixins as rules_mixins\nfrom meinberlin.apps.exports.views import DashboardExportView\n\nfrom . import models\n\n\nclass DocumentDashboardView(ProjectMixin,\n                            dashboard_mixins.DashboardBaseMixin,\n                            dashboard_mixins.DashboardComponentMixin,\n                            generic.TemplateView):\n    template_name = 'meinberlin_documents/document_dashboard.html'\n    permission_required = 'a4projects.change_project'\n\n    def get_permission_object(self):\n        return self.project\n\n\nclass ChapterDetailView(ProjectMixin,\n                        rules_mixins.PermissionRequiredMixin,\n                        generic.DetailView,\n                        DisplayProjectOrModuleMixin):\n    model = models.Chapter\n    permission_required = 'meinberlin_documents.view_chapter'\n    get_context_from_object = True\n\n    def get_context_data(self, **kwargs):\n        context = super(ChapterDetailView, self).get_context_data(**kwargs)\n        context['chapter_list'] = self.chapter_list\n        return context\n\n    @property\n    def chapter_list(self):\n        return models.Chapter.objects.filter(module=self.module)\n\n\nclass DocumentDetailView(ChapterDetailView):\n    get_context_from_object = False\n\n    def get_object(self):\n        first_chapter = models.Chapter.objects \\\n            .filter(module=self.module) \\\n            .first()\n\n        if not first_chapter:\n            raise Http404(_('Document has no chapters defined.'))\n        return first_chapter\n\n\nclass ParagraphDetailView(ProjectMixin,\n                          rules_mixins.PermissionRequiredMixin,\n                          generic.DetailView):\n    model = models.Paragraph\n    permission_required = 'meinberlin_documents.view_paragraph'\n\n\nclass DocumentDashboardExportView(DashboardExportView):\n    template_name = 'meinberlin_exports/export_dashboard.html'\n\n    def get_context_data(self, **kwargs):\n        context = super().get_context_data(**kwargs)\n        context['comment_export'] = reverse(\n            'a4dashboard:document-comment-export',\n            kwargs={'module_slug': self.module.slug})\n        return context\n", "path": "meinberlin/apps/documents/views.py"}, {"content": "from ckeditor_uploader.fields import RichTextUploadingField\nfrom django.contrib.contenttypes.fields import GenericRelation\nfrom django.db import models\nfrom django.urls import reverse\nfrom django.utils.functional import cached_property\n\nfrom adhocracy4 import transforms\nfrom adhocracy4.comments import models as comment_models\nfrom adhocracy4.models import base\nfrom adhocracy4.modules import models as module_models\n\n\nclass Chapter(module_models.Item):\n    name = models.CharField(max_length=120)\n    comments = GenericRelation(comment_models.Comment,\n                               related_query_name='chapter',\n                               object_id_field='object_pk')\n    weight = models.PositiveIntegerField(default=0)\n\n    class Meta:\n        ordering = ('weight',)\n\n    def __str__(self):\n        return \"{}_chapter_{}\".format(str(self.module), self.pk)\n\n    def get_absolute_url(self):\n        return reverse('meinberlin_documents:chapter-detail',\n                       args=[str(self.pk)])\n\n    @cached_property\n    def prev(self):\n        return Chapter.objects\\\n            .filter(module=self.module)\\\n            .filter(weight__lt=self.weight)\\\n            .order_by('-weight')\\\n            .first()\n\n    @cached_property\n    def next(self):\n        return Chapter.objects\\\n            .filter(module=self.module)\\\n            .filter(weight__gt=self.weight)\\\n            .order_by('weight')\\\n            .first()\n\n\nclass Paragraph(base.TimeStampedModel):\n    name = models.CharField(max_length=120, blank=True)\n    text = RichTextUploadingField(config_name='image-editor')\n    weight = models.PositiveIntegerField()\n    chapter = models.ForeignKey(Chapter,\n                                on_delete=models.CASCADE,\n                                related_name='paragraphs')\n    comments = GenericRelation(comment_models.Comment,\n                               related_query_name='paragraph',\n                               object_id_field='object_pk')\n\n    class Meta:\n        ordering = ('weight',)\n\n    def __str__(self):\n        return \"{}_paragraph_{}\".format(str(self.chapter), self.weight)\n\n    def save(self, *args, **kwargs):\n        self.text = transforms.clean_html_field(\n            self.text, 'image-editor')\n        super().save(*args, **kwargs)\n\n    def get_absolute_url(self):\n        return reverse('meinberlin_documents:paragraph-detail',\n                       args=[str(self.pk)])\n\n    @property\n    def creator(self):\n        return self.chapter.creator\n\n    @property\n    def project(self):\n        return self.module.project\n\n    @property\n    def module(self):\n        return self.chapter.module\n", "path": "meinberlin/apps/documents/models.py"}]}