prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  New user creation results in TypeError
  If one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.
  
  ![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)
  
  New user creation results in TypeError
  If one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.
  
  ![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)
  
  
  </issue>
  <code>
  [start of src/cms/forms/users/user_profile_form.py]
  1 """
  2 Form for creating a user object
  3 """
  4 import logging
  5 
  6 from django import forms
  7 
  8 from ...models import UserProfile
  9 
  10 
  11 logger = logging.getLogger(__name__)
  12 
  13 
  14 class UserProfileForm(forms.ModelForm):
  15 
  16     class Meta:
  17         model = UserProfile
  18         fields = [
  19             'regions',
  20             'organization'
  21         ]
  22 
  23     # pylint: disable=arguments-differ
  24     def save(self, *args, **kwargs):
  25 
  26         logger.info(
  27             'UserProfileForm saved with args %s and kwargs %s',
  28             args,
  29             kwargs
  30         )
  31 
  32         # pop kwarg to make sure the super class does not get this param
  33         user = kwargs.pop('user', None)
  34 
  35         if not self.instance.id:
  36             # don't commit saving of ModelForm, because required user field is still missing
  37             kwargs['commit'] = False
  38 
  39         # save ModelForm
  40         user_profile = super(UserProfileForm, self).save(*args, **kwargs)
  41 
  42         if not self.instance.id:
  43             user_profile.user = user
  44             user_profile.save()
  45             # check if called from UserProfileForm or RegionUserProfileForm
  46             if 'regions' in self.cleaned_data:
  47                 # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly
  48                 user_profile.regions = self.cleaned_data['regions']
  49                 user_profile.save()
  50 
  51         return user_profile
  52
  [end of src/cms/forms/users/user_profile_form.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/src/cms/forms/users/user_profile_form.py b/src/cms/forms/users/user_profile_form.py
  --- a/src/cms/forms/users/user_profile_form.py
  +++ b/src/cms/forms/users/user_profile_form.py
  @@ -45,7 +45,6 @@
               # check if called from UserProfileForm or RegionUserProfileForm
               if 'regions' in self.cleaned_data:
                   # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly
  -                user_profile.regions = self.cleaned_data['regions']
  -                user_profile.save()
  +                user_profile.regions.set(self.cleaned_data['regions'])
   
           return user_profile
  
verification_info: {"golden_diff": "diff --git a/src/cms/forms/users/user_profile_form.py b/src/cms/forms/users/user_profile_form.py\n--- a/src/cms/forms/users/user_profile_form.py\n+++ b/src/cms/forms/users/user_profile_form.py\n@@ -45,7 +45,6 @@\n             # check if called from UserProfileForm or RegionUserProfileForm\n             if 'regions' in self.cleaned_data:\n                 # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly\n-                user_profile.regions = self.cleaned_data['regions']\n-                user_profile.save()\n+                user_profile.regions.set(self.cleaned_data['regions'])\n \n         return user_profile\n", "issue": "New user creation results in TypeError\nIf one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.\r\n\r\n![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)\r\n\nNew user creation results in TypeError\nIf one wants to create a new user via the network settings an error will occur. The user gets created anyway, but this should be fixed quite fast.\r\n\r\n![grafik(1)](https://user-images.githubusercontent.com/15608678/77235502-78047780-6bb6-11ea-8fba-8e072c539c6f.png)\r\n\n", "before_files": [{"content": "\"\"\"\nForm for creating a user object\n\"\"\"\nimport logging\n\nfrom django import forms\n\nfrom ...models import UserProfile\n\n\nlogger = logging.getLogger(__name__)\n\n\nclass UserProfileForm(forms.ModelForm):\n\n    class Meta:\n        model = UserProfile\n        fields = [\n            'regions',\n            'organization'\n        ]\n\n    # pylint: disable=arguments-differ\n    def save(self, *args, **kwargs):\n\n        logger.info(\n            'UserProfileForm saved with args %s and kwargs %s',\n            args,\n            kwargs\n        )\n\n        # pop kwarg to make sure the super class does not get this param\n        user = kwargs.pop('user', None)\n\n        if not self.instance.id:\n            # don't commit saving of ModelForm, because required user field is still missing\n            kwargs['commit'] = False\n\n        # save ModelForm\n        user_profile = super(UserProfileForm, self).save(*args, **kwargs)\n\n        if not self.instance.id:\n            user_profile.user = user\n            user_profile.save()\n            # check if called from UserProfileForm or RegionUserProfileForm\n            if 'regions' in self.cleaned_data:\n                # regions can't be saved if commit=False on the ModelForm, so we have to save them explicitly\n                user_profile.regions = self.cleaned_data['regions']\n                user_profile.save()\n\n        return user_profile\n", "path": "src/cms/forms/users/user_profile_form.py"}]}