prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  UserProfile missing when User is not created during import
  Users which are not created by an enrollment data import but by logging in for the first time (using Kerberos authentication, so they don't need to have a local account first) don't have a UserProfile. This leads to undefined behavior.
  
  UserProfile missing when User is not created during import
  Users which are not created by an enrollment data import but by logging in for the first time (using Kerberos authentication, so they don't need to have a local account first) don't have a UserProfile. This leads to undefined behavior.
  
  
  </issue>
  <code>
  [start of evap/evaluation/views.py]
  1 from django.contrib import messages
  2 from django.contrib.auth import login as auth_login
  3 from django.shortcuts import redirect, render_to_response
  4 from django.template import RequestContext
  5 from django.utils.translation import ugettext as _
  6 
  7 from evap.evaluation.forms import NewKeyForm, LoginKeyForm, LoginUsernameForm
  8 from evap.evaluation.models import UserProfile, FaqSection, EmailTemplate
  9 
  10 
  11 def index(request):
  12     """Main entry page into EvaP providing all the login options available. THe username/password
  13        login is thought to be used for internal users, e.g. by connecting to a LDAP directory.
  14        The login key mechanism is meant to be used to include external participants, e.g. visiting
  15        students or visiting contributors.
  16     """
  17 
  18     # parse the form data into the respective form
  19     submit_type = request.POST.get("submit_type", "no_submit")
  20     new_key_form = NewKeyForm(request.POST if submit_type == "new_key" else None)
  21     login_key_form = LoginKeyForm(request.POST if submit_type == "login_key" else None)
  22     login_username_form = LoginUsernameForm(request, request.POST if submit_type == "login_username" else None)
  23 
  24     # process form data
  25     if request.method == 'POST':
  26         if new_key_form.is_valid():
  27             # user wants a new login key
  28             profile = new_key_form.get_profile()
  29             profile.generate_login_key()
  30             profile.save()
  31 
  32             EmailTemplate.get_login_key_template().send_to_user(new_key_form.get_user())
  33 
  34             messages.success(request, _(u"Successfully sent email with new login key."))
  35         elif login_key_form.is_valid():
  36             # user would like to login with a login key and passed key test
  37             auth_login(request, login_key_form.get_user())
  38         elif login_username_form.is_valid():
  39             # user would like to login with username and password and passed password test
  40             auth_login(request, login_username_form.get_user())
  41 
  42             # clean up our test cookie
  43             if request.session.test_cookie_worked():
  44                 request.session.delete_test_cookie()
  45 
  46     # if not logged in by now, render form
  47     if not request.user.is_active:
  48         # set test cookie to verify whether they work in the next step
  49         request.session.set_test_cookie()
  50 
  51         return render_to_response("index.html", dict(new_key_form=new_key_form, login_key_form=login_key_form, login_username_form=login_username_form), context_instance=RequestContext(request))
  52     else:
  53         # check for redirect variable
  54         redirect_to = request.GET.get("next", None)
  55         if redirect_to is not None:
  56             if redirect_to.startswith("/fsr/"):
  57                 if request.user.is_staff:
  58                     return redirect(redirect_to)
  59             elif redirect_to.startswith("/contributor/"):
  60                 if UserProfile.get_for_user(request.user).is_contributor:
  61                     return redirect(redirect_to)
  62             else:
  63                 return redirect(redirect_to)
  64 
  65         # redirect user to appropriate start page
  66         if request.user.is_staff:
  67             return redirect('evap.fsr.views.index')
  68         elif UserProfile.get_for_user(request.user).is_editor_or_delegate:
  69             return redirect('evap.contributor.views.index')
  70         else:
  71             return redirect('evap.student.views.index')
  72 
  73 
  74 def faq(request):
  75     return render_to_response("faq.html", dict(sections=FaqSection.objects.all()), context_instance=RequestContext(request))
  76
  [end of evap/evaluation/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/evap/evaluation/views.py b/evap/evaluation/views.py
  --- a/evap/evaluation/views.py
  +++ b/evap/evaluation/views.py
  @@ -50,6 +50,8 @@
   
           return render_to_response("index.html", dict(new_key_form=new_key_form, login_key_form=login_key_form, login_username_form=login_username_form), context_instance=RequestContext(request))
       else:
  +        userprofile, _ = UserProfile.objects.get_or_create(user=request.user)
  +
           # check for redirect variable
           redirect_to = request.GET.get("next", None)
           if redirect_to is not None:
  @@ -57,7 +59,7 @@
                   if request.user.is_staff:
                       return redirect(redirect_to)
               elif redirect_to.startswith("/contributor/"):
  -                if UserProfile.get_for_user(request.user).is_contributor:
  +                if userprofile.is_contributor:
                       return redirect(redirect_to)
               else:
                   return redirect(redirect_to)
  @@ -65,7 +67,7 @@
           # redirect user to appropriate start page
           if request.user.is_staff:
               return redirect('evap.fsr.views.index')
  -        elif UserProfile.get_for_user(request.user).is_editor_or_delegate:
  +        elif userprofile.is_editor_or_delegate:
               return redirect('evap.contributor.views.index')
           else:
               return redirect('evap.student.views.index')
  
verification_info: {"golden_diff": "diff --git a/evap/evaluation/views.py b/evap/evaluation/views.py\n--- a/evap/evaluation/views.py\n+++ b/evap/evaluation/views.py\n@@ -50,6 +50,8 @@\n \n         return render_to_response(\"index.html\", dict(new_key_form=new_key_form, login_key_form=login_key_form, login_username_form=login_username_form), context_instance=RequestContext(request))\n     else:\n+        userprofile, _ = UserProfile.objects.get_or_create(user=request.user)\n+\n         # check for redirect variable\n         redirect_to = request.GET.get(\"next\", None)\n         if redirect_to is not None:\n@@ -57,7 +59,7 @@\n                 if request.user.is_staff:\n                     return redirect(redirect_to)\n             elif redirect_to.startswith(\"/contributor/\"):\n-                if UserProfile.get_for_user(request.user).is_contributor:\n+                if userprofile.is_contributor:\n                     return redirect(redirect_to)\n             else:\n                 return redirect(redirect_to)\n@@ -65,7 +67,7 @@\n         # redirect user to appropriate start page\n         if request.user.is_staff:\n             return redirect('evap.fsr.views.index')\n-        elif UserProfile.get_for_user(request.user).is_editor_or_delegate:\n+        elif userprofile.is_editor_or_delegate:\n             return redirect('evap.contributor.views.index')\n         else:\n             return redirect('evap.student.views.index')\n", "issue": "UserProfile missing when User is not created during import\nUsers which are not created by an enrollment data import but by logging in for the first time (using Kerberos authentication, so they don't need to have a local account first) don't have a UserProfile. This leads to undefined behavior.\n\nUserProfile missing when User is not created during import\nUsers which are not created by an enrollment data import but by logging in for the first time (using Kerberos authentication, so they don't need to have a local account first) don't have a UserProfile. This leads to undefined behavior.\n\n", "before_files": [{"content": "from django.contrib import messages\nfrom django.contrib.auth import login as auth_login\nfrom django.shortcuts import redirect, render_to_response\nfrom django.template import RequestContext\nfrom django.utils.translation import ugettext as _\n\nfrom evap.evaluation.forms import NewKeyForm, LoginKeyForm, LoginUsernameForm\nfrom evap.evaluation.models import UserProfile, FaqSection, EmailTemplate\n\n\ndef index(request):\n    \"\"\"Main entry page into EvaP providing all the login options available. THe username/password\n       login is thought to be used for internal users, e.g. by connecting to a LDAP directory.\n       The login key mechanism is meant to be used to include external participants, e.g. visiting\n       students or visiting contributors.\n    \"\"\"\n\n    # parse the form data into the respective form\n    submit_type = request.POST.get(\"submit_type\", \"no_submit\")\n    new_key_form = NewKeyForm(request.POST if submit_type == \"new_key\" else None)\n    login_key_form = LoginKeyForm(request.POST if submit_type == \"login_key\" else None)\n    login_username_form = LoginUsernameForm(request, request.POST if submit_type == \"login_username\" else None)\n\n    # process form data\n    if request.method == 'POST':\n        if new_key_form.is_valid():\n            # user wants a new login key\n            profile = new_key_form.get_profile()\n            profile.generate_login_key()\n            profile.save()\n\n            EmailTemplate.get_login_key_template().send_to_user(new_key_form.get_user())\n\n            messages.success(request, _(u\"Successfully sent email with new login key.\"))\n        elif login_key_form.is_valid():\n            # user would like to login with a login key and passed key test\n            auth_login(request, login_key_form.get_user())\n        elif login_username_form.is_valid():\n            # user would like to login with username and password and passed password test\n            auth_login(request, login_username_form.get_user())\n\n            # clean up our test cookie\n            if request.session.test_cookie_worked():\n                request.session.delete_test_cookie()\n\n    # if not logged in by now, render form\n    if not request.user.is_active:\n        # set test cookie to verify whether they work in the next step\n        request.session.set_test_cookie()\n\n        return render_to_response(\"index.html\", dict(new_key_form=new_key_form, login_key_form=login_key_form, login_username_form=login_username_form), context_instance=RequestContext(request))\n    else:\n        # check for redirect variable\n        redirect_to = request.GET.get(\"next\", None)\n        if redirect_to is not None:\n            if redirect_to.startswith(\"/fsr/\"):\n                if request.user.is_staff:\n                    return redirect(redirect_to)\n            elif redirect_to.startswith(\"/contributor/\"):\n                if UserProfile.get_for_user(request.user).is_contributor:\n                    return redirect(redirect_to)\n            else:\n                return redirect(redirect_to)\n\n        # redirect user to appropriate start page\n        if request.user.is_staff:\n            return redirect('evap.fsr.views.index')\n        elif UserProfile.get_for_user(request.user).is_editor_or_delegate:\n            return redirect('evap.contributor.views.index')\n        else:\n            return redirect('evap.student.views.index')\n\n\ndef faq(request):\n    return render_to_response(\"faq.html\", dict(sections=FaqSection.objects.all()), context_instance=RequestContext(request))\n", "path": "evap/evaluation/views.py"}]}