internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: akvo/akvo-rsr

Issue:
Custom stylesheets for Akvo pages missing
The custom CSS that can be uploaded to an Akvo page site is currently not served.

This is due to the link to it accidentally being removed when the main stylesheet for RSR was supplemented with a second sheet for the new Results.


Discussion:

Resolving patch:
diff --git a/akvo/rsr/context_processors.py b/akvo/rsr/context_processors.py
--- a/akvo/rsr/context_processors.py
+++ b/akvo/rsr/context_processors.py
@@ -58,7 +58,7 @@ def extra_pages_context(request):
             'organisation': page.organisation,
             'return_url': page.return_url,
             'return_url_text': page.custom_return_url_text,
-            'stylesheet': page.stylesheet,
+            'page_stylesheet': page.stylesheet,
             'akvoapp_root_url': '//{}'.format(settings.AKVOAPP_DOMAIN),
             'domain_url': '//{}'.format(settings.RSR_DOMAIN),
             'no_facebook': not page.facebook_button,


Test patch:
Repository: akvo/akvo-rsr

Issue:
react-clickoutside doesn't close the date-picker on clicking outside
Created via Reamaze:

Link: https://akvoo.reamaze.com/admin/conversations/bug-10
Assignee: Anthony Gonzalez

React-clickoutside needs to load before the date-picker loads



Discussion:

Resolving patch:
diff --git a/akvo/rsr/context_processors.py b/akvo/rsr/context_processors.py
--- a/akvo/rsr/context_processors.py
+++ b/akvo/rsr/context_processors.py
@@ -58,7 +58,7 @@ def extra_pages_context(request):
             'organisation': page.organisation,
             'return_url': page.return_url,
             'return_url_text': page.custom_return_url_text,
-            'stylesheet': page.stylesheet,
+            'page_stylesheet': page.stylesheet,
             'akvoapp_root_url': '//{}'.format(settings.AKVOAPP_DOMAIN),
             'domain_url': '//{}'.format(settings.RSR_DOMAIN),
             'no_facebook': not page.facebook_button,


Test patch:
Repository: akvo/akvo-rsr

Issue:
Active filter should be kept when changing number of projects viewed
When changing the number of projects shown in the project directory, any filter that is in force should be "brought along".


Discussion:
@zzgvh This seems to be the case already. I couldn't reproduce the bug described here. Could you describe how to reproduce it? Thanks!
@zzgvh Have been able to reproduce this now, based on our conversation. Thanks!

Resolving patch:
diff --git a/akvo/rsr/views/project.py b/akvo/rsr/views/project.py
--- a/akvo/rsr/views/project.py
+++ b/akvo/rsr/views/project.py
@@ -128,6 +128,7 @@ def directory(request):
         'current_org': org_filter,
         'map_projects': map_projects,
         'sectors_dict': sectors_dict,
+        'limit': limit,
     }
     return render(request, 'project_directory.html', context)
 


Test patch:
Repository: akvo/akvo-rsr

Issue:
iati_status query parameter is still used on the site
The query parameter for status was changed from `iati_status` to `status` in #2681. But, the `iati_status` filter is being used in a bunch of places (for example on an organisation page - the link to projects). 

`iati_status` parameter needs to be brought back, and can be renamed to `status` when processing it. 


Discussion:

Resolving patch:
diff --git a/akvo/rsr/views/project.py b/akvo/rsr/views/project.py
--- a/akvo/rsr/views/project.py
+++ b/akvo/rsr/views/project.py
@@ -45,6 +45,10 @@ def directory(request):
     """The project list view."""
     qs = remove_empty_querydict_items(request.GET)
 
+    # iati_status was renamed to sector in fa8094647b
+    if 'status' not in qs:
+        qs['status'] = qs.pop('iati_status', [''])[0]
+
     # Set show_filters to "in" if any filter is selected
     show_filters = "in"  # To simplify template use bootstrap class
     available_filters = [


Test patch:
Repository: akvo/akvo-rsr

Issue:
List of reports not loading for some users
The reports page fetches user information from `/rest/v1/user/{id}` and this seems to be failing when the Country name of primary organisation is unicode. 

Created via Reamaze:

Link: https://akvoo.reamaze.com/admin/conversations/list-of-reports-not-loading





Discussion:
This is related to a bunch of other `str()` casting of objects, in a bunch of places. 

Resolving patch:
diff --git a/akvo/rest/views/user.py b/akvo/rest/views/user.py
--- a/akvo/rest/views/user.py
+++ b/akvo/rest/views/user.py
@@ -130,7 +130,7 @@ def request_organisation(request, pk=None):
         data = EmploymentSerializer(employment).data
         if data['country']:
             data['country_full'] = employment.iati_country().name
-            data['country_name'] = str(employment.iati_country())
+            data['country_name'] = unicode(employment.iati_country())
         else:
             data['country_full'] = ''
         data['organisation_full'] = OrganisationSerializer(organisation).data
diff --git a/akvo/rsr/models/employment.py b/akvo/rsr/models/employment.py
--- a/akvo/rsr/models/employment.py
+++ b/akvo/rsr/models/employment.py
@@ -76,7 +76,7 @@ def iati_country(self):
         return codelist_value(codelist_models.Country, self, 'country')
 
     def iati_country_unicode(self):
-        return str(self.iati_country())
+        return unicode(self.iati_country())
 
     def approve(self, approved_by):
         """


Test patch:
diff --git a/akvo/rsr/tests/rest/test_user.py b/akvo/rsr/tests/rest/test_user.py
--- a/akvo/rsr/tests/rest/test_user.py
+++ b/akvo/rsr/tests/rest/test_user.py
@@ -12,6 +12,7 @@
 from django.conf import settings
 from django.test import TransactionTestCase, Client
 
+from akvo.codelists.models import Country, Version
 from akvo.rsr.models import Employment, Organisation, User
 from akvo.utils import check_auth_groups
 
@@ -31,6 +32,13 @@ def setUp(self):
         self.user = self._create_user('abc@example.com', self.user_password)
         self.c.login(username=self.user.username, password=self.user_password)
 
+        version = Version.objects.create(code=settings.IATI_VERSION)
+        self.country = Country.objects.create(
+            code='CI',
+            name=u'CI - C\xc3\xb4te Divoire',
+            version=version
+        )
+
     def test_request_organisation_simple(self):
         # Given
         data = {'organisation': self.org.id}
@@ -48,7 +56,7 @@ def test_request_organisation_simple(self):
 
     def test_request_organisation_once(self):
         # Given
-        data = {'organisation': self.org.id, 'country': '', 'job_title': ''}
+        data = {'organisation': self.org.id, 'country': 'CI', 'job_title': ''}
         pk = self.user.id
 
         # When
Repository: akvo/akvo-rsr

Issue:
504 timeouts on the results framework page for project with lot of children and indicators



Discussion:

Resolving patch:
diff --git a/akvo/rest/views/indicator.py b/akvo/rest/views/indicator.py
--- a/akvo/rest/views/indicator.py
+++ b/akvo/rest/views/indicator.py
@@ -12,7 +12,12 @@
 class IndicatorViewSet(PublicProjectViewSet):
     """
     """
-    queryset = Indicator.objects.all()
+    queryset = Indicator.objects.all().select_related(
+        'result',
+        'result__project',
+    ).prefetch_related(
+        'child_indicators'
+    )
     serializer_class = IndicatorSerializer
     project_relation = 'result__project__'
 
@@ -20,6 +25,11 @@ class IndicatorViewSet(PublicProjectViewSet):
 class IndicatorFrameworkViewSet(PublicProjectViewSet):
     """
     """
-    queryset = Indicator.objects.all()
+    queryset = Indicator.objects.all().select_related(
+        'result',
+        'result__project',
+    ).prefetch_related(
+        'child_indicators'
+    )
     serializer_class = IndicatorFrameworkSerializer
     project_relation = 'result__project__'
diff --git a/akvo/rsr/models/indicator.py b/akvo/rsr/models/indicator.py
--- a/akvo/rsr/models/indicator.py
+++ b/akvo/rsr/models/indicator.py
@@ -196,7 +196,7 @@ def children_aggregate_percentage(self):
         """
         if self.measure == '2' and self.is_parent_indicator() and \
                 self.result.project.aggregate_children and \
-                any([ind.result.project.aggregate_to_parent for ind in self.child_indicators.all()]):
+                any(self.child_indicators.values_list('result__project__aggregate_to_parent', flat=True)):
             return True
         return False
 


Test patch:
Repository: akvo/akvo-rsr

Issue:
Add a command to "undo" results import
Some organizations would like to a results import for specific projects (probably because they were accidentally performed; See #2795).  Add a command for the developers to undo such imports


Discussion:

Resolving patch:
diff --git a/akvo/rsr/management/commands/undo_results_import.py b/akvo/rsr/management/commands/undo_results_import.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/management/commands/undo_results_import.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+
+# Akvo Reporting is covered by the GNU Affero General Public License.
+# See more details in the license.txt file located at the root folder of the Akvo RSR module.
+# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
+
+"""Undo results framework import for the specified projects
+
+Usage:
+
+    python manage.py undo_results_import <project-id1> [<project-id2> ...]
+
+"""
+
+import sys
+
+from django.core.management.base import BaseCommand
+from ...models import Result
+
+
+class Command(BaseCommand):
+    help = u"Undo results framework import for the specified projects"
+
+    def handle(self, *args, **options):
+        if not args:
+            print(__doc__)
+            sys.exit(1)
+
+        project_ids = map(int, args)
+
+        for id_ in project_ids:
+            results = Result.objects.filter(project__id=id_).exclude(parent_result=None)
+            print "Deleting {} results for project {}".format(results.count(), id_)
+            results.delete()


Test patch:
Repository: akvo/akvo-rsr

Issue:
UI tweaks for the Results framework
There are two small UI issues in the update form:

![screenshot_200](https://user-images.githubusercontent.com/142613/29261191-9262e060-80ce-11e7-953a-7e01df8e6902.png)

  * "says:" falls down to a new line even when there's space enough to keep it on the same line as the name.
  * If we remove "internal" from the internal notes input field the full text will be visible.


Discussion:

Resolving patch:
diff --git a/akvo/rsr/context_processors.py b/akvo/rsr/context_processors.py
--- a/akvo/rsr/context_processors.py
+++ b/akvo/rsr/context_processors.py
@@ -7,6 +7,7 @@
 < http://www.gnu.org/licenses/agpl.html >.
 """
 
+import re
 import django
 
 from django.conf import settings
@@ -27,6 +28,7 @@ def extra_context(request, protocol="http"):
     deploy_branch = getattr(settings, 'DEPLOY_BRANCH', 'Unknown')
     deploy_commit_id = getattr(settings, 'DEPLOY_COMMIT_ID', 'Unknown')
     deploy_commit_full_id = getattr(settings, 'DEPLOY_COMMIT_FULL_ID', 'Unknown')
+    sentry_dsn = get_sentry_dsn(settings)
 
     return dict(
         current_site=current_site,
@@ -35,10 +37,19 @@ def extra_context(request, protocol="http"):
         deploy_tag=deploy_tag,
         deploy_branch=deploy_branch,
         deploy_commit_id=deploy_commit_id,
-        deploy_commit_full_id=deploy_commit_full_id
+        deploy_commit_full_id=deploy_commit_full_id,
+        sentry_dsn=sentry_dsn,
     )
 
 
+def get_sentry_dsn(settings):
+    sentry_dsn = getattr(settings, 'RAVEN_CONFIG', {}).get('dsn', '')
+    sentry_dsn = re.sub('(:\w*?)@', '@', sentry_dsn)
+    # Always use https!
+    sentry_dsn = sentry_dsn.replace('http://', 'https://')
+    return sentry_dsn
+
+
 def get_current_path_without_lang(request):
     """Return current path without lang."""
     path = request.get_full_path()


Test patch:
Repository: akvo/akvo-rsr

Issue:
User permissions page should have roles ordered alphabetically in the drop-down
Roles are displayed in reverse alphabetical order in the User management page


Discussion:

Resolving patch:
diff --git a/akvo/rsr/views/my_rsr.py b/akvo/rsr/views/my_rsr.py
--- a/akvo/rsr/views/my_rsr.py
+++ b/akvo/rsr/views/my_rsr.py
@@ -487,11 +487,7 @@ def user_management(request):
         employments_array.append(employment_dict)
 
     organisations_list = list(organisations.values('id', 'name'))
-
-    roles_list = []
-    for role in roles:
-        roles_dict = {'id': role.id, 'name': role.name}
-        roles_list.append(roles_dict)
+    roles_list = list(roles.values('id', 'name').order_by('name'))
 
     context = {}
     if employments_array:


Test patch:
Repository: akvo/akvo-rsr

Issue:
Disaggregations set up in parent project are not inherited by children
When importing a Results framework into a child project, any disaggregations set up on the parent should be included in the import.


Discussion:

Resolving patch:
diff --git a/akvo/rsr/models/project.py b/akvo/rsr/models/project.py
--- a/akvo/rsr/models/project.py
+++ b/akvo/rsr/models/project.py
@@ -1324,6 +1324,15 @@ def add_result(self, result):
             self.add_indicator(child_result, indicator)
 
     def add_indicator(self, result, indicator):
+        """Add a new indicator to the result as a child of the specified indicator.
+
+        NOTE: There can only be one child for an indicator, per result. This
+        method automatically updates an existing child indicator, if present.
+
+        It also triggers the creation of periods, dimensions and references on
+        the indicator, if the indicator is being created and not updated.
+
+        """
         Indicator = get_model('rsr', 'Indicator')
         child_indicator, created = Indicator.objects.update_or_create(
             result=result,
@@ -1346,6 +1355,9 @@ def add_indicator(self, result, indicator):
         for reference in indicator.references.all():
             self.add_reference(child_indicator, reference)
 
+        for dimension in indicator.dimensions.all():
+            self.add_dimension(child_indicator, dimension)
+
     def add_period(self, indicator, period):
         """Add a new period to the indicator as a child of period.
 
@@ -1365,6 +1377,13 @@ def add_period(self, indicator, period):
         fields = ['target_value', 'target_comment', 'actual_comment']
         self._update_fields_if_not_child_updated(period, child_period, fields)
 
+    def add_dimension(self, indicator, dimension):
+        get_model('rsr', 'IndicatorDimension').objects.create(
+            indicator=indicator,
+            name=dimension.name,
+            value=dimension.value,
+        )
+
     def add_reference(self, indicator, reference):
         get_model('rsr', 'IndicatorReference').objects.create(
             indicator=indicator,


Test patch:
Repository: akvo/akvo-rsr

Issue:
Exclude data from qualitative indicators from IATI export files
The data for the qualitative indicators is currently included in the IATI export but should not be as IATI does not currently support qualitative indicators. 

Issue summarised in this support ticket: 

https://akvoo.reamaze.com/admin/conversations/qualitative-indicators


Discussion:

Resolving patch:
diff --git a/akvo/iati/exports/elements/result.py b/akvo/iati/exports/elements/result.py
--- a/akvo/iati/exports/elements/result.py
+++ b/akvo/iati/exports/elements/result.py
@@ -6,6 +6,8 @@
 
 from lxml import etree
 
+from akvo.rsr.models.result.utils import QUANTITATIVE
+
 
 def result(project):
     """
@@ -37,7 +39,7 @@ def result(project):
                 narrative_element = etree.SubElement(description_element, "narrative")
                 narrative_element.text = res.description
 
-            for indicator in res.indicators.all():
+            for indicator in res.indicators.filter(type=QUANTITATIVE):
                 if indicator.measure or indicator.ascending is not None or indicator.title or \
                         indicator.description or indicator.references.all() or \
                         indicator.baseline_year or indicator.baseline_value or \


Test patch:
diff --git a/akvo/rsr/tests/iati_export/test_iati_export.py b/akvo/rsr/tests/iati_export/test_iati_export.py
--- a/akvo/rsr/tests/iati_export/test_iati_export.py
+++ b/akvo/rsr/tests/iati_export/test_iati_export.py
@@ -18,6 +18,7 @@
                              IndicatorPeriodActualDimension, IndicatorPeriodActualLocation,
                              IndicatorPeriodTargetDimension, IndicatorPeriodTargetLocation,
                              IndicatorReference)
+from akvo.rsr.models.result.utils import QUALITATIVE
 
 from django.core.files.uploadedfile import SimpleUploadedFile
 from django.test import TestCase
@@ -410,6 +411,13 @@ def test_complete_project_export(self):
             baseline_value="1",
             baseline_comment="Comment"
         )
+        # Create a qualitative indicator
+        Indicator.objects.create(
+            result=result,
+            title="Qualitative indicator",
+            description="Indicator Description",
+            type=QUALITATIVE,
+        )
         IndicatorReference.objects.create(
             indicator=indicator,
             vocabulary="1",
@@ -495,6 +503,9 @@ def test_complete_project_export(self):
         indicators = root_test.xpath(indicator_description_xpath)
         self.assertEqual(indicators[0].text, 'Indicator Description')
 
+        # Test qualitative indicator is not included
+        self.assertEqual(1, len(indicators))
+
     def test_different_complete_project_export(self):
         """
         Test the export of a fully filled project with different settings.
Repository: akvo/akvo-rsr

Issue:
Trim disaggregation names and values
I looked at some disaggregation data in the Redux store and noted there are a number of records with leading or trailing spaces. Since groupings rely on exact matching of the strings I suggest we trim the strings on entry i.e. the project editor. Also as can be seen below there's a record without any values. We should try to prevent this too.

![screenshot_221](https://user-images.githubusercontent.com/142613/33078288-8007570a-ced2-11e7-8fe6-c3b8b2bfe7a1.png)



Discussion:

Resolving patch:
diff --git a/akvo/rest/views/project_editor.py b/akvo/rest/views/project_editor.py
--- a/akvo/rest/views/project_editor.py
+++ b/akvo/rest/views/project_editor.py
@@ -164,7 +164,7 @@ def pre_process_data(key, data, errors):
     # Text data does not need pre-processing
     if isinstance(model_field, (EmailField, ProjectLimitedTextField, URLField, ValidXMLCharField,
                                 ValidXMLTextField)):
-        return data, errors
+        return data.strip(), errors
 
     # Dates should be converted to a datetime object, or None if empty
     if isinstance(model_field, DateField):
diff --git a/akvo/rsr/migrations/0117_auto_20171201_0913.py b/akvo/rsr/migrations/0117_auto_20171201_0913.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/migrations/0117_auto_20171201_0913.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+def indicator_dimensions_cleanup(apps, schema_editor):
+    IndicatorDimension = apps.get_model('rsr', 'indicatordimension')
+    for dimension in IndicatorDimension.objects.all():
+        dimension.name = dimension.name.strip()
+        dimension.value = dimension.value.strip()
+        dimension.save()
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('rsr', '0116_auto_20171129_0731'),
+    ]
+
+    operations = [
+        migrations.RunPython(indicator_dimensions_cleanup,
+                             lambda x, y: None)
+    ]


Test patch:
Repository: akvo/akvo-rsr

Issue:
Adding a new period to parent results framework is super slow
You guessed it! Missing `select_related` calls, again. 


Discussion:

Resolving patch:
diff --git a/akvo/rsr/models/project.py b/akvo/rsr/models/project.py
--- a/akvo/rsr/models/project.py
+++ b/akvo/rsr/models/project.py
@@ -1366,7 +1366,10 @@ def add_period(self, indicator, period):
 
         """
         IndicatorPeriod = get_model('rsr', 'IndicatorPeriod')
-        child_period, created = IndicatorPeriod.objects.update_or_create(
+        child_period, created = IndicatorPeriod.objects.select_related(
+            'indicator',
+            'indicator__result',
+        ).update_or_create(
             indicator=indicator,
             parent_period=period,
             defaults=dict(
diff --git a/akvo/rsr/models/result/indicator_period.py b/akvo/rsr/models/result/indicator_period.py
--- a/akvo/rsr/models/result/indicator_period.py
+++ b/akvo/rsr/models/result/indicator_period.py
@@ -102,7 +102,12 @@ def save(self, *args, **kwargs):
 
         super(IndicatorPeriod, self).save(*args, **kwargs)
 
-        for child_indicator in self.indicator.child_indicators.all():
+        child_indicators = self.indicator.child_indicators.select_related(
+            'result',
+            'result__project',
+        )
+
+        for child_indicator in child_indicators.all():
             child_indicator.result.project.add_period(child_indicator, self)
 
         # If the actual value has changed, the period has a parent period and aggregations are on,


Test patch:
Repository: akvo/akvo-rsr

Issue:
createsuperuser is broken
The Django management command createsuperuser is broken. The reason for this is that in RSR's User model the email field is required.


Discussion:

Resolving patch:
diff --git a/akvo/rsr/models/user.py b/akvo/rsr/models/user.py
--- a/akvo/rsr/models/user.py
+++ b/akvo/rsr/models/user.py
@@ -50,7 +50,7 @@ def create_user(self, username, email, password=None, **extra_fields):
         return self._create_user(username, email, password, False, False, False, **extra_fields)
 
     def create_superuser(self, username, email, password, **extra_fields):
-        return self._create_user(username, email, password, True, True, False, **extra_fields)
+        return self._create_user(username, email, password, True, True, True, **extra_fields)
 
     def __getattr__(self, attr, *args):
         try:
@@ -102,7 +102,7 @@ class User(AbstractBaseUser, PermissionsMixin):
     objects = CustomUserManager()
 
     USERNAME_FIELD = 'username'
-    REQUIRED_FIELDS = []
+    REQUIRED_FIELDS = ['email', ]
 
     class Meta:
         app_label = 'rsr'


Test patch:
Repository: akvo/akvo-rsr

Issue:
Incorrect mandatory validation for qualitative indicators
The indicator measure for qualitative indicators is hidden, but the code checking for completion of sections doesn't ignore that field, and considers it mandatory.  


Discussion:

Resolving patch:
diff --git a/akvo/iati/checks/fields/results.py b/akvo/iati/checks/fields/results.py
--- a/akvo/iati/checks/fields/results.py
+++ b/akvo/iati/checks/fields/results.py
@@ -4,6 +4,8 @@
 # See more details in the license.txt file located at the root folder of the Akvo RSR module.
 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
 
+from akvo.rsr.models.result.utils import QUALITATIVE
+
 
 def results(project):
     """
@@ -32,7 +34,7 @@ def results(project):
             checks.append((u'error', u'result (id: %s) has no indicator(s)' % str(result.pk)))
 
         for indicator in result.indicators.all():
-            if not indicator.measure:
+            if indicator.type != QUALITATIVE and not indicator.measure:
                 all_checks_passed = False
                 checks.append((u'error', u'indicator (id: %s) has no measure specified' %
                                str(indicator.pk)))


Test patch: