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

Issue:
Bug in IATI checks for planned disbursements
## Test plan

GIVEN a project with a planned disbursement
WHEN the IATI checks are performed (MyRSR -> My IATI -> Select organisation -> Perform checks)
THEN the checks should not crash
## Issue description

There is a small bug in the IATI checks for planned disbursements, see http://sentry.support.akvo-ops.org/rsr/test/?url=http://rsr.test.akvo.org/rest/v1/project_iati_check/3522/.



Discussion:

Resolving patch:
diff --git a/akvo/iati/checks/v201.py b/akvo/iati/checks/v201.py
--- a/akvo/iati/checks/v201.py
+++ b/akvo/iati/checks/v201.py
@@ -434,7 +434,7 @@ def planned_disbursements(self):
         checks = []
 
         for pd in self.project.planned_disbursements.all():
-            if not pd.amount:
+            if not pd.value:
                 checks.append((u'error', u'planned disbursement (id: %s) has '
                                          u'no amount' % str(pd.pk)))
             if not pd.period_start:


Test patch:
Repository: akvo/akvo-rsr

Issue:
Partnerships with no organisations should not be allowed
## Test plan

GIVEN the project editor
WHEN the project has a funding partnership without an organisation
THEN an error should be displayed that the organisation field isn't filled in



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
@@ -757,10 +757,16 @@ def project_editor_step3(request, pk=None):
         if 'value-partner-' in key:
             partner_id = key.split('-', 2)[2]
 
-            partner, errors, rel_objects, new_object = check_related_object(
-                partner_id, 'partnership', Partnership, PARTNER_FIELDS, {'project': project}, data,
-                errors, rel_objects
-            )
+            # Custom validation for partnership.organisation
+            if data[key]:
+                partner, errors, rel_objects, new_object = check_related_object(
+                    partner_id, 'partnership', Partnership, PARTNER_FIELDS, {'project': project},
+                    data, errors, rel_objects
+                )
+            else:
+                errors.append({'name': key.replace('value-', ''),
+                               'error': u'%s' % _(u"Project partner can't be blank.")})
+                new_object, partner = None, None
 
             if new_object:
                 log_addition(partner, user)
diff --git a/akvo/rsr/migrations/0031_auto_20150825_1109.py b/akvo/rsr/migrations/0031_auto_20150825_1109.py
new file mode 100644
--- /dev/null
+++ b/akvo/rsr/migrations/0031_auto_20150825_1109.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('rsr', '0030_remove_partnership_partner_type'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='partnership',
+            name='organisation',
+            field=models.ForeignKey(related_name='partnerships', blank=False, to='rsr.Organisation', help_text='Select an organisation that is taking an active role in the project.', null=True, verbose_name='organisation'),
+            preserve_default=True,
+        ),
+    ]
diff --git a/akvo/rsr/models/partnership.py b/akvo/rsr/models/partnership.py
--- a/akvo/rsr/models/partnership.py
+++ b/akvo/rsr/models/partnership.py
@@ -84,7 +84,9 @@ class Partnership(models.Model):
 
     organisation = models.ForeignKey(
         'Organisation', verbose_name=_(u'organisation'), related_name='partnerships', null=True,
-        help_text=_(u'Select an organisation that is taking an active role in the project.'))
+        blank=False, help_text=_(u'Select an organisation that is taking an active role in the '
+                                 u'project.')
+    )
     project = models.ForeignKey('Project', verbose_name=_(u'project'), related_name='partnerships')
     iati_organisation_role = models.PositiveSmallIntegerField(
         u'Organisation role', choices=IATI_ROLES, db_index=True, null=True)


Test patch:
Repository: akvo/akvo-rsr

Issue:
Sector vocabulary saved value not updated
## Test plan

GIVEN the project editor
WHEN the sector vocabulary AND sector code are filled in
THEN the 'saved-value' attribute of the vocabulary should be correctly updated



Discussion:

Resolving patch:
diff --git a/akvo/rsr/models/sector.py b/akvo/rsr/models/sector.py
--- a/akvo/rsr/models/sector.py
+++ b/akvo/rsr/models/sector.py
@@ -6,8 +6,6 @@
 
 
 from django.db import models
-from django.db.models.signals import post_save
-from django.dispatch import receiver
 from django.core.validators import MaxValueValidator, MinValueValidator
 from django.utils.translation import ugettext_lazy as _
 
@@ -82,14 +80,3 @@ class Meta:
         app_label = 'rsr'
         verbose_name = _(u'sector')
         verbose_name_plural = _(u'sectors')
-
-@receiver(post_save, sender=Sector)
-def update_vocabulary(sender, **kwargs):
-    "Updates the vocabulary if not specified."
-    sector = kwargs['instance']
-    if not sector.vocabulary and sector.sector_code:
-        if len(sector.sector_code) == 3:
-            sector.vocabulary = '2'
-        elif len(sector.sector_code) == 5:
-            sector.vocabulary = '1'
-        sector.save()


Test patch:
Repository: akvo/akvo-rsr

Issue:
Can't add locations to update through REST API
## Test plan

GIVEN the Up app
WHEN the user tries to add an update
THEN this should not give a 400 error



Discussion:

Resolving patch:
diff --git a/akvo/rest/serializers/__init__.py b/akvo/rest/serializers/__init__.py
--- a/akvo/rest/serializers/__init__.py
+++ b/akvo/rest/serializers/__init__.py
@@ -40,6 +40,7 @@
 from .project_update import (ProjectUpdateSerializer,
                              ProjectUpdateExtraSerializer)
 from .project_update_location import (ProjectUpdateLocationSerializer,
+                                      ProjectUpdateLocationNestedSerializer,
                                       MapProjectUpdateLocationSerializer)
 from .publishing_status import PublishingStatusSerializer
 from .recipient_country import RecipientCountrySerializer
@@ -93,6 +94,7 @@
     'ProjectSerializer',
     'ProjectUpdateExtraSerializer',
     'ProjectUpdateLocationSerializer',
+    'ProjectUpdateLocationNestedSerializer',
     'ProjectUpdateSerializer',
     'ProjectUpSerializer',
     'PublishingStatusSerializer',
diff --git a/akvo/rest/serializers/project_update.py b/akvo/rest/serializers/project_update.py
--- a/akvo/rest/serializers/project_update.py
+++ b/akvo/rest/serializers/project_update.py
@@ -8,7 +8,7 @@
 from rest_framework import serializers
 from akvo.rsr.models import ProjectUpdate
 from ..fields import Base64ImageField
-from .project_update_location import (ProjectUpdateLocationSerializer,
+from .project_update_location import (ProjectUpdateLocationNestedSerializer,
                                       ProjectUpdateLocationExtraSerializer)
 from .rsr_serializer import BaseRSRSerializer
 from .user import UserSerializer
@@ -18,8 +18,8 @@ class ProjectUpdateSerializer(BaseRSRSerializer):
 
     """Serializer for project updates."""
 
-    locations = ProjectUpdateLocationSerializer(source='locations', many=True, required=False,
-                                                allow_add_remove=True)
+    locations = ProjectUpdateLocationNestedSerializer(source='locations', many=True, required=False,
+                                                      allow_add_remove=True)
     photo = Base64ImageField(required=False, allow_empty_file=True)
 
     class Meta:
diff --git a/akvo/rest/serializers/project_update_location.py b/akvo/rest/serializers/project_update_location.py
--- a/akvo/rest/serializers/project_update_location.py
+++ b/akvo/rest/serializers/project_update_location.py
@@ -16,6 +16,14 @@ class Meta:
         model = ProjectUpdateLocation
 
 
+class ProjectUpdateLocationNestedSerializer(ProjectUpdateLocationSerializer):
+
+    class Meta(ProjectUpdateLocationSerializer.Meta):
+        # Exclude the mandatory 'location_target' field, so that it is possible to create a
+        # project update location at the same time as the project update.
+        exclude = ('location_target',)
+
+
 class ProjectUpdateLocationExtraSerializer(ProjectUpdateLocationSerializer):
 
     # Limit update data to its PK, this is needed because of Meta.depth = 2


Test patch:
Repository: akvo/akvo-rsr

Issue:
Small project editor bugs
## Test plan

GIVEN the project editor

WHEN changing the photo caption or credit
AND saving the first section
THEN the alert showing 'unsaved changes in section 1' should not be displayed when moving away from the page

WHEN clicking the 'Delete photo' link
THEN the photo should be deleted

WHEN changing the project status
THEN the `ReferenceError: toggleDonateButton is not defined` should not be shown in the console
## Issue description

After changing the photo caption or credit and saving section 1, the editor still indicates that there are unsaved changes in the first section.

In addition, the "Delete photo" button does not work and sometimes this error comes up: `ReferenceError: toggleDonateButton is not defined`



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
@@ -467,7 +467,7 @@ def log_changes(changes, user, project):
         field_changes = []
         for change in changes:
             for fields in change[1]:
-                if not ('photo' in fields[1] or 'document-document-' in fields[1]):
+                if not (fields[1] == 'photo' or 'document-document-' in fields[1]):
                     field_changes.append([fields[1], fields[2]])
 
         return field_changes


Test patch:
Repository: akvo/akvo-rsr

Issue:
Filter on project id in typeaheads
In addition to the project name, it should also be possible to filter on the project id in the typeaheads of the project editor.



Discussion:
Would it be acceptable for the ID to appear in brackets after the project name? E.g. `My Test Project (61)` or possibly `My Test Project (ID: 61)`

Yup, definitely (right @lauraroverts?). I would personally go for the latter `My Test Project (ID: 61)`


Resolving patch:
diff --git a/akvo/rest/serializers/typeahead.py b/akvo/rest/serializers/typeahead.py
--- a/akvo/rest/serializers/typeahead.py
+++ b/akvo/rest/serializers/typeahead.py
@@ -30,7 +30,7 @@ class Meta:
         fields = (
             'id',
             'name',
-            # 'long_name',
+            'long_name',
         )
 
 
diff --git a/akvo/rest/views/typeahead.py b/akvo/rest/views/typeahead.py
--- a/akvo/rest/views/typeahead.py
+++ b/akvo/rest/views/typeahead.py
@@ -51,7 +51,7 @@ def typeahead_reporting_organisation(request):
 
 @api_view(['GET'])
 def typeahead_project(request):
-    projects = Project.objects.published()
+    projects = Project.objects.all().exclude(title='')
     return Response(
         rejig(projects, TypeaheadProjectSerializer(projects, many=True))
     )


Test patch:
Repository: akvo/akvo-rsr

Issue:
API endpoint to get server information/configuration needed.
AN API endpoint that would return server settings would be useful for:
- Getting the setting for update edit grace period.
- Getting a server description string ("Production server", "Test server" etc)
- Verifying that there is a working API on the server. (For Up, verifying that the user has spelled the server URL right)
  Other data items could be added over time.



Discussion:

Resolving patch:
diff --git a/akvo/rest/urls.py b/akvo/rest/urls.py
--- a/akvo/rest/urls.py
+++ b/akvo/rest/urls.py
@@ -93,6 +93,7 @@
     url(r'^project_iati_check/(?P<pk>[0-9]+)/$',
         views.ProjectIatiCheckView.as_view(),
         name='project_iati_check'),
+    url(r'^server_info/$', views.server_info, name='server_info'),
 )
 
 # Project editor
diff --git a/akvo/rest/views/__init__.py b/akvo/rest/views/__init__.py
--- a/akvo/rest/views/__init__.py
+++ b/akvo/rest/views/__init__.py
@@ -59,6 +59,7 @@
 from .region import RecipientRegionViewSet
 from .result import ResultViewSet
 from .sector import SectorViewSet
+from .server_info import server_info
 from .transaction import TransactionViewSet, TransactionSectorViewSet
 from .typeahead import (typeahead_country,
                         typeahead_organisation,
@@ -131,6 +132,7 @@
     'request_organisation',
     'ResultViewSet',
     'SectorViewSet',
+    'server_info',
     'set_group',
     'TransactionViewSet',
     'TransactionSectorViewSet',
diff --git a/akvo/rest/views/server_info.py b/akvo/rest/views/server_info.py
new file mode 100644
--- /dev/null
+++ b/akvo/rest/views/server_info.py
@@ -0,0 +1,29 @@
+# -*- 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 >.
+
+import socket
+
+from django.conf import settings
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+
+
+@api_view(['GET',])
+def server_info(request):
+    """ Info about the server.
+        Used by RSR Up.
+    """
+    # tuple with settings we want exposed in the endpoint
+    server_settings = (
+        "PROJECT_UPDATE_TIMEOUT",
+        "DEPLOY_TAG",
+        "DEPLOY_BRANCH",
+        "DEPLOY_COMMIT_ID",
+    )
+    settings_dict = {'CANONICAL_HOST_NAME': socket.gethostname()}
+    for setting in server_settings:
+        settings_dict[setting] = getattr(settings, setting, "")
+    return Response(settings_dict)


Test patch:
Repository: akvo/akvo-rsr

Issue:
Show all projects in MyRSR for superusers and RSR admins
## Test plan
1. **Superusers or RSR admins**
   1. Login as a superuser or RSR admin
   2. Go to MyRSR -> My projects
   3. All projects should be shown
2. **Organisation admins or project editors**
   1. Login as an organisation admin or project editor
   2. Go to MyRSR -> My projects
   3. Only the projects of which the user is admin or project editor should be shown
## Issue description

Since superusers or RSR admins are able to edit any projects, they should also be able to see all projects in the project list on the 'My projects' page of MyRSR.



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
@@ -112,10 +112,14 @@ def my_updates(request):
 def my_projects(request):
     """Directory of Projects connected to the user."""
     organisations = request.user.employers.approved().organisations()
-    projects = organisations.all_projects().distinct().select_related(
-        'publishingstatus',
-        'primary_location__country',
-    )
+
+    if request.user.is_superuser or request.user.is_admin:
+        projects = Project.objects.all()
+    else:
+        projects = organisations.all_projects().distinct().select_related(
+            'publishingstatus',
+            'primary_location__country',
+        )
 
     new_project_custom_fields = OrganisationCustomField.objects.filter(
         organisation__in=organisations


Test patch:
Repository: akvo/akvo-rsr

Issue:
No reporting organisation with multiple employments
## Test plan
1. Login with a user that is connected to multiple organisations that have 'Reportable' set to True.
2. Add a new project.
3. One of the reportable organisations should be filled in as the reporting organisation of the project.
## Issue description

This part of code isn't finished yet: https://github.com/akvo/akvo-rsr/blob/develop/akvo/rsr/static/scripts-src/my-projects.js#L135

This causes problems when an organisation admin adds a project, but has more than 1 employment. In that case, no reporting organisation is attached, so that means that the organisation admin is not allowed to edit the project.



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
@@ -135,6 +135,13 @@ def my_projects(request):
     page = request.GET.get('page')
     page, paginator, page_range = pagination(page, projects, 10)
 
+    # User's organisations that are reportable
+    approved_employments = request.user.approved_employments()
+    reportable_organisations = []
+    for employment in approved_employments:
+        if employment.organisation.can_become_reporting:
+            reportable_organisations.append(employment.organisation.id)
+
     context = {
         'organisations': organisations,
         'new_project_custom_fields': new_project_custom_fields,
@@ -143,6 +150,7 @@ def my_projects(request):
         'page_range': page_range,
         'q': filter_query_string(qs),
         'q_search': q,
+        'reportable_organisations': reportable_organisations
     }
     return render(request, 'myrsr/my_projects.html', context)
 


Test patch:
Repository: akvo/akvo-rsr

Issue:
MyRSR search malfunction
## Test plan
1. Go to the User Management page
2. Search for an organisation
3. All users of the organisation should be returned (if the user has permission to view the user's employment)
## Issue description

In MyRSR user management it is not clear how the searchbox is searching for. Does it provide results for email address? Or for email + first name + last name etc? Is it searching for results at the first page? Or at all pages? 

If I search for 'Cordaid' it gives me 5 users, while there are certainly more users. 

If I search for 'Akvo' it tells me there are 23 users. At the first page I see 10 Akvo users. When I click through to the next page, it seems that the search selection Akvo has disappeared and I see all 227 pages of users again. 



Discussion:
I'll check this out to be sure, but from the top of my head the MyRSR user management searches for email, first name and last name.

`If I search for 'Akvo' it tells me there are 23 users. At the first page I see 10 Akvo users. When I click through to the next page, it seems that the search selection Akvo has disappeared and I see all 227 pages of users again.`

This was fixed in the last release (see #1560).

@lauraroverts Not sure what to do with this one. It searches for first name, last name and email address and everything seems to work as intended (probably also due to the fixes in #1560).

This is solved indeed: If I search for 'Akvo' it tells me there are 23 users. At the first page I see 10 Akvo users. When I click through to the next page, it seems that the search selection Akvo has disappeared and I see all 227 pages of users again.

But still, when I search for Cordaid it only gives me 5 names. It makes sense to also make it possible to search for organisation. Now it doesn't. 

Ah, yeah.. We can add that easily.


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
@@ -378,7 +378,9 @@ def user_management(request):
         for q_item in q_list:
             employments = employments.filter(user__username__icontains=q_item) | \
                 employments.filter(user__first_name__icontains=q_item) | \
-                employments.filter(user__last_name__icontains=q_item)
+                employments.filter(user__last_name__icontains=q_item) | \
+                employments.filter(organisation__name__icontains=q_item) | \
+                employments.filter(organisation__long_name__icontains=q_item)
 
     qs = remove_empty_querydict_items(request.GET)
     page = request.GET.get('page')


Test patch:
Repository: akvo/akvo-rsr

Issue:
IATI import
## Test plan
1. Take any IATI file from the [IATI registry](http://iatiregistry.org)
2. Make sure the reporting organisation is in RSR, with the correct IATI Organisation ID and 'Reportable' set to True.
3. In the old admin, add a new IATI import. Either fill in an external URL, or a local file. The user that is selected will get an email with a summary of the import. _Note that for larger files (e.g. > 100 projects), you might see a timeout. However, the import should continue to run in the background._
4. When the import is done, it should show up with status completed, and the mail with import details should have been sent. _Note that files up to 100 projects take about half a minute._
## Issue description

See product design repository: https://github.com/akvo/akvo-product-design/issues/97



Discussion:

Resolving patch:
diff --git a/akvo/rsr/migrations/0032_auto_20151001_0956.py b/akvo/rsr/migrations/0032_auto_20151001_0956.py
--- a/akvo/rsr/migrations/0032_auto_20151001_0956.py
+++ b/akvo/rsr/migrations/0032_auto_20151001_0956.py
@@ -116,4 +116,10 @@ class Migration(migrations.Migration):
             field=models.DecimalField(decimal_places=2, max_digits=14, blank=True, help_text='Enter the transaction amount.', null=True, verbose_name='value'),
             preserve_default=True,
         ),
+        migrations.AlterField(
+            model_name='project',
+            name='iati_activity_id',
+            field=akvo.rsr.fields.ValidXMLCharField(null=True, max_length=100, blank=True, help_text='This should be the official unique IATI Identifier for the project. The identifier consists of the IATI organisation identifier and the (organisations internal) project identifier, e.g. NL-KVK-31156201-TZ1234. (100 characters)<br>Note that \'projects\' in this form are the same as \'activities\' in IATI.<br><a href="http://iatistandard.org/activity-standard/iati-activities/iati-activity/iati-identifier" target="_blank">How to create</a>', verbose_name='IATI Project Identifier', db_index=True),
+            preserve_default=True,
+        ),
     ]


Test patch:
Repository: akvo/akvo-rsr

Issue:
Filtering Projects by title behaviour is odd
## Test plan
1. In the project editor, add a leading or trailing space to the project title or subtitle
2. Save section
3. Reload page or visit project page
4. There should not be any leading or trailing spaces
## Issue description

I'm not sure if it's related to #1338 or not, but the sort by title on project listings doesn't seem to be working as expected. See here:

http://rsr.uat.akvo.org/projects/?page=1&sort_by=-title



Discussion:
The problem lies in the data. Try http://rsr.uat.akvo.org/projects/?page=1&sort_by=title to get sorted A-Z. The fist projects (as of this writing) are 2531, 317 and 2118 all of which have a leading space in their titles! After that we have a project with a leading **'** and then follow a number of projects with an integer as the first char of the title.

So it works as intended :stuck_out_tongue: 

On a more serious note, we can create fix the three (or so, dunno if there's more on live) projects with leading spaces and then add form validation forbidding leading spaces. After that it becomes somewhat tricky. You can sort using regexp_replace() ([see here](http://stackoverflow.com/questions/12965463/humanized-or-natural-number-sorting-of-mixed-word-and-number-strings)) but it's not trivial to write a good regex and I have no idea of the performance impact of it. I think it's possible to create an index using similar technique but that feels like an even deeper rabbit hole.

I would suggest a quick fix: strip all leading spaces for titles of existing projects and add a validation on the project model.


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
@@ -323,6 +323,16 @@ def clean(self):
                                               u'time than end date (actual).')}
             )
 
+    def save(self, *args, **kwargs):
+        """Strip the title and subtitle from any leading or trailing spaces."""
+        if self.title:
+            self.title = self.title.strip()
+
+        if self.subtitle:
+            self.subtitle = self.subtitle.strip()
+
+        super(Project, self).save(*args, **kwargs)
+
     @models.permalink
     def get_absolute_url(self):
         return ('project-main', (), {'project_id': self.pk})


Test patch: