prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  When editing an application user can select capabilities not allowed by his groups
  
  
  </issue>
  <code>
  [start of apps/dot_ext/views/application.py]
  1 from django.core.urlresolvers import reverse_lazy
  2 from django.forms.models import modelform_factory
  3 from django.views.generic import CreateView, DetailView, DeleteView, ListView, UpdateView
  4 
  5 from braces.views import LoginRequiredMixin
  6 
  7 from oauth2_provider.models import get_application_model
  8 
  9 
  10 class ApplicationOwnerIsUserMixin(LoginRequiredMixin):
  11     """
  12     This mixin is used to provide an Application queryset filtered by the current request.user.
  13     """
  14     fields = '__all__'
  15 
  16     def get_queryset(self):
  17         return get_application_model().objects.filter(user=self.request.user)
  18 
  19 
  20 class ApplicationRegistration(LoginRequiredMixin, CreateView):
  21     """
  22     View used to register a new Application for the request.user
  23     """
  24     template_name = "application_registration_form.html"
  25 
  26     def get_form_class(self):
  27         """
  28         Returns the form class for the application model
  29         """
  30         
  31         mff = modelform_factory(
  32             get_application_model(),
  33             fields=('name', 'client_id', 'client_secret', 'client_type',
  34                     'authorization_grant_type', 'scope', 'redirect_uris', )
  35         )
  36         return mff
  37     
  38     
  39 
  40     def form_valid(self, form):
  41         form.instance.user = self.request.user
  42         return super(ApplicationRegistration, self).form_valid(form)
  43 
  44 
  45 class ApplicationDetail(ApplicationOwnerIsUserMixin, DetailView):
  46     """
  47     Detail view for an application instance owned by the request.user
  48     """
  49     context_object_name = 'application'
  50     template_name = "application_detail.html"
  51 
  52 
  53 class ApplicationList(ApplicationOwnerIsUserMixin, ListView):
  54     """
  55     List view for all the applications owned by the request.user
  56     """
  57     context_object_name = 'applications'
  58     template_name = "application_list.html"
  59 
  60 
  61 class ApplicationDelete(ApplicationOwnerIsUserMixin, DeleteView):
  62     """
  63     View used to delete an application owned by the request.user
  64     """
  65     context_object_name = 'application'
  66     success_url = reverse_lazy('dote_list')
  67     template_name = "application_confirm_delete.html"
  68 
  69 
  70 class ApplicationUpdate(ApplicationOwnerIsUserMixin, UpdateView):
  71     """
  72     View used to update an application owned by the request.user
  73     """
  74     context_object_name = 'application'
  75     template_name = "application_form.html"
  76
  [end of apps/dot_ext/views/application.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/apps/dot_ext/views/application.py b/apps/dot_ext/views/application.py
  --- a/apps/dot_ext/views/application.py
  +++ b/apps/dot_ext/views/application.py
  @@ -6,6 +6,8 @@
   
   from oauth2_provider.models import get_application_model
   
  +from ..forms import CustomRegisterApplicationForm
  +
   
   class ApplicationOwnerIsUserMixin(LoginRequiredMixin):
       """
  @@ -27,15 +29,15 @@
           """
           Returns the form class for the application model
           """
  -        
  +
           mff = modelform_factory(
               get_application_model(),
               fields=('name', 'client_id', 'client_secret', 'client_type',
                       'authorization_grant_type', 'scope', 'redirect_uris', )
           )
           return mff
  -    
  -    
  +
  +
   
       def form_valid(self, form):
           form.instance.user = self.request.user
  @@ -73,3 +75,15 @@
       """
       context_object_name = 'application'
       template_name = "application_form.html"
  +
  +    fields = None
  +    form_class = CustomRegisterApplicationForm
  +
  +    def get_form_kwargs(self):
  +        """
  +        Add `user` to kwargs because it is required by the constructor of
  +        CustomRegisterApplicationForm class.
  +        """
  +        kwargs = super(ApplicationUpdate, self).get_form_kwargs()
  +        kwargs['user'] = self.request.user
  +        return kwargs
  
verification_info: {"golden_diff": "diff --git a/apps/dot_ext/views/application.py b/apps/dot_ext/views/application.py\n--- a/apps/dot_ext/views/application.py\n+++ b/apps/dot_ext/views/application.py\n@@ -6,6 +6,8 @@\n \n from oauth2_provider.models import get_application_model\n \n+from ..forms import CustomRegisterApplicationForm\n+\n \n class ApplicationOwnerIsUserMixin(LoginRequiredMixin):\n     \"\"\"\n@@ -27,15 +29,15 @@\n         \"\"\"\n         Returns the form class for the application model\n         \"\"\"\n-        \n+\n         mff = modelform_factory(\n             get_application_model(),\n             fields=('name', 'client_id', 'client_secret', 'client_type',\n                     'authorization_grant_type', 'scope', 'redirect_uris', )\n         )\n         return mff\n-    \n-    \n+\n+\n \n     def form_valid(self, form):\n         form.instance.user = self.request.user\n@@ -73,3 +75,15 @@\n     \"\"\"\n     context_object_name = 'application'\n     template_name = \"application_form.html\"\n+\n+    fields = None\n+    form_class = CustomRegisterApplicationForm\n+\n+    def get_form_kwargs(self):\n+        \"\"\"\n+        Add `user` to kwargs because it is required by the constructor of\n+        CustomRegisterApplicationForm class.\n+        \"\"\"\n+        kwargs = super(ApplicationUpdate, self).get_form_kwargs()\n+        kwargs['user'] = self.request.user\n+        return kwargs\n", "issue": "When editing an application user can select capabilities not allowed by his groups\n\n", "before_files": [{"content": "from django.core.urlresolvers import reverse_lazy\nfrom django.forms.models import modelform_factory\nfrom django.views.generic import CreateView, DetailView, DeleteView, ListView, UpdateView\n\nfrom braces.views import LoginRequiredMixin\n\nfrom oauth2_provider.models import get_application_model\n\n\nclass ApplicationOwnerIsUserMixin(LoginRequiredMixin):\n    \"\"\"\n    This mixin is used to provide an Application queryset filtered by the current request.user.\n    \"\"\"\n    fields = '__all__'\n\n    def get_queryset(self):\n        return get_application_model().objects.filter(user=self.request.user)\n\n\nclass ApplicationRegistration(LoginRequiredMixin, CreateView):\n    \"\"\"\n    View used to register a new Application for the request.user\n    \"\"\"\n    template_name = \"application_registration_form.html\"\n\n    def get_form_class(self):\n        \"\"\"\n        Returns the form class for the application model\n        \"\"\"\n        \n        mff = modelform_factory(\n            get_application_model(),\n            fields=('name', 'client_id', 'client_secret', 'client_type',\n                    'authorization_grant_type', 'scope', 'redirect_uris', )\n        )\n        return mff\n    \n    \n\n    def form_valid(self, form):\n        form.instance.user = self.request.user\n        return super(ApplicationRegistration, self).form_valid(form)\n\n\nclass ApplicationDetail(ApplicationOwnerIsUserMixin, DetailView):\n    \"\"\"\n    Detail view for an application instance owned by the request.user\n    \"\"\"\n    context_object_name = 'application'\n    template_name = \"application_detail.html\"\n\n\nclass ApplicationList(ApplicationOwnerIsUserMixin, ListView):\n    \"\"\"\n    List view for all the applications owned by the request.user\n    \"\"\"\n    context_object_name = 'applications'\n    template_name = \"application_list.html\"\n\n\nclass ApplicationDelete(ApplicationOwnerIsUserMixin, DeleteView):\n    \"\"\"\n    View used to delete an application owned by the request.user\n    \"\"\"\n    context_object_name = 'application'\n    success_url = reverse_lazy('dote_list')\n    template_name = \"application_confirm_delete.html\"\n\n\nclass ApplicationUpdate(ApplicationOwnerIsUserMixin, UpdateView):\n    \"\"\"\n    View used to update an application owned by the request.user\n    \"\"\"\n    context_object_name = 'application'\n    template_name = \"application_form.html\"\n", "path": "apps/dot_ext/views/application.py"}]}