We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Move to IATI currencies
Currently, there's only 2 options for a currency in RSR: Euros and US Dollars. However, with the introduction of IATI fields we have also incorporated the IATI codelists for some fields that allow the list of IATI currencies including all possible currencies. We should extend the currencies of RSR, keeping in mind:
- [x] Project editor should allow to select all possible currencies and display it for any 'currency' field.
- [x] Show the currency code (e.g. EUR, USD, YEN) everywhere:
  - [x] Projects list
  - [x] Project page (summary, full report and finance tabs)
  - [x] Organisation page
- [x] All fields in the project editor should respond to the currency selection. When you switch to a different currency, this should happen for all fields that use a currency in the editor.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `akvo/rsr/models/partnership.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 # Akvo RSR is covered by the GNU Affero General Public License.
4 # See more details in the license.txt file located at the root folder of the Akvo RSR module.
5 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
6 
7 
8 from django.core.exceptions import ValidationError
9 from django.db import models
10 from django.utils.translation import ugettext_lazy as _
11 
12 from ..fields import ValidXMLCharField
13 
14 
15 class Partnership(models.Model):
16     # the old way
17     FIELD_PARTNER = u'field'
18     FUNDING_PARTNER = u'funding'
19     SPONSOR_PARTNER = u'sponsor'
20     SUPPORT_PARTNER = u'support'
21     EXTENDING_PARTNER = u'extending'
22 
23     PARTNER_TYPE_LIST = [
24         FIELD_PARTNER, FUNDING_PARTNER, SPONSOR_PARTNER, SUPPORT_PARTNER, EXTENDING_PARTNER
25     ]
26     PARTNER_LABELS = [
27         _(u'Implementing partner'),
28         _(u'Funding partner'),
29         _(u'Sponsor partner'),
30         _(u'Accountable partner'),
31         _(u'Extending partner'),
32     ]
33     PARTNER_TYPES = zip(PARTNER_TYPE_LIST, PARTNER_LABELS)
34 
35     # the new way
36     IATI_FUNDING_PARTNER = 1
37     IATI_ACCOUNTABLE_PARTNER = 2
38     IATI_EXTENDING_PARTNER = 3
39     IATI_IMPLEMENTING_PARTNER = 4
40     AKVO_SPONSOR_PARTNER = 100   # not part of the IATI OrganisationRole codelist!
41     IATI_REPORTING_ORGANISATION = 101
42 
43     # make sure the AKVO_SPONSOR_PARTNER is last in the list
44     IATI_ROLE_LIST = [
45         IATI_FUNDING_PARTNER, IATI_ACCOUNTABLE_PARTNER, IATI_EXTENDING_PARTNER,
46         IATI_IMPLEMENTING_PARTNER, AKVO_SPONSOR_PARTNER, IATI_REPORTING_ORGANISATION
47     ]
48     IATI_ROLE_LABELS = [
49         _(u'Funding partner'),
50         _(u'Accountable partner'),
51         _(u'Extending partner'),
52         _(u'Implementing partner'),
53         _(u'Sponsor partner'),
54         _(u'Reporting organisation'),
55     ]
56     IATI_ROLES = zip(IATI_ROLE_LIST, IATI_ROLE_LABELS)
57 
58     # used when migrating
59     PARTNER_TYPES_TO_ROLES_MAP = {
60         FUNDING_PARTNER: IATI_FUNDING_PARTNER,
61         SUPPORT_PARTNER: IATI_ACCOUNTABLE_PARTNER,
62         FIELD_PARTNER: IATI_IMPLEMENTING_PARTNER,
63         SPONSOR_PARTNER: AKVO_SPONSOR_PARTNER,
64     }
65 
66     # backwards compatibility
67     ROLES_TO_PARTNER_TYPES_MAP = {
68         IATI_FUNDING_PARTNER: FUNDING_PARTNER,
69         IATI_ACCOUNTABLE_PARTNER: SUPPORT_PARTNER,
70         IATI_EXTENDING_PARTNER: EXTENDING_PARTNER,
71         IATI_IMPLEMENTING_PARTNER: FIELD_PARTNER,
72         AKVO_SPONSOR_PARTNER: SPONSOR_PARTNER,
73         # TODO: not backwards compatible
74         IATI_REPORTING_ORGANISATION: u''
75     }
76 
77     ALLIANCE_PARTNER = u'alliance'
78     KNOWLEDGE_PARTNER = u'knowledge'
79     NETWORK_PARTNER = u'network'
80 
81     PARTNER_TYPE_EXTRAS_LIST = (ALLIANCE_PARTNER, KNOWLEDGE_PARTNER, NETWORK_PARTNER)
82     PARTNER_TYPE_EXTRA_LABELS = (
83         _(u'Alliance'),
84         _(u'Knowledge'),
85         _(u'Network')
86     )
87 
88     PARTNER_TYPE_EXTRAS = zip(PARTNER_TYPE_EXTRAS_LIST, PARTNER_TYPE_EXTRA_LABELS)
89 
90     organisation = models.ForeignKey(
91         'Organisation', verbose_name=_(u'organisation'), related_name='partnerships', null=True,
92         blank=True,
93         help_text=_(u'Select an organisation that is taking an active role in the project.')
94     )
95     project = models.ForeignKey('Project', verbose_name=_(u'project'), related_name='partnerships')
96     iati_organisation_role = models.PositiveSmallIntegerField(
97         _(u'organisation role'), choices=IATI_ROLES, db_index=True, null=True, blank=True,
98         help_text=_(u'Select the role of the organisation within the project:<br/>'
99                     u'- Funding organisation: a government or organisation that provides funds to '
100                     u'the project<br/>'
101                     u'- Implementing organisation: an organisation involved in carrying out the '
102                     u'activity or intervention<br/>'
103                     u'- Accountable organisation: an organisation responsible for oversight of '
104                     u'the project and its outcomes<br/>'
105                     u'- Extending organisation: an organisation that manages the budget and '
106                     u'direction of a project on behalf of the funding organisation<br/>'
107                     u'- Reporting organisation: an organisation that will report this project in '
108                     u'an IATI file')
109     )
110     # is_secondary_reporter is only used when the iati_organisation_role is set to
111     # IATI_REPORTING_ORGANISATION, thus the use of NullBooleanField
112     is_secondary_reporter = models.NullBooleanField(
113         _(u'secondary reporter'),
114         help_text=_(
115             u'This indicates whether the reporting organisation is a secondary publisher: '
116             u'publishing data for which it is not directly responsible.'
117         )
118     )
119     funding_amount = models.DecimalField(
120         _(u'funding amount'), max_digits=14, decimal_places=2, blank=True, null=True, db_index=True,
121         help_text=_(u'It’s only possible to indicate a funding amount for funding partners. Use a '
122                     u'period to denote decimals.')
123     )
124     partner_type_extra = ValidXMLCharField(
125         _(u'partner type extra'), max_length=30, blank=True, null=True, choices=PARTNER_TYPE_EXTRAS,
126         help_text=_(u'RSR specific partner type.')
127     )
128     iati_activity_id = ValidXMLCharField(
129         _(u'IATI activity ID'), max_length=100, blank=True, null=True, db_index=True,
130         help_text=_(u'A valid activity identifier published by the participating organisation '
131                     u'which points to the activity that it has published to IATI that describes '
132                     u'its role in this activity.')
133     )
134     internal_id = ValidXMLCharField(
135         _(u'Internal ID'), max_length=75, blank=True, null=True, db_index=True,
136         help_text=_(u'This field can be used to indicate an internal identifier that is used by '
137                     u'the organisation for this project. (75 characters)')
138     )
139     iati_url = models.URLField(
140         blank=True,
141         help_text=_(
142             u'Please enter the URL for where the IATI Activity Id Funding details are published. '
143             u'For projects directly or indirectly funded by the Dutch Government, this should '
144             u'be the OpenAid.nl page. For other projects, an alternative URL can be used.'
145         )
146     )
147     related_activity_id = ValidXMLCharField(
148         _(u'related IATI activity ID'), max_length=100, blank=True
149     )
150 
151     def iati_organisation_role_label(self):
152         if self.iati_organisation_role:
153             return dict(self.IATI_ROLES).get(self.iati_organisation_role)
154         else:
155             return ''
156 
157     def iati_role_to_partner_type(self):
158         if self.iati_organisation_role:
159             return dict(self.ROLES_TO_PARTNER_TYPES_MAP).get(int(self.iati_organisation_role))
160         else:
161             return None
162 
163     def organisation_show_link(self):
164         if self.organisation:
165             return u'<a href="{0}">{1}</a>'.format(self.organisation.get_absolute_url(),
166                                                    self.organisation.long_name or
167                                                    self.organisation.name)
168         return ''
169 
170     class Meta:
171         app_label = 'rsr'
172         verbose_name = _(u'project partner')
173         verbose_name_plural = _(u'project partners')
174         ordering = ['iati_organisation_role']
175 
176     def __unicode__(self):
177         if self.organisation:
178             if self.organisation.name:
179                 organisation_unicode = self.organisation.name
180             elif self.organisation.long_name:
181                 organisation_unicode = self.organisation.long_name
182             else:
183                 organisation_unicode = u'%s' % _(u'Organisation name not specified')
184         else:
185             organisation_unicode = u'%s' % _(u'Organisation not specified')
186 
187         if self.iati_organisation_role:
188             organisation_unicode += u' ({})'.format(
189                 unicode(dict(self.IATI_ROLES)[self.iati_organisation_role])
190             )
191         return organisation_unicode
192 
193     def clean(self):
194         # Don't allow multiple reporting organisations
195         if self.iati_organisation_role == self.IATI_REPORTING_ORGANISATION:
196             reporting_orgs = self.project.partnerships.filter(
197                 iati_organisation_role=self.IATI_REPORTING_ORGANISATION
198             )
199 
200             if reporting_orgs.count() > 1:
201                 raise ValidationError(
202                     {'iati_organisation_role': u'%s' % _(u'Project can only have one reporting '
203                                                          u'organisation')}
204                 )
205 
206     def save(self, *args, **kwargs):
207         super(Partnership, self).save(*args, **kwargs)
208         self.set_primary_organisation()
209 
210     def delete(self, *args, **kwargs):
211         super(Partnership, self).delete(*args, **kwargs)
212         self.set_primary_organisation()
213 
214     def set_primary_organisation(self):
215         # Check which organisation should be set to the primary organisation of the project
216         # This is done to get better performance on the project list page
217         self.project.primary_organisation = self.project.find_primary_organisation()
218         self.project.save(update_fields=['primary_organisation'])
219
```

