internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: learningequality/kolibri

Issue:
Login ID and Password fields for a learner/user should not be case sensitive.
## Summary

Login ID and Password fields for a learner/user should not be case sensitive, this is especially for young learners and they struggle a lot to login itself.

Please consider this change for Nalanda branch.

## System information
 - Version: Kolibri 0.4.0beta9
 - Operating system: Ubuntu 14.04 LTS
 - Browser: Chrome



Discussion:
Fixed in #1633 
@rtibbles The functionality works smooth and helps a lot.
But the usernames are still case sensitive:
The user name created is _Harish_ and a kid if enters _Hari_ only then he is suggested the full name Harish in dropdown, instead if case-insensitve _hari_ should also show Harish in the dropdown. This would be a great flow where any young learners will have total benefit of login in quickly.

1. In this I have to enter _har_ in small case to enable me to login to _harry_ quickly.
![case1](https://user-images.githubusercontent.com/13453618/27506671-0909d1d6-58db-11e7-9bc0-40d2ef1baf1d.png)
2. In this I have to enter _Har_ to enable me to login to _Harish_ quickly 
![case2](https://user-images.githubusercontent.com/13453618/27506672-09b39df6-58db-11e7-9560-953cf62670ab.png)
I can make the username search case insensitive, will update and build a new release by the end of Sunday. 

Resolving patch:
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 @@ def authenticate(self, username=None, password=None, facility=None):
         :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:


Test patch:
Repository: learningequality/kolibri

Issue:
imports get stuck when server is restarted

* begin importing channel
* stop server
* start server

Transfer is stuck partway. It does not continue, and due to #1673 cannot be canceled:

![image](https://user-images.githubusercontent.com/2367265/27461544-370a8796-576f-11e7-8e64-86fb3562d304.png)




Discussion:
Expected behavior is that there would be no in-progress Tasks, as Tasks are not restarted when the server is restarted.
When there's no import running, then clicking cancel should now clear the job from the job queue. Fixed by this PR: https://github.com/learningequality/kolibri/pull/1734
would it be possible to always clear the queue on startup?
Yup! Should be in a PR coming in either later or tomorrow morning (along with some other optimizations)

Resolving patch:
diff --git a/kolibri/tasks/api.py b/kolibri/tasks/api.py
--- a/kolibri/tasks/api.py
+++ b/kolibri/tasks/api.py
@@ -13,7 +13,6 @@
 
 import requests
 from django.core.management import call_command
-from django.conf import settings
 from django.http import Http404
 from django.utils.translation import ugettext as _
 from kolibri.content.models import ChannelMetadataCache
@@ -29,15 +28,14 @@
 
 logging = logger.getLogger(__name__)
 
-client = SimpleClient(
-    app="kolibri", storage_path=settings.QUEUE_JOB_STORAGE_PATH)
+client = SimpleClient(app="kolibri")
 
 # all tasks are marked as remote imports for nwo
 TASKTYPE = "remoteimport"
 
 
 class TasksViewSet(viewsets.ViewSet):
-    permission_classes = (IsDeviceOwnerOnly, )
+    permission_classes = (IsDeviceOwnerOnly,)
 
     def list(self, request):
         jobs_response = [_job_to_response(j) for j in client.all_jobs()]


Test patch:
Repository: learningequality/kolibri

Issue:
Value Error when running migrations for DateTimeTzField
## Summary

When switching from 0.4.x to 0.5.x, the migration can fail for the logger module with the following error:

`ValueError: time data '2017-06-27 20:59:11' does not match format '%Y-%m-%d %H:%M:%S.%f'`

## System information

*Please specify the Kolibri version you were using and your operating system!*

 - Version: 0.5.x
 - Operating system: Ubuntu 16.04
 - Browser: Chrome

## Traceback or relevant snippet from server.log or browser console

`ValueError: time data '2017-06-27 20:59:11' does not match format '%Y-%m-%d %H:%M:%S.%f'`

## How to reproduce

1. Ensure there is a time stamp in the database with no fractions of a second portion
2. Run migrations on 0.5.x

## Real-life consequences (anything community should be aware of, for instance how it affects your deployment)

Could block upgrade for 0.4.x users.


Discussion:

Resolving patch:
diff --git a/kolibri/core/fields.py b/kolibri/core/fields.py
--- a/kolibri/core/fields.py
+++ b/kolibri/core/fields.py
@@ -2,6 +2,7 @@
 import re
 
 import pytz
+from django.db.backends.utils import typecast_timestamp
 from django.db.models.fields import Field
 from django.utils import timezone
 
@@ -16,8 +17,10 @@ def parse_timezonestamp(value):
     else:
         tz = timezone.get_current_timezone()
     utc_value = tz_regex.sub('', value)
-    value = datetime.datetime.strptime(utc_value, date_time_format)
-    value = timezone.make_aware(value, pytz.utc)
+    value = typecast_timestamp(utc_value)
+    if value.tzinfo is None:
+        # Naive datetime, make aware
+        value = timezone.make_aware(value, pytz.utc)
     return value.astimezone(tz)
 
 def create_timezonestamp(value):


Test patch:
diff --git a/kolibri/core/test/test_datetimetzfield.py b/kolibri/core/test/test_datetimetzfield.py
--- a/kolibri/core/test/test_datetimetzfield.py
+++ b/kolibri/core/test/test_datetimetzfield.py
@@ -6,7 +6,7 @@
 from django.db import models
 from django.test import override_settings, TestCase
 from django.utils import timezone
-from kolibri.core.fields import DateTimeTzField
+from kolibri.core.fields import DateTimeTzField, parse_timezonestamp
 from kolibri.core.serializers import DateTimeTzField as DateTimeTzSerializerField
 
 def aware_datetime():
@@ -66,6 +66,17 @@ def test_default_arbitrary_create(self):
         self.assertEqual(obj.default_timestamp.tzinfo, timestamp.tzinfo)
         timezone.deactivate()
 
+    def test_zero_second_fractions_read(self):
+        # Regression test for https://github.com/learningequality/kolibri/issues/1758
+        timezone.activate(pytz.utc)
+        try:
+            timestamp = parse_timezonestamp('2000-12-11 10:09:08')
+            self.assertEqual(timestamp, aware_datetime())
+        except ValueError:
+            self.fail('parse_timezonestamp did not parse time data missing fractions of seconds.')
+        finally:
+            timezone.deactivate()
+
 
 @override_settings(USE_TZ=False)
 class NaiveDateTimeTzFieldTestCase(TestCase):
Repository: learningequality/kolibri

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.


Discussion:
@harishbalachandran This might be a duplicate of #1656.

When you are with this learner, could you check to see if their points are updated temporarily when the "good work" pop-up appears, then get reverted after the "good work" pop-up is dismissed?
@jonboiser 
Though the behaviour is same as 1656, I have raised this separate issue because they are different scenarios and flows. 

> When you are with this learner, could you check to see if their points are updated temporarily when the "good work" pop-up appears, then get reverted after the "good work" pop-up is dismissed?

This was a problem I had reported before, but now this issue of points reverting is not observed, points get updated and stays the same even after dismissing the popup.



Resolving patch:
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 @@ def authenticate(self, username=None, password=None, facility=None):
         :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:


Test patch:
Repository: learningequality/kolibri

Issue:
When accessing a channel under the 'Recent' coach reports tab, an error is thrown
## Summary

An error gets thrown when navigating to a particular channel under the recent coach report tab

## System information

 - Version: release-v0.5.x @ 4e03db7ba39fd5595df00bf560e5750ed74dfefd
 - Operating system: Ubuntu
 - Browser: Chrome

## Traceback or relevant snippet from server.log or browser console

```
Request Method: | GET
-- | --
http://127.0.0.1:8000/coach/api/fb51dae6df7545af8455aa3a0c32048d/fb51dae6df7545af8455aa3a0c32048d/classroom/22283b95afbd36b5b9eec1dfc29e5ef0/recentreport/?1499805004681=1499805004681
1.9.7
AttributeError
'tzutc' object has no attribute 'zone'
/home/richard/github/kolibri/kolibri/core/fields.py in create_timezonestamp, line 28
/home/richard/.virtualenvs/kolibripy3/bin/python3
3.5.3
['',
 '/home/richard/.virtualenvs/kolibripy3/lib/python3.5',
 '/home/richard/.virtualenvs/kolibripy3/lib/python3.5/plat-x86_64-linux-gnu',
 '/home/richard/.virtualenvs/kolibripy3/lib/python3.5/lib-dynload',
 '/usr/lib/python3.5',
 '/usr/lib/python3.5/plat-x86_64-linux-gnu',
 '/home/richard/.virtualenvs/kolibripy3/lib/python3.5/site-packages',
 '/home/richard/github/kolibri_exercise_perseus_plugin',
 '/home/richard/github/kolibri',
 '/home/richard/github/kolibri/kolibri/dist']
Tue, 11 Jul 2017 13:30:10 -0700
```

## How to reproduce

1.. Log on to coach or admin
2. Navigate to Coach reports
3. Click on 'recent' tab
4. Click on a channel

## Screenshot

![image](https://user-images.githubusercontent.com/1680573/28089959-8bf3411a-663f-11e7-88f0-e26482325f39.png)


## Real-life consequences (anything community should be aware of, for instance how it affects your deployment)

Recent reports are currently broken.


Discussion:

Resolving patch:
diff --git a/kolibri/core/fields.py b/kolibri/core/fields.py
--- a/kolibri/core/fields.py
+++ b/kolibri/core/fields.py
@@ -24,8 +24,16 @@ def parse_timezonestamp(value):
     return value.astimezone(tz)
 
 def create_timezonestamp(value):
-    if value.tzinfo:
+    if value.tzinfo and hasattr(value.tzinfo, 'zone'):
+        # We have a pytz timezone, we can work with this
         tz = value.tzinfo.zone
+    elif value.tzinfo:
+        # Got some timezone data, but it's not a pytz timezone
+        # Let's just assume someone used dateutil parser on a UTC
+        # ISO format timestamp
+        # Fixes https://github.com/learningequality/kolibri/issues/1824
+        tz = pytz.utc
+        value = value.astimezone(tz)
     else:
         tz = timezone.get_current_timezone().zone
         value = timezone.make_aware(value, timezone.get_current_timezone())


Test patch:
Repository: learningequality/kolibri

Issue:
My Channels not listing the new channels after import
## Summary

After importing a channel, whether from local drive or Internet, it does not appear under `My Channels` until page reload. 

## System information

 - Version: `0.5.0-beta9`
 - Operating system: Windows 7 & Ubuntu 16.10
 - Browser: Chrome

![ubuntu3 0 5-beta9 running - oracle vm virtualbox_494](https://user-images.githubusercontent.com/1457929/29728036-9cf986f8-89d6-11e7-99b0-fc0d7619fbdd.png)


On [version 0.4.0](https://github.com/learningequality/kolibri/issues/1640#issuecomment-313949731) at least there was a green notification, but now it's missing too:

![selection_328](https://user-images.githubusercontent.com/1457929/27996982-56743686-64ee-11e7-8f3d-cb2e1044b7d9.png)

State is correctly reported after deleting the channel, green notification included.

![ubuntu3 0 5-beta9 running - oracle vm virtualbox_496](https://user-images.githubusercontent.com/1457929/29727957-49d8e04a-89d6-11e7-8af6-3a70805475a4.png)


Discussion:

Resolving patch:
diff --git a/kolibri/tasks/api.py b/kolibri/tasks/api.py
--- a/kolibri/tasks/api.py
+++ b/kolibri/tasks/api.py
@@ -44,10 +44,10 @@ def list(self, request):
         jobs_response = [_job_to_response(j) for j in get_client().all_jobs()]
         ids = [job["id"] for job in jobs_response]
         # Clean up old job tasktypes
-        for key in id_tasktype.keys():
-            if key not in ids:
-                id_tasktype.pop(key)
-        get_client().clear(force=False)
+        keys_to_pop = [key for key in id_tasktype.keys() if key not in ids]
+        for key in keys_to_pop:
+            id_tasktype.pop(key)
+
         return Response(jobs_response)
 
     def create(self, request):
@@ -64,9 +64,9 @@ def destroy(self, request, pk=None):
 
     @list_route(methods=['post'])
     def startremoteimport(self, request):
-        '''Download a channel's database from the main curation server, and then
+        '''
+        Download a channel's database from the main curation server, and then
         download its content.
-
         '''
 
         if "channel_id" not in request.data:


Test patch:
Repository: learningequality/kolibri

Issue:
inconsistent French language label
Is there a reason that French has "langue française" after it?

![image](https://user-images.githubusercontent.com/2367265/29900327-09c9c1c6-8da6-11e7-8b55-06aa5753bcd5.png)





Discussion:
Pretty sure I got that from Django, but it would make sense to shorten it, certainly.

Resolving patch:
diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py
--- a/kolibri/deployment/default/settings/base.py
+++ b/kolibri/deployment/default/settings/base.py
@@ -147,7 +147,7 @@
     ('sw-tz', 'Kiswahili'),
     ('es-es', 'Español'),
     ('es-mx', 'Español (México)'),
-    ('fr-fr', 'Français, langue française'),
+    ('fr-fr', 'Français'),
     ('pt-pt', 'Português'),
     ('hi-in', 'हिंदी'),
 ]


Test patch:
Repository: learningequality/kolibri

Issue:
Detecting if a topic is a channel
## Summary

Currenty, we detect if a topic is a channel by checking that the `channel_id` and `pk` are equal. I ran into a channel where they are not equal. See 2nd channel in image below. Does this just need to be republished? Also, should we be just annotating channels as kind=channel in the models?

![image](https://user-images.githubusercontent.com/7193975/30656070-ab496d34-9de7-11e7-86d1-c27b27a669bb.png)


![image](https://user-images.githubusercontent.com/7193975/30656122-d5060c4a-9de7-11e7-909e-ff67890a4a5a.png)



Discussion:
If a node has `null` for `parent`, does that mean it's a channel?
Sounds right. 
Yes, this is a better test, as we are really looking at a root node. We may also want to just use the channel data instead, which,  in the database at least, has a base64 encoded thumbnail. 
I just did it this way to quickly reuse the existing grid. 
+1 on anything that helps grab the thumbnail

Resolving patch:
diff --git a/kolibri/content/serializers.py b/kolibri/content/serializers.py
--- a/kolibri/content/serializers.py
+++ b/kolibri/content/serializers.py
@@ -25,7 +25,7 @@ def to_representation(self, instance):
 
     class Meta:
         model = ChannelMetadata
-        fields = ('root', 'id', 'name', 'description', 'author', 'last_updated', 'version')
+        fields = ('root', 'id', 'name', 'description', 'author', 'last_updated', 'version', 'thumbnail')
 
 
 class LowerCaseField(serializers.CharField):


Test patch:
Repository: learningequality/kolibri

Issue:
Role still says 'Device Owner' in profile page

sign in as a superuser and click on 'Profile'

subtask of #2201



Discussion:

Resolving patch:
diff --git a/kolibri/auth/api.py b/kolibri/auth/api.py
--- a/kolibri/auth/api.py
+++ b/kolibri/auth/api.py
@@ -233,21 +233,23 @@ def get_session(self, request):
                    'user_id': user.id,
                    'can_manage_content': user.can_manage_content}
         roles = Role.objects.filter(user_id=user.id)
-        if len(roles) is not 0 or user.is_superuser:
+
+        if len(roles) is 0:
+            session.update({'facility_id': user.facility_id,
+                            'kind': ['learner'],
+                            'error': '200'})
+        else:
             session.update({'facility_id': user.facility_id,
                             'kind': [],
                             'error': '200'})
-            if user.is_superuser:
-                session['kind'].append('superuser')
             for role in roles:
                 if role.kind == 'admin':
                     session['kind'].append('admin')
-                else:
+                elif role.kind == 'coach':
                     session['kind'].append('coach')
-        else:
-            session.update({'facility_id': user.facility_id,
-                            'kind': ['learner'],
-                            'error': '200'})
+
+        if user.is_superuser:
+            session['kind'].insert(0, 'superuser')
 
         UserSessionLog.update_log(user)
 
diff --git a/kolibri/auth/serializers.py b/kolibri/auth/serializers.py
--- a/kolibri/auth/serializers.py
+++ b/kolibri/auth/serializers.py
@@ -43,7 +43,7 @@ class FacilityUserSerializer(BaseKolibriUserSerializer):
     class Meta:
         model = FacilityUser
         extra_kwargs = {'password': {'write_only': True}}
-        fields = ('id', 'username', 'full_name', 'password', 'facility', 'roles')
+        fields = ('id', 'username', 'full_name', 'password', 'facility', 'roles', 'is_superuser')
 
 
 class FacilityUsernameSerializer(serializers.ModelSerializer):
diff --git a/kolibri/logger/api.py b/kolibri/logger/api.py
--- a/kolibri/logger/api.py
+++ b/kolibri/logger/api.py
@@ -17,7 +17,7 @@ class BaseLogFilter(filters.FilterSet):
     classroom = filters.django_filters.MethodFilter()
     learner_group = filters.django_filters.MethodFilter()
 
-    # Only device owner (superuser) can filter by facilities
+    # Only a superuser can filter by facilities
     def filter_facility(self, queryset, value):
         return queryset.filter(user__facility_id=value)
 


Test patch:
Repository: learningequality/kolibri

Issue:
help text is unhelpful
descriptions of two types of deployments are exactly the same

![image](https://user-images.githubusercontent.com/2367265/30944677-503aa0da-a3ae-11e7-9624-2bb625f1d881.png)



Discussion:

Resolving patch:
diff --git a/kolibri/plugins/coach/api.py b/kolibri/plugins/coach/api.py
--- a/kolibri/plugins/coach/api.py
+++ b/kolibri/plugins/coach/api.py
@@ -86,6 +86,7 @@ class RecentReportViewSet(viewsets.ModelViewSet):
     serializer_class = ContentReportSerializer
 
     def get_queryset(self):
+        channel_id = self.kwargs['channel_id']
         attempted_mastery_logs = MasteryLog.objects.filter(attemptlogs__isnull=False)
         query_node = ContentNode.objects.get(pk=self.kwargs['content_node_id'])
         if self.request.query_params.get('last_active_time'):
@@ -101,13 +102,13 @@ def get_queryset(self):
             end_timestamp__gte=datetime_cutoff).values_list('content_id', flat=True)
         if connection.vendor == 'postgresql':
             pks_with_unique_content_ids = ContentNode.objects.order_by('content_id').distinct('content_id').filter(
-                content_id__in=recent_content_items).values_list('pk', flat=True)
+                channel_id=channel_id, content_id__in=recent_content_items).values_list('pk', flat=True)
         else:
             # note from rtibbles:
             # As good as either I or jamalex could come up with to ensure that we only return
             # unique content_id'ed ContentNodes from the coach recent report endpoint.
             # Would have loved to use distinct('content_id'), but unfortunately DISTINCT ON is Postgresql only
             pks_with_unique_content_ids = ContentNode.objects.filter(
-                content_id__in=recent_content_items).values('content_id').order_by('lft').annotate(
+                channel_id=channel_id, content_id__in=recent_content_items).values('content_id').order_by('lft').annotate(
                 pk=Min('pk')).values_list('pk', flat=True)
         return ContentNode.objects.filter(pk__in=pks_with_unique_content_ids).order_by('lft')


Test patch:
Repository: learningequality/kolibri

Issue:
on macos, default to --foreground
currently, daemonization doesn't work on macos. Until/unless we fix this, 

```
./kolibri.pex start
```

should behave the same as

```
./kolibri.pex start --foreground
```

on macos




Discussion:

Resolving patch:
diff --git a/kolibri/utils/cli.py b/kolibri/utils/cli.py
--- a/kolibri/utils/cli.py
+++ b/kolibri/utils/cli.py
@@ -624,7 +624,10 @@ def main(args=None):
     if arguments['start']:
         port = arguments['--port']
         port = int(port) if port else None
-        start(port, daemon=not arguments['--foreground'])
+        daemon = not arguments['--foreground']
+        if sys.platform == 'darwin':
+            daemon = False
+        start(port, daemon=daemon)
         return
 
     if arguments['stop']:


Test patch:
Repository: learningequality/kolibri

Issue:
end session after a period of time
## Summary
Automatic sign out form learner's Kolibri account when browser is closed or when tablet is powered off or after some stipulated time of no activity.

- The kids have the tendency to forget to sign out of their account:
- The kids when they continue from the next session they are already logged into their peers account and unknowingly start continue with the wrong account.
- The teachers don't have to give that extra instruction to students to sign out.
- The students, as they can directly close the browser or power off the tablet.

## System information
 - Version: 0.4.5
 - Operating system: Ubuntu 14.04LTS
 - Browser: Chrome 

## How to reproduce

1. Log in as a learner.
2. Power of the tablets.
3. Switch on and Access the Kolibri page.
4. You will be logged into previously logged learner account. 



Discussion:
We should add a session timeout so that when multiple students share a tablet, they don't share progress.

* Let's choose a reasonable default for now. Maybe 4 hours?
* ~The session should also end when the browser is closed.~ [not feasible]

We can explore making it configurable by the admins in a future release.

Note that closing the session on browser close was very difficult for us to do reliably in KA Lite, don't know if there is anything new that would help with it. 
> Note that closing the session on browser close was very difficult for us to do reliably in KA Lite, don't know if there is anything new that would help with it.

Yes, that makes sense. Typically, "clear session on browser close" is a browser setting, not something controlled by the web app. Will update.

Resolving patch:
diff --git a/kolibri/deployment/default/settings/base.py b/kolibri/deployment/default/settings/base.py
--- a/kolibri/deployment/default/settings/base.py
+++ b/kolibri/deployment/default/settings/base.py
@@ -319,3 +319,7 @@
 JS_REVERSE_EXCLUDE_NAMESPACES = ['admin', ]
 
 ENABLE_DATA_BOOTSTRAPPING = True
+
+SESSION_EXPIRE_AT_BROWSER_CLOSE = True
+
+SESSION_COOKIE_AGE = 300


Test patch: