prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  The mastery completion sign updates only after a page refresh and not real time.
  ## Summary
  
  A learner had completed and came out of the exercise and found the green completed tick did not get updated real time, but after refreshing the page the completed tick appeared. 
  
  ## System information
   - Version: Kolibri 0.4.0beta10
   - Operating system: Ubuntu 14.04 LTS
   - Browser: Chrome
  
  
  ## How to reproduce
  1. Attempt an exercise or master it.
  2. Come out of the exercise.
  3. The completed or In progress stamp is not updated real time.
  
  ## Screenshots
  Learner has mastered the topic.
  ![whatsapp image 2017-06-16 at 8 53 16 pm](https://user-images.githubusercontent.com/13453618/27233432-10160d78-52d7-11e7-847a-841e87703bc8.jpeg)
  
  He exited the exercise and the completed sign on the thumbnail is not update:
  ![whatsapp image 2017-06-16 at 8 53 16 pm 1](https://user-images.githubusercontent.com/13453618/27233430-0ec0ba9a-52d7-11e7-9560-a942c1cd221d.jpeg)
  
  But on refreshing the page the thumbnail has the completed sign.
  
  </issue>
  <code>
  [start of kolibri/auth/backends.py]
  1 """
  2 Implements custom auth backends as described in the Django docs, for our custom user classes -- FacilityUser and
  3 DeviceOwner. The appropriate classes should be listed in the AUTHENTICATION_BACKENDS. Note that authentication
  4 backends are checked in the order they're listed.
  5 """
  6 
  7 from kolibri.auth.models import DeviceOwner, FacilityUser
  8 
  9 
  10 class FacilityUserBackend(object):
  11     """
  12     A class that implements authentication for FacilityUsers.
  13     """
  14 
  15     def authenticate(self, username=None, password=None, facility=None):
  16         """
  17         Authenticates the user if the credentials correspond to a FacilityUser for the specified Facility.
  18 
  19         :param username: a string
  20         :param password: a string
  21         :param facility: a Facility
  22         :return: A FacilityUser instance if successful, or None if authentication failed.
  23         """
  24         users = FacilityUser.objects.filter(username=username)
  25         if facility:
  26             users = users.filter(facility=facility)
  27         for user in users:
  28             if user.check_password(password):
  29                 return user
  30             # Allow login without password for learners for facilities that allow this.
  31             # Must specify the facility, to prevent accidental logins
  32             elif facility and user.dataset.learner_can_login_with_no_password and not user.roles.count():
  33                 return user
  34         return None
  35 
  36     def get_user(self, user_id):
  37         """
  38         Gets a user. Auth backends are required to implement this.
  39 
  40         :param user_id: A FacilityUser pk
  41         :return: A FacilityUser instance if a BaseUser with that pk is found, else None.
  42         """
  43         try:
  44             return FacilityUser.objects.get(pk=user_id)
  45         except FacilityUser.DoesNotExist:
  46             return None
  47 
  48 
  49 class DeviceOwnerBackend(object):
  50     """
  51     A class that implements authentication for DeviceOwners.
  52     """
  53 
  54     def authenticate(self, username=None, password=None, **kwargs):
  55         """
  56         Authenticates the user if the credentials correspond to a DeviceOwner.
  57 
  58         :param username: a string
  59         :param password: a string
  60         :return: A DeviceOwner instance if successful, or None if authentication failed.
  61         """
  62         try:
  63             user = DeviceOwner.objects.get(username=username)
  64             if user.check_password(password):
  65                 return user
  66             else:
  67                 return None
  68         except DeviceOwner.DoesNotExist:
  69             return None
  70 
  71     def get_user(self, user_id):
  72         """
  73         Gets a user. Auth backends are required to implement this.
  74 
  75         :param user_id: A BaseUser pk
  76         :return: A DeviceOwner instance if a BaseUser with that pk is found, else None.
  77         """
  78         try:
  79             return DeviceOwner.objects.get(pk=user_id)
  80         except DeviceOwner.DoesNotExist:
  81             return None
  82
  [end of kolibri/auth/backends.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/kolibri/auth/backends.py b/kolibri/auth/backends.py
  --- a/kolibri/auth/backends.py
  +++ b/kolibri/auth/backends.py
  @@ -21,7 +21,7 @@
           :param facility: a Facility
           :return: A FacilityUser instance if successful, or None if authentication failed.
           """
  -        users = FacilityUser.objects.filter(username=username)
  +        users = FacilityUser.objects.filter(username__iexact=username)
           if facility:
               users = users.filter(facility=facility)
           for user in users:
  
verification_info: {"golden_diff": "diff --git a/kolibri/auth/backends.py b/kolibri/auth/backends.py\n--- a/kolibri/auth/backends.py\n+++ b/kolibri/auth/backends.py\n@@ -21,7 +21,7 @@\n         :param facility: a Facility\n         :return: A FacilityUser instance if successful, or None if authentication failed.\n         \"\"\"\n-        users = FacilityUser.objects.filter(username=username)\n+        users = FacilityUser.objects.filter(username__iexact=username)\n         if facility:\n             users = users.filter(facility=facility)\n         for user in users:\n", "issue": "The mastery completion sign updates only after a page refresh and not real time.\n## Summary\r\n\r\nA learner had completed and came out of the exercise and found the green completed tick did not get updated real time, but after refreshing the page the completed tick appeared. \r\n\r\n## System information\r\n - Version: Kolibri 0.4.0beta10\r\n - Operating system: Ubuntu 14.04 LTS\r\n - Browser: Chrome\r\n\r\n\r\n## How to reproduce\r\n1. Attempt an exercise or master it.\r\n2. Come out of the exercise.\r\n3. The completed or In progress stamp is not updated real time.\r\n\r\n## Screenshots\r\nLearner has mastered the topic.\r\n![whatsapp image 2017-06-16 at 8 53 16 pm](https://user-images.githubusercontent.com/13453618/27233432-10160d78-52d7-11e7-847a-841e87703bc8.jpeg)\r\n\r\nHe exited the exercise and the completed sign on the thumbnail is not update:\r\n![whatsapp image 2017-06-16 at 8 53 16 pm 1](https://user-images.githubusercontent.com/13453618/27233430-0ec0ba9a-52d7-11e7-9560-a942c1cd221d.jpeg)\r\n\r\nBut on refreshing the page the thumbnail has the completed sign.\n", "before_files": [{"content": "\"\"\"\nImplements custom auth backends as described in the Django docs, for our custom user classes -- FacilityUser and\nDeviceOwner. The appropriate classes should be listed in the AUTHENTICATION_BACKENDS. Note that authentication\nbackends are checked in the order they're listed.\n\"\"\"\n\nfrom kolibri.auth.models import DeviceOwner, FacilityUser\n\n\nclass FacilityUserBackend(object):\n    \"\"\"\n    A class that implements authentication for FacilityUsers.\n    \"\"\"\n\n    def authenticate(self, username=None, password=None, facility=None):\n        \"\"\"\n        Authenticates the user if the credentials correspond to a FacilityUser for the specified Facility.\n\n        :param username: a string\n        :param password: a string\n        :param facility: a Facility\n        :return: A FacilityUser instance if successful, or None if authentication failed.\n        \"\"\"\n        users = FacilityUser.objects.filter(username=username)\n        if facility:\n            users = users.filter(facility=facility)\n        for user in users:\n            if user.check_password(password):\n                return user\n            # Allow login without password for learners for facilities that allow this.\n            # Must specify the facility, to prevent accidental logins\n            elif facility and user.dataset.learner_can_login_with_no_password and not user.roles.count():\n                return user\n        return None\n\n    def get_user(self, user_id):\n        \"\"\"\n        Gets a user. Auth backends are required to implement this.\n\n        :param user_id: A FacilityUser pk\n        :return: A FacilityUser instance if a BaseUser with that pk is found, else None.\n        \"\"\"\n        try:\n            return FacilityUser.objects.get(pk=user_id)\n        except FacilityUser.DoesNotExist:\n            return None\n\n\nclass DeviceOwnerBackend(object):\n    \"\"\"\n    A class that implements authentication for DeviceOwners.\n    \"\"\"\n\n    def authenticate(self, username=None, password=None, **kwargs):\n        \"\"\"\n        Authenticates the user if the credentials correspond to a DeviceOwner.\n\n        :param username: a string\n        :param password: a string\n        :return: A DeviceOwner instance if successful, or None if authentication failed.\n        \"\"\"\n        try:\n            user = DeviceOwner.objects.get(username=username)\n            if user.check_password(password):\n                return user\n            else:\n                return None\n        except DeviceOwner.DoesNotExist:\n            return None\n\n    def get_user(self, user_id):\n        \"\"\"\n        Gets a user. Auth backends are required to implement this.\n\n        :param user_id: A BaseUser pk\n        :return: A DeviceOwner instance if a BaseUser with that pk is found, else None.\n        \"\"\"\n        try:\n            return DeviceOwner.objects.get(pk=user_id)\n        except DeviceOwner.DoesNotExist:\n            return None\n", "path": "kolibri/auth/backends.py"}]}