prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  project_list in container add project form contains all projects
  @CarolingerSeilchenspringer at the moment all projects (not only the ones belonging to the organisation) can be added to a container. Should that stay that way?
  
  
  </issue>
  <code>
  [start of meinberlin/apps/projectcontainers/forms.py]
  1 from django.db.models import Q
  2 from django.utils.translation import ugettext_lazy as _
  3 
  4 from adhocracy4.dashboard.forms import ProjectCreateForm
  5 from adhocracy4.dashboard.forms import ProjectDashboardForm
  6 from meinberlin.apps.contrib.widgets import Select2MultipleWidget
  7 
  8 from . import models
  9 
  10 LABELS = {
  11     'name': _('Title of your container'),
  12     'description': _('Short description of your container'),
  13     'tile_image': _('Logo'),
  14 }
  15 
  16 HELP_TEXTS = {
  17     'name': _('This title will appear on the '
  18               'teaser card and on top of the container '
  19               'detail page. It should be max. 120 characters long'),
  20     'description': _('This short description will appear on '
  21                      'the header of the container and in the teaser. '
  22                      'It should briefly state the goal of the '
  23                      'projects in max. 250 chars.'),
  24     'tile_image': _(
  25         'The image will be shown in the container tile.'
  26     ),
  27 }
  28 
  29 
  30 class ContainerCreateForm(ProjectCreateForm):
  31 
  32     class Meta:
  33         model = models.ProjectContainer
  34         fields = ['name', 'description',
  35                   'tile_image', 'tile_image_copyright']
  36         labels = LABELS
  37         help_texts = HELP_TEXTS
  38 
  39 
  40 class ContainerBasicForm(ProjectDashboardForm):
  41 
  42     class Meta:
  43         model = models.ProjectContainer
  44         fields = ['name', 'description', 'tile_image',
  45                   'tile_image_copyright', 'is_archived']
  46         required_for_project_publish = ['name', 'description']
  47         labels = LABELS
  48         help_texts = HELP_TEXTS
  49 
  50 
  51 class ContainerInformationForm(ProjectDashboardForm):
  52 
  53     class Meta:
  54         model = models.ProjectContainer
  55         fields = ['information']
  56         required_for_project_publish = ['information']
  57         labels = {
  58             'information': _('Description of your container'),
  59         }
  60 
  61 
  62 class ContainerProjectsForm(ProjectDashboardForm):
  63 
  64     def __init__(self, *args, **kwargs):
  65         super().__init__(*args, **kwargs)
  66 
  67         # We tried to find a good balance between a short list and
  68         # all necessary projects. The details may change over time.
  69         # Projects that are already selected should remain in the queryset.
  70         self.fields['projects'].queryset = self.fields['projects'].queryset \
  71             .filter(projectcontainer=None)\
  72             .filter(Q(containers=self.instance) |
  73                     (Q(containers=None) &
  74                      Q(is_archived=False) &
  75                      Q(is_public=True)))\
  76             .order_by('name')
  77 
  78     class Meta:
  79         model = models.ProjectContainer
  80         fields = ['projects']
  81         required_for_project_publish = ['projects']
  82         widgets = {
  83             'projects': Select2MultipleWidget,
  84         }
  85
  [end of meinberlin/apps/projectcontainers/forms.py]
  [start of meinberlin/apps/projectcontainers/views.py]
  1 from django.utils.translation import ugettext_lazy as _
  2 from django.views import generic
  3 
  4 from adhocracy4.dashboard import mixins as dashboard_mixins
  5 from adhocracy4.dashboard.blueprints import ProjectBlueprint
  6 from adhocracy4.dashboard.components.forms.views import \
  7     ProjectComponentFormView
  8 from adhocracy4.dashboard.views import ProjectCreateView
  9 
  10 from . import forms
  11 from . import models
  12 
  13 
  14 class ContainerCreateView(ProjectCreateView):
  15     model = models.ProjectContainer
  16     slug_url_kwarg = 'project_slug'
  17     form_class = forms.ContainerCreateForm
  18     template_name = 'meinberlin_projectcontainers/container_create_form.html'
  19     success_message = _('Container successfully created.')
  20 
  21     blueprint = ProjectBlueprint(
  22         title=_('Container'),
  23         description=_(
  24             'A container contains multiple projects.'
  25         ),
  26         content=[],
  27         image='',
  28         settings_model=None,
  29     )
  30 
  31 
  32 class ContainerBasicFormView(ProjectComponentFormView):
  33     model = models.ProjectContainer
  34 
  35     @property
  36     def project(self):
  37         project = super().project
  38         return project.projectcontainer
  39 
  40     def get_object(self, queryset=None):
  41         return self.project
  42 
  43 
  44 class ContainerProjectsView(ProjectComponentFormView):
  45     model = models.ProjectContainer
  46 
  47     @property
  48     def project(self):
  49         project = super().project
  50         return project.projectcontainer
  51 
  52     def get_object(self, queryset=None):
  53         return self.project
  54 
  55 
  56 class ContainerListView(dashboard_mixins.DashboardBaseMixin,
  57                         generic.ListView):
  58     model = models.ProjectContainer
  59     paginate_by = 12
  60     template_name = 'meinberlin_projectcontainers/container_list.html'
  61     permission_required = 'a4projects.add_project'
  62     menu_item = 'project'
  63 
  64     def get_queryset(self):
  65         return super().get_queryset().filter(
  66             organisation=self.organisation
  67         )
  68 
  69     def get_permission_object(self):
  70         return self.organisation
  71
  [end of meinberlin/apps/projectcontainers/views.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/projectcontainers/forms.py b/meinberlin/apps/projectcontainers/forms.py
  --- a/meinberlin/apps/projectcontainers/forms.py
  +++ b/meinberlin/apps/projectcontainers/forms.py
  @@ -62,12 +62,20 @@
   class ContainerProjectsForm(ProjectDashboardForm):
   
       def __init__(self, *args, **kwargs):
  +        self.user = kwargs.pop('user')
  +        self.organisation = kwargs.pop('organisation')
           super().__init__(*args, **kwargs)
   
  -        # We tried to find a good balance between a short list and
  -        # all necessary projects. The details may change over time.
  -        # Projects that are already selected should remain in the queryset.
  -        self.fields['projects'].queryset = self.fields['projects'].queryset \
  +        projects = self.fields['projects']\
  +            .queryset.filter(organisation=self.organisation)
  +        if not self.organisation.has_initiator(self.user):
  +            user_groups = self.user.groups.all()
  +            org_groups = self.organisation.groups.all()
  +            shared_groups = user_groups & org_groups
  +            group = shared_groups.distinct().first()
  +            projects = projects.filter(group=group)
  +
  +        self.fields['projects'].queryset = projects \
               .filter(projectcontainer=None)\
               .filter(Q(containers=self.instance) |
                       (Q(containers=None) &
  diff --git a/meinberlin/apps/projectcontainers/views.py b/meinberlin/apps/projectcontainers/views.py
  --- a/meinberlin/apps/projectcontainers/views.py
  +++ b/meinberlin/apps/projectcontainers/views.py
  @@ -52,6 +52,12 @@
       def get_object(self, queryset=None):
           return self.project
   
  +    def get_form_kwargs(self):
  +        kwargs = super().get_form_kwargs()
  +        kwargs['user'] = self.request.user
  +        kwargs['organisation'] = self.project.organisation
  +        return kwargs
  +
   
   class ContainerListView(dashboard_mixins.DashboardBaseMixin,
                           generic.ListView):
  
verification_info: {"golden_diff": "diff --git a/meinberlin/apps/projectcontainers/forms.py b/meinberlin/apps/projectcontainers/forms.py\n--- a/meinberlin/apps/projectcontainers/forms.py\n+++ b/meinberlin/apps/projectcontainers/forms.py\n@@ -62,12 +62,20 @@\n class ContainerProjectsForm(ProjectDashboardForm):\n \n     def __init__(self, *args, **kwargs):\n+        self.user = kwargs.pop('user')\n+        self.organisation = kwargs.pop('organisation')\n         super().__init__(*args, **kwargs)\n \n-        # We tried to find a good balance between a short list and\n-        # all necessary projects. The details may change over time.\n-        # Projects that are already selected should remain in the queryset.\n-        self.fields['projects'].queryset = self.fields['projects'].queryset \\\n+        projects = self.fields['projects']\\\n+            .queryset.filter(organisation=self.organisation)\n+        if not self.organisation.has_initiator(self.user):\n+            user_groups = self.user.groups.all()\n+            org_groups = self.organisation.groups.all()\n+            shared_groups = user_groups & org_groups\n+            group = shared_groups.distinct().first()\n+            projects = projects.filter(group=group)\n+\n+        self.fields['projects'].queryset = projects \\\n             .filter(projectcontainer=None)\\\n             .filter(Q(containers=self.instance) |\n                     (Q(containers=None) &\ndiff --git a/meinberlin/apps/projectcontainers/views.py b/meinberlin/apps/projectcontainers/views.py\n--- a/meinberlin/apps/projectcontainers/views.py\n+++ b/meinberlin/apps/projectcontainers/views.py\n@@ -52,6 +52,12 @@\n     def get_object(self, queryset=None):\n         return self.project\n \n+    def get_form_kwargs(self):\n+        kwargs = super().get_form_kwargs()\n+        kwargs['user'] = self.request.user\n+        kwargs['organisation'] = self.project.organisation\n+        return kwargs\n+\n \n class ContainerListView(dashboard_mixins.DashboardBaseMixin,\n                         generic.ListView):\n", "issue": "project_list in container add project form contains all projects\n@CarolingerSeilchenspringer at the moment all projects (not only the ones belonging to the organisation) can be added to a container. Should that stay that way?\r\n\n", "before_files": [{"content": "from django.db.models import Q\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom adhocracy4.dashboard.forms import ProjectCreateForm\nfrom adhocracy4.dashboard.forms import ProjectDashboardForm\nfrom meinberlin.apps.contrib.widgets import Select2MultipleWidget\n\nfrom . import models\n\nLABELS = {\n    'name': _('Title of your container'),\n    'description': _('Short description of your container'),\n    'tile_image': _('Logo'),\n}\n\nHELP_TEXTS = {\n    'name': _('This title will appear on the '\n              'teaser card and on top of the container '\n              'detail page. It should be max. 120 characters long'),\n    'description': _('This short description will appear on '\n                     'the header of the container and in the teaser. '\n                     'It should briefly state the goal of the '\n                     'projects in max. 250 chars.'),\n    'tile_image': _(\n        'The image will be shown in the container tile.'\n    ),\n}\n\n\nclass ContainerCreateForm(ProjectCreateForm):\n\n    class Meta:\n        model = models.ProjectContainer\n        fields = ['name', 'description',\n                  'tile_image', 'tile_image_copyright']\n        labels = LABELS\n        help_texts = HELP_TEXTS\n\n\nclass ContainerBasicForm(ProjectDashboardForm):\n\n    class Meta:\n        model = models.ProjectContainer\n        fields = ['name', 'description', 'tile_image',\n                  'tile_image_copyright', 'is_archived']\n        required_for_project_publish = ['name', 'description']\n        labels = LABELS\n        help_texts = HELP_TEXTS\n\n\nclass ContainerInformationForm(ProjectDashboardForm):\n\n    class Meta:\n        model = models.ProjectContainer\n        fields = ['information']\n        required_for_project_publish = ['information']\n        labels = {\n            'information': _('Description of your container'),\n        }\n\n\nclass ContainerProjectsForm(ProjectDashboardForm):\n\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n\n        # We tried to find a good balance between a short list and\n        # all necessary projects. The details may change over time.\n        # Projects that are already selected should remain in the queryset.\n        self.fields['projects'].queryset = self.fields['projects'].queryset \\\n            .filter(projectcontainer=None)\\\n            .filter(Q(containers=self.instance) |\n                    (Q(containers=None) &\n                     Q(is_archived=False) &\n                     Q(is_public=True)))\\\n            .order_by('name')\n\n    class Meta:\n        model = models.ProjectContainer\n        fields = ['projects']\n        required_for_project_publish = ['projects']\n        widgets = {\n            'projects': Select2MultipleWidget,\n        }\n", "path": "meinberlin/apps/projectcontainers/forms.py"}, {"content": "from django.utils.translation import ugettext_lazy as _\nfrom django.views import generic\n\nfrom adhocracy4.dashboard import mixins as dashboard_mixins\nfrom adhocracy4.dashboard.blueprints import ProjectBlueprint\nfrom adhocracy4.dashboard.components.forms.views import \\\n    ProjectComponentFormView\nfrom adhocracy4.dashboard.views import ProjectCreateView\n\nfrom . import forms\nfrom . import models\n\n\nclass ContainerCreateView(ProjectCreateView):\n    model = models.ProjectContainer\n    slug_url_kwarg = 'project_slug'\n    form_class = forms.ContainerCreateForm\n    template_name = 'meinberlin_projectcontainers/container_create_form.html'\n    success_message = _('Container successfully created.')\n\n    blueprint = ProjectBlueprint(\n        title=_('Container'),\n        description=_(\n            'A container contains multiple projects.'\n        ),\n        content=[],\n        image='',\n        settings_model=None,\n    )\n\n\nclass ContainerBasicFormView(ProjectComponentFormView):\n    model = models.ProjectContainer\n\n    @property\n    def project(self):\n        project = super().project\n        return project.projectcontainer\n\n    def get_object(self, queryset=None):\n        return self.project\n\n\nclass ContainerProjectsView(ProjectComponentFormView):\n    model = models.ProjectContainer\n\n    @property\n    def project(self):\n        project = super().project\n        return project.projectcontainer\n\n    def get_object(self, queryset=None):\n        return self.project\n\n\nclass ContainerListView(dashboard_mixins.DashboardBaseMixin,\n                        generic.ListView):\n    model = models.ProjectContainer\n    paginate_by = 12\n    template_name = 'meinberlin_projectcontainers/container_list.html'\n    permission_required = 'a4projects.add_project'\n    menu_item = 'project'\n\n    def get_queryset(self):\n        return super().get_queryset().filter(\n            organisation=self.organisation\n        )\n\n    def get_permission_object(self):\n        return self.organisation\n", "path": "meinberlin/apps/projectcontainers/views.py"}]}