Path: `akvo/rest/serializers/partnership.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 # Akvo RSR is covered by the GNU Affero General Public License.
4 # See more details in the license.txt file located at the root folder of the Akvo RSR module.
5 # For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
6 
7 from rest_framework import serializers
8 
9 from akvo.rsr.models import Partnership
10 
11 from akvo.rest.serializers.organisation import OrganisationBasicSerializer
12 from akvo.rest.serializers.rsr_serializer import BaseRSRSerializer
13 
14 
15 class PartnershipRawSerializer(BaseRSRSerializer):
16 
17     class Meta:
18         model = Partnership
19 
20 
21 class PartnershipSerializer(PartnershipRawSerializer):
22 
23     organisation_show_link = serializers.Field(source='organisation_show_link')
24     partner_type = serializers.Field(source='iati_role_to_partner_type')
25     organisation_role_label = serializers.Field(source='iati_organisation_role_label')
26 
27 
28 class PartnershipBasicSerializer(BaseRSRSerializer):
29 
30     organisation = OrganisationBasicSerializer(source='organisation')
31     iati_organisation_role_label = serializers.Field(source='iati_organisation_role_label')
32 
33     class Meta:
34         model = Partnership
35         fields = (
36             'id',
37             'project',
38             'organisation',
39             'iati_organisation_role',
40             'iati_organisation_role_label',
41         )
42
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/akvo/rest/serializers/partnership.py b/akvo/rest/serializers/partnership.py
--- a/akvo/rest/serializers/partnership.py
+++ b/akvo/rest/serializers/partnership.py
@@ -23,6 +23,7 @@
     organisation_show_link = serializers.Field(source='organisation_show_link')
     partner_type = serializers.Field(source='iati_role_to_partner_type')
     organisation_role_label = serializers.Field(source='iati_organisation_role_label')
+    funding_amount_label = serializers.Field(source='funding_amount_with_currency')
 
 
 class PartnershipBasicSerializer(BaseRSRSerializer):
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
@@ -167,6 +167,12 @@
                                                    self.organisation.name)
         return ''
 
+    def funding_amount_with_currency(self):
+        """Returns the funding amount, prepended by the project's currency."""
+        if self.funding_amount and self.project and self.project.currency:
+            return u'{0} {1}'.format(self.project.currency, self.funding_amount)
+        return self.funding_amount
+
     class Meta:
         app_label = 'rsr'
         verbose_name = _(u'project partner')

{"golden_diff": "diff --git a/akvo/rest/serializers/partnership.py b/akvo/rest/serializers/partnership.py\n--- a/akvo/rest/serializers/partnership.py\n+++ b/akvo/rest/serializers/partnership.py\n@@ -23,6 +23,7 @@\n     organisation_show_link = serializers.Field(source='organisation_show_link')\n     partner_type = serializers.Field(source='iati_role_to_partner_type')\n     organisation_role_label = serializers.Field(source='iati_organisation_role_label')\n+    funding_amount_label = serializers.Field(source='funding_amount_with_currency')\n \n \n class PartnershipBasicSerializer(BaseRSRSerializer):\ndiff --git a/akvo/rsr/models/partnership.py b/akvo/rsr/models/partnership.py\n--- a/akvo/rsr/models/partnership.py\n+++ b/akvo/rsr/models/partnership.py\n@@ -167,6 +167,12 @@\n                                                    self.organisation.name)\n         return ''\n \n+    def funding_amount_with_currency(self):\n+        \"\"\"Returns the funding amount, prepended by the project's currency.\"\"\"\n+        if self.funding_amount and self.project and self.project.currency:\n+            return u'{0} {1}'.format(self.project.currency, self.funding_amount)\n+        return self.funding_amount\n+\n     class Meta:\n         app_label = 'rsr'\n         verbose_name = _(u'project partner')\n", "issue": "Move to IATI currencies\nCurrently, there's only 2 options for a currency in RSR: Euros and US Dollars. However, with the introduction of IATI fields we have also incorporated the IATI codelists for some fields that allow the list of IATI currencies including all possible currencies. We should extend the currencies of RSR, keeping in mind:\n- [x] Project editor should allow to select all possible currencies and display it for any 'currency' field.\n- [x] Show the currency code (e.g. EUR, USD, YEN) everywhere:\n  - [x] Projects list\n  - [x] Project page (summary, full report and finance tabs)\n  - [x] Organisation page\n- [x] All fields in the project editor should respond to the currency selection. When you switch to a different currency, this should happen for all fields that use a currency in the editor.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\n\nfrom django.core.exceptions import ValidationError\nfrom django.db import models\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom ..fields import ValidXMLCharField\n\n\nclass Partnership(models.Model):\n    # the old way\n    FIELD_PARTNER = u'field'\n    FUNDING_PARTNER = u'funding'\n    SPONSOR_PARTNER = u'sponsor'\n    SUPPORT_PARTNER = u'support'\n    EXTENDING_PARTNER = u'extending'\n\n    PARTNER_TYPE_LIST = [\n        FIELD_PARTNER, FUNDING_PARTNER, SPONSOR_PARTNER, SUPPORT_PARTNER, EXTENDING_PARTNER\n    ]\n    PARTNER_LABELS = [\n        _(u'Implementing partner'),\n        _(u'Funding partner'),\n        _(u'Sponsor partner'),\n        _(u'Accountable partner'),\n        _(u'Extending partner'),\n    ]\n    PARTNER_TYPES = zip(PARTNER_TYPE_LIST, PARTNER_LABELS)\n\n    # the new way\n    IATI_FUNDING_PARTNER = 1\n    IATI_ACCOUNTABLE_PARTNER = 2\n    IATI_EXTENDING_PARTNER = 3\n    IATI_IMPLEMENTING_PARTNER = 4\n    AKVO_SPONSOR_PARTNER = 100   # not part of the IATI OrganisationRole codelist!\n    IATI_REPORTING_ORGANISATION = 101\n\n    # make sure the AKVO_SPONSOR_PARTNER is last in the list\n    IATI_ROLE_LIST = [\n        IATI_FUNDING_PARTNER, IATI_ACCOUNTABLE_PARTNER, IATI_EXTENDING_PARTNER,\n        IATI_IMPLEMENTING_PARTNER, AKVO_SPONSOR_PARTNER, IATI_REPORTING_ORGANISATION\n    ]\n    IATI_ROLE_LABELS = [\n        _(u'Funding partner'),\n        _(u'Accountable partner'),\n        _(u'Extending partner'),\n        _(u'Implementing partner'),\n        _(u'Sponsor partner'),\n        _(u'Reporting organisation'),\n    ]\n    IATI_ROLES = zip(IATI_ROLE_LIST, IATI_ROLE_LABELS)\n\n    # used when migrating\n    PARTNER_TYPES_TO_ROLES_MAP = {\n        FUNDING_PARTNER: IATI_FUNDING_PARTNER,\n        SUPPORT_PARTNER: IATI_ACCOUNTABLE_PARTNER,\n        FIELD_PARTNER: IATI_IMPLEMENTING_PARTNER,\n        SPONSOR_PARTNER: AKVO_SPONSOR_PARTNER,\n    }\n\n    # backwards compatibility\n    ROLES_TO_PARTNER_TYPES_MAP = {\n        IATI_FUNDING_PARTNER: FUNDING_PARTNER,\n        IATI_ACCOUNTABLE_PARTNER: SUPPORT_PARTNER,\n        IATI_EXTENDING_PARTNER: EXTENDING_PARTNER,\n        IATI_IMPLEMENTING_PARTNER: FIELD_PARTNER,\n        AKVO_SPONSOR_PARTNER: SPONSOR_PARTNER,\n        # TODO: not backwards compatible\n        IATI_REPORTING_ORGANISATION: u''\n    }\n\n    ALLIANCE_PARTNER = u'alliance'\n    KNOWLEDGE_PARTNER = u'knowledge'\n    NETWORK_PARTNER = u'network'\n\n    PARTNER_TYPE_EXTRAS_LIST = (ALLIANCE_PARTNER, KNOWLEDGE_PARTNER, NETWORK_PARTNER)\n    PARTNER_TYPE_EXTRA_LABELS = (\n        _(u'Alliance'),\n        _(u'Knowledge'),\n        _(u'Network')\n    )\n\n    PARTNER_TYPE_EXTRAS = zip(PARTNER_TYPE_EXTRAS_LIST, PARTNER_TYPE_EXTRA_LABELS)\n\n    organisation = models.ForeignKey(\n        'Organisation', verbose_name=_(u'organisation'), related_name='partnerships', null=True,\n        blank=True,\n        help_text=_(u'Select an organisation that is taking an active role in the project.')\n    )\n    project = models.ForeignKey('Project', verbose_name=_(u'project'), related_name='partnerships')\n    iati_organisation_role = models.PositiveSmallIntegerField(\n        _(u'organisation role'), choices=IATI_ROLES, db_index=True, null=True, blank=True,\n        help_text=_(u'Select the role of the organisation within the project:<br/>'\n                    u'- Funding organisation: a government or organisation that provides funds to '\n                    u'the project<br/>'\n                    u'- Implementing organisation: an organisation involved in carrying out the '\n                    u'activity or intervention<br/>'\n                    u'- Accountable organisation: an organisation responsible for oversight of '\n                    u'the project and its outcomes<br/>'\n                    u'- Extending organisation: an organisation that manages the budget and '\n                    u'direction of a project on behalf of the funding organisation<br/>'\n                    u'- Reporting organisation: an organisation that will report this project in '\n                    u'an IATI file')\n    )\n    # is_secondary_reporter is only used when the iati_organisation_role is set to\n    # IATI_REPORTING_ORGANISATION, thus the use of NullBooleanField\n    is_secondary_reporter = models.NullBooleanField(\n        _(u'secondary reporter'),\n        help_text=_(\n            u'This indicates whether the reporting organisation is a secondary publisher: '\n            u'publishing data for which it is not directly responsible.'\n        )\n    )\n    funding_amount = models.DecimalField(\n        _(u'funding amount'), max_digits=14, decimal_places=2, blank=True, null=True, db_index=True,\n        help_text=_(u'It\u2019s only possible to indicate a funding amount for funding partners. Use a '\n                    u'period to denote decimals.')\n    )\n    partner_type_extra = ValidXMLCharField(\n        _(u'partner type extra'), max_length=30, blank=True, null=True, choices=PARTNER_TYPE_EXTRAS,\n        help_text=_(u'RSR specific partner type.')\n    )\n    iati_activity_id = ValidXMLCharField(\n        _(u'IATI activity ID'), max_length=100, blank=True, null=True, db_index=True,\n        help_text=_(u'A valid activity identifier published by the participating organisation '\n                    u'which points to the activity that it has published to IATI that describes '\n                    u'its role in this activity.')\n    )\n    internal_id = ValidXMLCharField(\n        _(u'Internal ID'), max_length=75, blank=True, null=True, db_index=True,\n        help_text=_(u'This field can be used to indicate an internal identifier that is used by '\n                    u'the organisation for this project. (75 characters)')\n    )\n    iati_url = models.URLField(\n        blank=True,\n        help_text=_(\n            u'Please enter the URL for where the IATI Activity Id Funding details are published. '\n            u'For projects directly or indirectly funded by the Dutch Government, this should '\n            u'be the OpenAid.nl page. For other projects, an alternative URL can be used.'\n        )\n    )\n    related_activity_id = ValidXMLCharField(\n        _(u'related IATI activity ID'), max_length=100, blank=True\n    )\n\n    def iati_organisation_role_label(self):\n        if self.iati_organisation_role:\n            return dict(self.IATI_ROLES).get(self.iati_organisation_role)\n        else:\n            return ''\n\n    def iati_role_to_partner_type(self):\n        if self.iati_organisation_role:\n            return dict(self.ROLES_TO_PARTNER_TYPES_MAP).get(int(self.iati_organisation_role))\n        else:\n            return None\n\n    def organisation_show_link(self):\n        if self.organisation:\n            return u'<a href=\"{0}\">{1}</a>'.format(self.organisation.get_absolute_url(),\n                                                   self.organisation.long_name or\n                                                   self.organisation.name)\n        return ''\n\n    class Meta:\n        app_label = 'rsr'\n        verbose_name = _(u'project partner')\n        verbose_name_plural = _(u'project partners')\n        ordering = ['iati_organisation_role']\n\n    def __unicode__(self):\n        if self.organisation:\n            if self.organisation.name:\n                organisation_unicode = self.organisation.name\n            elif self.organisation.long_name:\n                organisation_unicode = self.organisation.long_name\n            else:\n                organisation_unicode = u'%s' % _(u'Organisation name not specified')\n        else:\n            organisation_unicode = u'%s' % _(u'Organisation not specified')\n\n        if self.iati_organisation_role:\n            organisation_unicode += u' ({})'.format(\n                unicode(dict(self.IATI_ROLES)[self.iati_organisation_role])\n            )\n        return organisation_unicode\n\n    def clean(self):\n        # Don't allow multiple reporting organisations\n        if self.iati_organisation_role == self.IATI_REPORTING_ORGANISATION:\n            reporting_orgs = self.project.partnerships.filter(\n                iati_organisation_role=self.IATI_REPORTING_ORGANISATION\n            )\n\n            if reporting_orgs.count() > 1:\n                raise ValidationError(\n                    {'iati_organisation_role': u'%s' % _(u'Project can only have one reporting '\n                                                         u'organisation')}\n                )\n\n    def save(self, *args, **kwargs):\n        super(Partnership, self).save(*args, **kwargs)\n        self.set_primary_organisation()\n\n    def delete(self, *args, **kwargs):\n        super(Partnership, self).delete(*args, **kwargs)\n        self.set_primary_organisation()\n\n    def set_primary_organisation(self):\n        # Check which organisation should be set to the primary organisation of the project\n        # This is done to get better performance on the project list page\n        self.project.primary_organisation = self.project.find_primary_organisation()\n        self.project.save(update_fields=['primary_organisation'])\n", "path": "akvo/rsr/models/partnership.py"}, {"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\nfrom rest_framework import serializers\n\nfrom akvo.rsr.models import Partnership\n\nfrom akvo.rest.serializers.organisation import OrganisationBasicSerializer\nfrom akvo.rest.serializers.rsr_serializer import BaseRSRSerializer\n\n\nclass PartnershipRawSerializer(BaseRSRSerializer):\n\n    class Meta:\n        model = Partnership\n\n\nclass PartnershipSerializer(PartnershipRawSerializer):\n\n    organisation_show_link = serializers.Field(source='organisation_show_link')\n    partner_type = serializers.Field(source='iati_role_to_partner_type')\n    organisation_role_label = serializers.Field(source='iati_organisation_role_label')\n\n\nclass PartnershipBasicSerializer(BaseRSRSerializer):\n\n    organisation = OrganisationBasicSerializer(source='organisation')\n    iati_organisation_role_label = serializers.Field(source='iati_organisation_role_label')\n\n    class Meta:\n        model = Partnership\n        fields = (\n            'id',\n            'project',\n            'organisation',\n            'iati_organisation_role',\n            'iati_organisation_role_label',\n        )\n", "path": "akvo/rest/serializers/partnership.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\n\nfrom django.core.exceptions import ValidationError\nfrom django.db import models\nfrom django.utils.translation import ugettext_lazy as _\n\nfrom ..fields import ValidXMLCharField\n\n\nclass Partnership(models.Model):\n    # the old way\n    FIELD_PARTNER = u'field'\n    FUNDING_PARTNER = u'funding'\n    SPONSOR_PARTNER = u'sponsor'\n    SUPPORT_PARTNER = u'support'\n    EXTENDING_PARTNER = u'extending'\n\n    PARTNER_TYPE_LIST = [\n        FIELD_PARTNER, FUNDING_PARTNER, SPONSOR_PARTNER, SUPPORT_PARTNER, EXTENDING_PARTNER\n    ]\n    PARTNER_LABELS = [\n        _(u'Implementing partner'),\n        _(u'Funding partner'),\n        _(u'Sponsor partner'),\n        _(u'Accountable partner'),\n        _(u'Extending partner'),\n    ]\n    PARTNER_TYPES = zip(PARTNER_TYPE_LIST, PARTNER_LABELS)\n\n    # the new way\n    IATI_FUNDING_PARTNER = 1\n    IATI_ACCOUNTABLE_PARTNER = 2\n    IATI_EXTENDING_PARTNER = 3\n    IATI_IMPLEMENTING_PARTNER = 4\n    AKVO_SPONSOR_PARTNER = 100   # not part of the IATI OrganisationRole codelist!\n    IATI_REPORTING_ORGANISATION = 101\n\n    # make sure the AKVO_SPONSOR_PARTNER is last in the list\n    IATI_ROLE_LIST = [\n        IATI_FUNDING_PARTNER, IATI_ACCOUNTABLE_PARTNER, IATI_EXTENDING_PARTNER,\n        IATI_IMPLEMENTING_PARTNER, AKVO_SPONSOR_PARTNER, IATI_REPORTING_ORGANISATION\n    ]\n    IATI_ROLE_LABELS = [\n        _(u'Funding partner'),\n        _(u'Accountable partner'),\n        _(u'Extending partner'),\n        _(u'Implementing partner'),\n        _(u'Sponsor partner'),\n        _(u'Reporting organisation'),\n    ]\n    IATI_ROLES = zip(IATI_ROLE_LIST, IATI_ROLE_LABELS)\n\n    # used when migrating\n    PARTNER_TYPES_TO_ROLES_MAP = {\n        FUNDING_PARTNER: IATI_FUNDING_PARTNER,\n        SUPPORT_PARTNER: IATI_ACCOUNTABLE_PARTNER,\n        FIELD_PARTNER: IATI_IMPLEMENTING_PARTNER,\n        SPONSOR_PARTNER: AKVO_SPONSOR_PARTNER,\n    }\n\n    # backwards compatibility\n    ROLES_TO_PARTNER_TYPES_MAP = {\n        IATI_FUNDING_PARTNER: FUNDING_PARTNER,\n        IATI_ACCOUNTABLE_PARTNER: SUPPORT_PARTNER,\n        IATI_EXTENDING_PARTNER: EXTENDING_PARTNER,\n        IATI_IMPLEMENTING_PARTNER: FIELD_PARTNER,\n        AKVO_SPONSOR_PARTNER: SPONSOR_PARTNER,\n        # TODO: not backwards compatible\n        IATI_REPORTING_ORGANISATION: u''\n    }\n\n    ALLIANCE_PARTNER = u'alliance'\n    KNOWLEDGE_PARTNER = u'knowledge'\n    NETWORK_PARTNER = u'network'\n\n    PARTNER_TYPE_EXTRAS_LIST = (ALLIANCE_PARTNER, KNOWLEDGE_PARTNER, NETWORK_PARTNER)\n    PARTNER_TYPE_EXTRA_LABELS = (\n        _(u'Alliance'),\n        _(u'Knowledge'),\n        _(u'Network')\n    )\n\n    PARTNER_TYPE_EXTRAS = zip(PARTNER_TYPE_EXTRAS_LIST, PARTNER_TYPE_EXTRA_LABELS)\n\n    organisation = models.ForeignKey(\n        'Organisation', verbose_name=_(u'organisation'), related_name='partnerships', null=True,\n        blank=True,\n        help_text=_(u'Select an organisation that is taking an active role in the project.')\n    )\n    project = models.ForeignKey('Project', verbose_name=_(u'project'), related_name='partnerships')\n    iati_organisation_role = models.PositiveSmallIntegerField(\n        _(u'organisation role'), choices=IATI_ROLES, db_index=True, null=True, blank=True,\n        help_text=_(u'Select the role of the organisation within the project:<br/>'\n                    u'- Funding organisation: a government or organisation that provides funds to '\n                    u'the project<br/>'\n                    u'- Implementing organisation: an organisation involved in carrying out the '\n                    u'activity or intervention<br/>'\n                    u'- Accountable organisation: an organisation responsible for oversight of '\n                    u'the project and its outcomes<br/>'\n                    u'- Extending organisation: an organisation that manages the budget and '\n                    u'direction of a project on behalf of the funding organisation<br/>'\n                    u'- Reporting organisation: an organisation that will report this project in '\n                    u'an IATI file')\n    )\n    # is_secondary_reporter is only used when the iati_organisation_role is set to\n    # IATI_REPORTING_ORGANISATION, thus the use of NullBooleanField\n    is_secondary_reporter = models.NullBooleanField(\n        _(u'secondary reporter'),\n        help_text=_(\n            u'This indicates whether the reporting organisation is a secondary publisher: '\n            u'publishing data for which it is not directly responsible.'\n        )\n    )\n    funding_amount = models.DecimalField(\n        _(u'funding amount'), max_digits=14, decimal_places=2, blank=True, null=True, db_index=True,\n        help_text=_(u'It\u2019s only possible to indicate a funding amount for funding partners. Use a '\n                    u'period to denote decimals.')\n    )\n    partner_type_extra = ValidXMLCharField(\n        _(u'partner type extra'), max_length=30, blank=True, null=True, choices=PARTNER_TYPE_EXTRAS,\n        help_text=_(u'RSR specific partner type.')\n    )\n    iati_activity_id = ValidXMLCharField(\n        _(u'IATI activity ID'), max_length=100, blank=True, null=True, db_index=True,\n        help_text=_(u'A valid activity identifier published by the participating organisation '\n                    u'which points to the activity that it has published to IATI that describes '\n                    u'its role in this activity.')\n    )\n    internal_id = ValidXMLCharField(\n        _(u'Internal ID'), max_length=75, blank=True, null=True, db_index=True,\n        help_text=_(u'This field can be used to indicate an internal identifier that is used by '\n                    u'the organisation for this project. (75 characters)')\n    )\n    iati_url = models.URLField(\n        blank=True,\n        help_text=_(\n            u'Please enter the URL for where the IATI Activity Id Funding details are published. '\n            u'For projects directly or indirectly funded by the Dutch Government, this should '\n            u'be the OpenAid.nl page. For other projects, an alternative URL can be used.'\n        )\n    )\n    related_activity_id = ValidXMLCharField(\n        _(u'related IATI activity ID'), max_length=100, blank=True\n    )\n\n    def iati_organisation_role_label(self):\n        if self.iati_organisation_role:\n            return dict(self.IATI_ROLES).get(self.iati_organisation_role)\n        else:\n            return ''\n\n    def iati_role_to_partner_type(self):\n        if self.iati_organisation_role:\n            return dict(self.ROLES_TO_PARTNER_TYPES_MAP).get(int(self.iati_organisation_role))\n        else:\n            return None\n\n    def organisation_show_link(self):\n        if self.organisation:\n            return u'<a href=\"{0}\">{1}</a>'.format(self.organisation.get_absolute_url(),\n                                                   self.organisation.long_name or\n                                                   self.organisation.name)\n        return ''\n\n    def funding_amount_with_currency(self):\n        \"\"\"Returns the funding amount, prepended by the project's currency.\"\"\"\n        if self.funding_amount and self.project and self.project.currency:\n            return u'{0} {1}'.format(self.project.currency, self.funding_amount)\n        return self.funding_amount\n\n    class Meta:\n        app_label = 'rsr'\n        verbose_name = _(u'project partner')\n        verbose_name_plural = _(u'project partners')\n        ordering = ['iati_organisation_role']\n\n    def __unicode__(self):\n        if self.organisation:\n            if self.organisation.name:\n                organisation_unicode = self.organisation.name\n            elif self.organisation.long_name:\n                organisation_unicode = self.organisation.long_name\n            else:\n                organisation_unicode = u'%s' % _(u'Organisation name not specified')\n        else:\n            organisation_unicode = u'%s' % _(u'Organisation not specified')\n\n        if self.iati_organisation_role:\n            organisation_unicode += u' ({})'.format(\n                unicode(dict(self.IATI_ROLES)[self.iati_organisation_role])\n            )\n        return organisation_unicode\n\n    def clean(self):\n        # Don't allow multiple reporting organisations\n        if self.iati_organisation_role == self.IATI_REPORTING_ORGANISATION:\n            reporting_orgs = self.project.partnerships.filter(\n                iati_organisation_role=self.IATI_REPORTING_ORGANISATION\n            )\n\n            if reporting_orgs.count() > 1:\n                raise ValidationError(\n                    {'iati_organisation_role': u'%s' % _(u'Project can only have one reporting '\n                                                         u'organisation')}\n                )\n\n    def save(self, *args, **kwargs):\n        super(Partnership, self).save(*args, **kwargs)\n        self.set_primary_organisation()\n\n    def delete(self, *args, **kwargs):\n        super(Partnership, self).delete(*args, **kwargs)\n        self.set_primary_organisation()\n\n    def set_primary_organisation(self):\n        # Check which organisation should be set to the primary organisation of the project\n        # This is done to get better performance on the project list page\n        self.project.primary_organisation = self.project.find_primary_organisation()\n        self.project.save(update_fields=['primary_organisation'])\n", "path": "akvo/rsr/models/partnership.py"}, {"content": "# -*- coding: utf-8 -*-\n\n# Akvo RSR is covered by the GNU Affero General Public License.\n# See more details in the license.txt file located at the root folder of the Akvo RSR module.\n# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.\n\nfrom rest_framework import serializers\n\nfrom akvo.rsr.models import Partnership\n\nfrom akvo.rest.serializers.organisation import OrganisationBasicSerializer\nfrom akvo.rest.serializers.rsr_serializer import BaseRSRSerializer\n\n\nclass PartnershipRawSerializer(BaseRSRSerializer):\n\n    class Meta:\n        model = Partnership\n\n\nclass PartnershipSerializer(PartnershipRawSerializer):\n\n    organisation_show_link = serializers.Field(source='organisation_show_link')\n    partner_type = serializers.Field(source='iati_role_to_partner_type')\n    organisation_role_label = serializers.Field(source='iati_organisation_role_label')\n    funding_amount_label = serializers.Field(source='funding_amount_with_currency')\n\n\nclass PartnershipBasicSerializer(BaseRSRSerializer):\n\n    organisation = OrganisationBasicSerializer(source='organisation')\n    iati_organisation_role_label = serializers.Field(source='iati_organisation_role_label')\n\n    class Meta:\n        model = Partnership\n        fields = (\n            'id',\n            'project',\n            'organisation',\n            'iati_organisation_role',\n            'iati_organisation_role_label',\n        )\n", "path": "akvo/rest/serializers/partnership.py"}]}