We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
IATI expects baseline year to be a positiveInteger
N/A values for baseline year are not acceptable, and cause the XML to fail validation.

--- 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/iati/checks/fields/results.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 akvo.rsr.models.result.utils import QUANTITATIVE
8 
9 DGIS_VALIDATION_SET_NAME = u"DGIS IATI"
10 
11 
12 def results(project):
13     """
14     :param project: Project object
15     :return: All checks passed boolean, [Check results]
16     """
17     checks = []
18     all_checks_passed = True
19 
20     DGIS_PROJECT = project.validations.filter(name=DGIS_VALIDATION_SET_NAME).count() == 1
21 
22     for result in project.results.all():
23         if not result.type:
24             all_checks_passed = False
25             checks.append((u'error', u'result (id: %s) has no type specified' % str(result.pk)))
26 
27         if not result.title:
28             all_checks_passed = False
29             checks.append((u'error', u'result (id: %s) has no title specified' % str(result.pk)))
30 
31         if not result.indicators.filter(type=QUANTITATIVE):
32             all_checks_passed = False
33             checks.append(
34                 (u'error', u'result (id: %s) has no quantitative indicator(s)' % str(result.pk))
35             )
36 
37         for indicator in result.indicators.filter(type=QUANTITATIVE):
38             if not indicator.measure:
39                 all_checks_passed = False
40                 checks.append((u'error', u'indicator (id: %s) has no measure specified' %
41                                str(indicator.pk)))
42 
43             if not indicator.title:
44                 all_checks_passed = False
45                 checks.append((u'error', u'indicator (id: %s) has no title specified' %
46                                str(indicator.pk)))
47 
48             if not indicator.baseline_value:
49                 if DGIS_PROJECT:
50                     all_checks_passed = False
51                     checks.append((u'warning', u'indicator (id: %s) baseline has no value '
52                                                u'specified, however the value of "N/A" has been '
53                                                u'set for the attribute' % str(indicator.pk)))
54                 elif indicator.baseline_year or indicator.baseline_comment:
55                     all_checks_passed = False
56                     checks.append((u'error', u'indicator (id: %s) baseline has no value specified' %
57                                    str(indicator.pk)))
58 
59             if not indicator.baseline_year:
60                 if DGIS_PROJECT:
61                     all_checks_passed = False
62                     checks.append((u'warning', u'indicator (id: %s) baseline has no year '
63                                                u'specified, however the value of "N/A" has been '
64                                                u'set for the attribute' % str(indicator.pk)))
65                 elif indicator.baseline_value or indicator.baseline_comment:
66                     all_checks_passed = False
67                     checks.append((u'error', u'indicator (id: %s) baseline has no year specified' %
68                                    str(indicator.pk)))
69 
70             for reference in indicator.references.all():
71                 if not reference.reference:
72                     all_checks_passed = False
73                     checks.append((u'error', u'indicator reference (id: %s) has no code '
74                                              u'specified' % str(reference.pk)))
75 
76                 if not reference.vocabulary:
77                     all_checks_passed = False
78                     checks.append((u'error', u'indicator reference (id: %s) has no vocabulary '
79                                              u'specified' % str(reference.pk)))
80 
81                 if reference.vocabulary == '99' and not reference.vocabulary_uri:
82                     all_checks_passed = False
83                     checks.append((u'error', u'indicator reference (id: %s) has vocabulary 99 '
84                                              u'(reporting organisation) but no vocabulary URI '
85                                              u'specified' % str(reference.pk)))
86 
87             for period in indicator.periods.all():
88                 if not period.period_start:
89                     all_checks_passed = False
90                     checks.append((u'error', u'indicator period (id: %s) has no start date '
91                                              u'specified' % str(period.pk)))
92 
93                 if not period.period_end:
94                     all_checks_passed = False
95                     checks.append((u'error', u'indicator period (id: %s) has no end date '
96                                              u'specified' % str(period.pk)))
97 
98                 if period.period_start and period.period_end and \
99                         period.period_start > period.period_end:
100                     all_checks_passed = False
101                     checks.append((u'error', u'indicator period (id: %s) has a start date '
102                                              u'later than the end date' % str(period.pk)))
103 
104                 if not period.target_value:
105                     if DGIS_PROJECT:
106                         all_checks_passed = False
107                         checks.append((u'warning', u'indicator period (id: %s) has no target value '
108                                                    u'specified. The value "N/A" has been set for '
109                                                    u'the target value attribute' % str(period.pk)))
110                     elif (period.target_comment or period.target_locations.all() or
111                           period.target_dimensions.all()):
112                         all_checks_passed = False
113                         checks.append((u'error', u'indicator period (id: %s) has no target value, '
114                                                  u'but does have a target comment, target '
115                                                  u'location(s) or target dimension(s)' %
116                                        str(period.pk)))
117 
118                 if not period.actual_value:
119                     if DGIS_PROJECT:
120                         all_checks_passed = False
121                         checks.append((u'warning', u'indicator period (id: %s) has no actual value '
122                                                    u'specified. The value "N/A" has been set for '
123                                                    u'the actual value attribute' % str(period.pk)))
124                     elif (period.actual_comment or period.actual_locations.all() or
125                           period.actual_dimensions.all()):
126                         all_checks_passed = False
127                         checks.append((u'error', u'indicator period (id: %s) has no actual value, '
128                                                  u'but does have a actual comment, actual '
129                                                  u'location(s) or actual dimension(s)' %
130                                        str(period.pk)))
131 
132     if project.results.all() and all_checks_passed:
133         checks.append((u'success', u'has valid result(s)'))
134 
135     return all_checks_passed, checks
136
```

Path: `akvo/iati/exports/elements/result.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 lxml import etree
8 
9 from akvo.rsr.models.result.utils import QUANTITATIVE
10 
11 DGIS_VALIDATION_SET_NAME = u"DGIS IATI"
12 NOT_AVAILABLE = u"N/A"
13 
14 
15 def result(project):
16     """
17     Generate the result elements.
18 
19     :param project: Project object
20     :return: A list of Etree elements
21     """
22     result_elements = []
23 
24     DGIS_PROJECT = project.validations.filter(name=DGIS_VALIDATION_SET_NAME).count() == 1
25 
26     for res in project.results.all():
27         if res.type or res.aggregation_status is not None or res.title or res.description or \
28                 res.indicators.all():
29             element = etree.Element("result")
30 
31             if res.type:
32                 element.attrib['type'] = res.type
33 
34             if res.aggregation_status is not None:
35                 element.attrib['aggregation-status'] = '1' if res.aggregation_status else '0'
36 
37             if res.title:
38                 title_element = etree.SubElement(element, "title")
39                 narrative_element = etree.SubElement(title_element, "narrative")
40                 narrative_element.text = res.title
41 
42             if res.description:
43                 description_element = etree.SubElement(element, "description")
44                 narrative_element = etree.SubElement(description_element, "narrative")
45                 narrative_element.text = res.description
46 
47             for indicator in res.indicators.filter(type=QUANTITATIVE):
48                 if indicator.measure or indicator.ascending is not None or indicator.title or \
49                         indicator.description or indicator.references.all() or \
50                         indicator.baseline_year or indicator.baseline_value or \
51                         indicator.baseline_comment or indicator.periods.all():
52                     indicator_element = etree.SubElement(element, "indicator")
53 
54                     if indicator.measure:
55                         indicator_element.attrib['measure'] = indicator.measure
56 
57                     if indicator.ascending is not None:
58                         indicator_element.attrib['ascending'] = '1' if indicator.ascending else '0'
59 
60                     if indicator.title:
61                         title_element = etree.SubElement(indicator_element, "title")
62                         narrative_element = etree.SubElement(title_element, "narrative")
63                         narrative_element.text = indicator.title
64 
65                     if indicator.description:
66                         description_element = etree.SubElement(indicator_element, "description")
67                         narrative_element = etree.SubElement(description_element, "narrative")
68                         narrative_element.text = indicator.description
69 
70                     for reference in indicator.references.all():
71                         if reference.vocabulary or reference.reference or reference.vocabulary_uri:
72                             reference_element = etree.SubElement(indicator_element, "reference")
73 
74                             if reference.vocabulary:
75                                 reference_element.attrib['vocabulary'] = reference.vocabulary
76 
77                             if reference.reference:
78                                 reference_element.attrib['code'] = reference.reference
79 
80                             if reference.vocabulary_uri:
81                                 reference_element.attrib['indicator-uri'] = reference.vocabulary_uri
82 
83                     if DGIS_PROJECT or indicator.baseline_year or indicator.baseline_value or \
84                             indicator.baseline_comment:
85                             baseline_element = etree.SubElement(indicator_element, "baseline")
86 
87                             if indicator.baseline_year:
88                                 baseline_element.attrib['year'] = str(indicator.baseline_year)
89                             elif DGIS_PROJECT:
90                                 baseline_element.attrib['year'] = NOT_AVAILABLE
91 
92                             if indicator.baseline_value:
93                                 baseline_element.attrib['value'] = indicator.baseline_value
94                             elif DGIS_PROJECT:
95                                 baseline_element.attrib['value'] = NOT_AVAILABLE
96 
97                             if indicator.baseline_comment:
98                                 comment_element = etree.SubElement(baseline_element, "comment")
99                                 narrative_element = etree.SubElement(comment_element, "narrative")
100                                 narrative_element.text = indicator.baseline_comment
101 
102                     for period in indicator.periods.all():
103                         if period.period_start or period.period_end or period.target_value or \
104                                 period.target_locations.all() or period.target_dimensions.all() or \
105                                 period.target_comment or period.actual_value or \
106                                 period.actual_locations.all() or period.actual_dimensions.all() or \
107                                 period.actual_comment:
108                             period_element = etree.SubElement(indicator_element, "period")
109 
110                             if period.period_start:
111                                 period_start_element = etree.SubElement(period_element,
112                                                                         "period-start")
113                                 period_start_element.attrib['iso-date'] = str(period.period_start)
114 
115                             if period.period_end:
116                                 period_end_element = etree.SubElement(period_element, "period-end")
117                                 period_end_element.attrib['iso-date'] = str(period.period_end)
118 
119                             if (DGIS_PROJECT or period.target_value or
120                                     period.target_locations.all() or
121                                     period.target_dimensions.all() or period.target_comment):
122                                 target_element = etree.SubElement(period_element, "target")
123 
124                                 if period.target_value:
125                                     target_element.attrib['value'] = period.target_value
126                                 elif DGIS_PROJECT:
127                                     target_element.attrib['value'] = NOT_AVAILABLE
128 
129                                 for target_location in period.target_locations.all():
130                                     target_location_element = etree.SubElement(target_element,
131                                                                                "location")
132                                     target_location_element.attrib['ref'] = target_location.location
133 
134                                 for target_dimension in period.target_dimensions.all():
135                                     if target_dimension.name or target_dimension.value:
136                                         target_dimension_element = etree.SubElement(target_element,
137                                                                                     "dimension")
138 
139                                         if target_dimension.name:
140                                             target_dimension_element.attrib['name'] = \
141                                                 target_dimension.name
142 
143                                         if target_dimension.value:
144                                             target_dimension_element.attrib['value'] = \
145                                                 target_dimension.value
146 
147                                 if period.target_comment:
148                                     comment_element = etree.SubElement(target_element, "comment")
149                                     narrative_element = etree.SubElement(comment_element,
150                                                                          "narrative")
151                                     narrative_element.text = period.target_comment
152 
153                             if (DGIS_PROJECT or period.actual_value or
154                                     period.actual_locations.all() or
155                                     period.actual_dimensions.all() or period.actual_comment):
156                                 actual_element = etree.SubElement(period_element, "actual")
157 
158                                 if period.actual_value:
159                                     actual_element.attrib['value'] = period.actual_value
160                                 elif DGIS_PROJECT:
161                                     actual_element.attrib['value'] = NOT_AVAILABLE
162 
163                                 for actual_location in period.actual_locations.all():
164                                     actual_location_element = etree.SubElement(actual_element,
165                                                                                "location")
166                                     actual_location_element.attrib['ref'] = actual_location.location
167 
168                                 for actual_dimension in period.actual_dimensions.all():
169                                     if actual_dimension.name or actual_dimension.value:
170                                         actual_dimension_element = etree.SubElement(actual_element,
171                                                                                     "dimension")
172 
173                                         if actual_dimension.name:
174                                             actual_dimension_element.attrib['name'] = \
175                                                 actual_dimension.name
176 
177                                         if actual_dimension.value:
178                                             actual_dimension_element.attrib['value'] = \
179                                                 actual_dimension.value
180 
181                                 if period.actual_comment:
182                                     comment_element = etree.SubElement(actual_element, "comment")
183                                     narrative_element = etree.SubElement(comment_element,
184                                                                          "narrative")
185                                     narrative_element.text = period.actual_comment
186 
187             result_elements.append(element)
188 
189     return result_elements
190
```
--- 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/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
@@ -60,7 +60,7 @@
                 if DGIS_PROJECT:
                     all_checks_passed = False
                     checks.append((u'warning', u'indicator (id: %s) baseline has no year '
-                                               u'specified, however the value of "N/A" has been '
+                                               u'specified, however the value of "1" has been '
                                                u'set for the attribute' % str(indicator.pk)))
                 elif indicator.baseline_value or indicator.baseline_comment:
                     all_checks_passed = False
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
@@ -10,6 +10,7 @@
 
 DGIS_VALIDATION_SET_NAME = u"DGIS IATI"
 NOT_AVAILABLE = u"N/A"
+NOT_AVAILABLE_YEAR = u"1"
 
 
 def result(project):
@@ -87,7 +88,7 @@
                             if indicator.baseline_year:
                                 baseline_element.attrib['year'] = str(indicator.baseline_year)
                             elif DGIS_PROJECT:
-                                baseline_element.attrib['year'] = NOT_AVAILABLE
+                                baseline_element.attrib['year'] = NOT_AVAILABLE_YEAR
 
                             if indicator.baseline_value:
                                 baseline_element.attrib['value'] = indicator.baseline_value

{"golden_diff": "diff --git a/akvo/iati/checks/fields/results.py b/akvo/iati/checks/fields/results.py\n--- a/akvo/iati/checks/fields/results.py\n+++ b/akvo/iati/checks/fields/results.py\n@@ -60,7 +60,7 @@\n                 if DGIS_PROJECT:\n                     all_checks_passed = False\n                     checks.append((u'warning', u'indicator (id: %s) baseline has no year '\n-                                               u'specified, however the value of \"N/A\" has been '\n+                                               u'specified, however the value of \"1\" has been '\n                                                u'set for the attribute' % str(indicator.pk)))\n                 elif indicator.baseline_value or indicator.baseline_comment:\n                     all_checks_passed = False\ndiff --git a/akvo/iati/exports/elements/result.py b/akvo/iati/exports/elements/result.py\n--- a/akvo/iati/exports/elements/result.py\n+++ b/akvo/iati/exports/elements/result.py\n@@ -10,6 +10,7 @@\n \n DGIS_VALIDATION_SET_NAME = u\"DGIS IATI\"\n NOT_AVAILABLE = u\"N/A\"\n+NOT_AVAILABLE_YEAR = u\"1\"\n \n \n def result(project):\n@@ -87,7 +88,7 @@\n                             if indicator.baseline_year:\n                                 baseline_element.attrib['year'] = str(indicator.baseline_year)\n                             elif DGIS_PROJECT:\n-                                baseline_element.attrib['year'] = NOT_AVAILABLE\n+                                baseline_element.attrib['year'] = NOT_AVAILABLE_YEAR\n \n                             if indicator.baseline_value:\n                                 baseline_element.attrib['value'] = indicator.baseline_value\n", "issue": "IATI expects baseline year to be a positiveInteger\nN/A values for baseline year are not acceptable, and cause the XML to fail validation.\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\nfrom akvo.rsr.models.result.utils import QUANTITATIVE\n\nDGIS_VALIDATION_SET_NAME = u\"DGIS IATI\"\n\n\ndef results(project):\n    \"\"\"\n    :param project: Project object\n    :return: All checks passed boolean, [Check results]\n    \"\"\"\n    checks = []\n    all_checks_passed = True\n\n    DGIS_PROJECT = project.validations.filter(name=DGIS_VALIDATION_SET_NAME).count() == 1\n\n    for result in project.results.all():\n        if not result.type:\n            all_checks_passed = False\n            checks.append((u'error', u'result (id: %s) has no type specified' % str(result.pk)))\n\n        if not result.title:\n            all_checks_passed = False\n            checks.append((u'error', u'result (id: %s) has no title specified' % str(result.pk)))\n\n        if not result.indicators.filter(type=QUANTITATIVE):\n            all_checks_passed = False\n            checks.append(\n                (u'error', u'result (id: %s) has no quantitative indicator(s)' % str(result.pk))\n            )\n\n        for indicator in result.indicators.filter(type=QUANTITATIVE):\n            if not indicator.measure:\n                all_checks_passed = False\n                checks.append((u'error', u'indicator (id: %s) has no measure specified' %\n                               str(indicator.pk)))\n\n            if not indicator.title:\n                all_checks_passed = False\n                checks.append((u'error', u'indicator (id: %s) has no title specified' %\n                               str(indicator.pk)))\n\n            if not indicator.baseline_value:\n                if DGIS_PROJECT:\n                    all_checks_passed = False\n                    checks.append((u'warning', u'indicator (id: %s) baseline has no value '\n                                               u'specified, however the value of \"N/A\" has been '\n                                               u'set for the attribute' % str(indicator.pk)))\n                elif indicator.baseline_year or indicator.baseline_comment:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator (id: %s) baseline has no value specified' %\n                                   str(indicator.pk)))\n\n            if not indicator.baseline_year:\n                if DGIS_PROJECT:\n                    all_checks_passed = False\n                    checks.append((u'warning', u'indicator (id: %s) baseline has no year '\n                                               u'specified, however the value of \"N/A\" has been '\n                                               u'set for the attribute' % str(indicator.pk)))\n                elif indicator.baseline_value or indicator.baseline_comment:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator (id: %s) baseline has no year specified' %\n                                   str(indicator.pk)))\n\n            for reference in indicator.references.all():\n                if not reference.reference:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator reference (id: %s) has no code '\n                                             u'specified' % str(reference.pk)))\n\n                if not reference.vocabulary:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator reference (id: %s) has no vocabulary '\n                                             u'specified' % str(reference.pk)))\n\n                if reference.vocabulary == '99' and not reference.vocabulary_uri:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator reference (id: %s) has vocabulary 99 '\n                                             u'(reporting organisation) but no vocabulary URI '\n                                             u'specified' % str(reference.pk)))\n\n            for period in indicator.periods.all():\n                if not period.period_start:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator period (id: %s) has no start date '\n                                             u'specified' % str(period.pk)))\n\n                if not period.period_end:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator period (id: %s) has no end date '\n                                             u'specified' % str(period.pk)))\n\n                if period.period_start and period.period_end and \\\n                        period.period_start > period.period_end:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator period (id: %s) has a start date '\n                                             u'later than the end date' % str(period.pk)))\n\n                if not period.target_value:\n                    if DGIS_PROJECT:\n                        all_checks_passed = False\n                        checks.append((u'warning', u'indicator period (id: %s) has no target value '\n                                                   u'specified. The value \"N/A\" has been set for '\n                                                   u'the target value attribute' % str(period.pk)))\n                    elif (period.target_comment or period.target_locations.all() or\n                          period.target_dimensions.all()):\n                        all_checks_passed = False\n                        checks.append((u'error', u'indicator period (id: %s) has no target value, '\n                                                 u'but does have a target comment, target '\n                                                 u'location(s) or target dimension(s)' %\n                                       str(period.pk)))\n\n                if not period.actual_value:\n                    if DGIS_PROJECT:\n                        all_checks_passed = False\n                        checks.append((u'warning', u'indicator period (id: %s) has no actual value '\n                                                   u'specified. The value \"N/A\" has been set for '\n                                                   u'the actual value attribute' % str(period.pk)))\n                    elif (period.actual_comment or period.actual_locations.all() or\n                          period.actual_dimensions.all()):\n                        all_checks_passed = False\n                        checks.append((u'error', u'indicator period (id: %s) has no actual value, '\n                                                 u'but does have a actual comment, actual '\n                                                 u'location(s) or actual dimension(s)' %\n                                       str(period.pk)))\n\n    if project.results.all() and all_checks_passed:\n        checks.append((u'success', u'has valid result(s)'))\n\n    return all_checks_passed, checks\n", "path": "akvo/iati/checks/fields/results.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 lxml import etree\n\nfrom akvo.rsr.models.result.utils import QUANTITATIVE\n\nDGIS_VALIDATION_SET_NAME = u\"DGIS IATI\"\nNOT_AVAILABLE = u\"N/A\"\n\n\ndef result(project):\n    \"\"\"\n    Generate the result elements.\n\n    :param project: Project object\n    :return: A list of Etree elements\n    \"\"\"\n    result_elements = []\n\n    DGIS_PROJECT = project.validations.filter(name=DGIS_VALIDATION_SET_NAME).count() == 1\n\n    for res in project.results.all():\n        if res.type or res.aggregation_status is not None or res.title or res.description or \\\n                res.indicators.all():\n            element = etree.Element(\"result\")\n\n            if res.type:\n                element.attrib['type'] = res.type\n\n            if res.aggregation_status is not None:\n                element.attrib['aggregation-status'] = '1' if res.aggregation_status else '0'\n\n            if res.title:\n                title_element = etree.SubElement(element, \"title\")\n                narrative_element = etree.SubElement(title_element, \"narrative\")\n                narrative_element.text = res.title\n\n            if res.description:\n                description_element = etree.SubElement(element, \"description\")\n                narrative_element = etree.SubElement(description_element, \"narrative\")\n                narrative_element.text = res.description\n\n            for indicator in res.indicators.filter(type=QUANTITATIVE):\n                if indicator.measure or indicator.ascending is not None or indicator.title or \\\n                        indicator.description or indicator.references.all() or \\\n                        indicator.baseline_year or indicator.baseline_value or \\\n                        indicator.baseline_comment or indicator.periods.all():\n                    indicator_element = etree.SubElement(element, \"indicator\")\n\n                    if indicator.measure:\n                        indicator_element.attrib['measure'] = indicator.measure\n\n                    if indicator.ascending is not None:\n                        indicator_element.attrib['ascending'] = '1' if indicator.ascending else '0'\n\n                    if indicator.title:\n                        title_element = etree.SubElement(indicator_element, \"title\")\n                        narrative_element = etree.SubElement(title_element, \"narrative\")\n                        narrative_element.text = indicator.title\n\n                    if indicator.description:\n                        description_element = etree.SubElement(indicator_element, \"description\")\n                        narrative_element = etree.SubElement(description_element, \"narrative\")\n                        narrative_element.text = indicator.description\n\n                    for reference in indicator.references.all():\n                        if reference.vocabulary or reference.reference or reference.vocabulary_uri:\n                            reference_element = etree.SubElement(indicator_element, \"reference\")\n\n                            if reference.vocabulary:\n                                reference_element.attrib['vocabulary'] = reference.vocabulary\n\n                            if reference.reference:\n                                reference_element.attrib['code'] = reference.reference\n\n                            if reference.vocabulary_uri:\n                                reference_element.attrib['indicator-uri'] = reference.vocabulary_uri\n\n                    if DGIS_PROJECT or indicator.baseline_year or indicator.baseline_value or \\\n                            indicator.baseline_comment:\n                            baseline_element = etree.SubElement(indicator_element, \"baseline\")\n\n                            if indicator.baseline_year:\n                                baseline_element.attrib['year'] = str(indicator.baseline_year)\n                            elif DGIS_PROJECT:\n                                baseline_element.attrib['year'] = NOT_AVAILABLE\n\n                            if indicator.baseline_value:\n                                baseline_element.attrib['value'] = indicator.baseline_value\n                            elif DGIS_PROJECT:\n                                baseline_element.attrib['value'] = NOT_AVAILABLE\n\n                            if indicator.baseline_comment:\n                                comment_element = etree.SubElement(baseline_element, \"comment\")\n                                narrative_element = etree.SubElement(comment_element, \"narrative\")\n                                narrative_element.text = indicator.baseline_comment\n\n                    for period in indicator.periods.all():\n                        if period.period_start or period.period_end or period.target_value or \\\n                                period.target_locations.all() or period.target_dimensions.all() or \\\n                                period.target_comment or period.actual_value or \\\n                                period.actual_locations.all() or period.actual_dimensions.all() or \\\n                                period.actual_comment:\n                            period_element = etree.SubElement(indicator_element, \"period\")\n\n                            if period.period_start:\n                                period_start_element = etree.SubElement(period_element,\n                                                                        \"period-start\")\n                                period_start_element.attrib['iso-date'] = str(period.period_start)\n\n                            if period.period_end:\n                                period_end_element = etree.SubElement(period_element, \"period-end\")\n                                period_end_element.attrib['iso-date'] = str(period.period_end)\n\n                            if (DGIS_PROJECT or period.target_value or\n                                    period.target_locations.all() or\n                                    period.target_dimensions.all() or period.target_comment):\n                                target_element = etree.SubElement(period_element, \"target\")\n\n                                if period.target_value:\n                                    target_element.attrib['value'] = period.target_value\n                                elif DGIS_PROJECT:\n                                    target_element.attrib['value'] = NOT_AVAILABLE\n\n                                for target_location in period.target_locations.all():\n                                    target_location_element = etree.SubElement(target_element,\n                                                                               \"location\")\n                                    target_location_element.attrib['ref'] = target_location.location\n\n                                for target_dimension in period.target_dimensions.all():\n                                    if target_dimension.name or target_dimension.value:\n                                        target_dimension_element = etree.SubElement(target_element,\n                                                                                    \"dimension\")\n\n                                        if target_dimension.name:\n                                            target_dimension_element.attrib['name'] = \\\n                                                target_dimension.name\n\n                                        if target_dimension.value:\n                                            target_dimension_element.attrib['value'] = \\\n                                                target_dimension.value\n\n                                if period.target_comment:\n                                    comment_element = etree.SubElement(target_element, \"comment\")\n                                    narrative_element = etree.SubElement(comment_element,\n                                                                         \"narrative\")\n                                    narrative_element.text = period.target_comment\n\n                            if (DGIS_PROJECT or period.actual_value or\n                                    period.actual_locations.all() or\n                                    period.actual_dimensions.all() or period.actual_comment):\n                                actual_element = etree.SubElement(period_element, \"actual\")\n\n                                if period.actual_value:\n                                    actual_element.attrib['value'] = period.actual_value\n                                elif DGIS_PROJECT:\n                                    actual_element.attrib['value'] = NOT_AVAILABLE\n\n                                for actual_location in period.actual_locations.all():\n                                    actual_location_element = etree.SubElement(actual_element,\n                                                                               \"location\")\n                                    actual_location_element.attrib['ref'] = actual_location.location\n\n                                for actual_dimension in period.actual_dimensions.all():\n                                    if actual_dimension.name or actual_dimension.value:\n                                        actual_dimension_element = etree.SubElement(actual_element,\n                                                                                    \"dimension\")\n\n                                        if actual_dimension.name:\n                                            actual_dimension_element.attrib['name'] = \\\n                                                actual_dimension.name\n\n                                        if actual_dimension.value:\n                                            actual_dimension_element.attrib['value'] = \\\n                                                actual_dimension.value\n\n                                if period.actual_comment:\n                                    comment_element = etree.SubElement(actual_element, \"comment\")\n                                    narrative_element = etree.SubElement(comment_element,\n                                                                         \"narrative\")\n                                    narrative_element.text = period.actual_comment\n\n            result_elements.append(element)\n\n    return result_elements\n", "path": "akvo/iati/exports/elements/result.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\nfrom akvo.rsr.models.result.utils import QUANTITATIVE\n\nDGIS_VALIDATION_SET_NAME = u\"DGIS IATI\"\n\n\ndef results(project):\n    \"\"\"\n    :param project: Project object\n    :return: All checks passed boolean, [Check results]\n    \"\"\"\n    checks = []\n    all_checks_passed = True\n\n    DGIS_PROJECT = project.validations.filter(name=DGIS_VALIDATION_SET_NAME).count() == 1\n\n    for result in project.results.all():\n        if not result.type:\n            all_checks_passed = False\n            checks.append((u'error', u'result (id: %s) has no type specified' % str(result.pk)))\n\n        if not result.title:\n            all_checks_passed = False\n            checks.append((u'error', u'result (id: %s) has no title specified' % str(result.pk)))\n\n        if not result.indicators.filter(type=QUANTITATIVE):\n            all_checks_passed = False\n            checks.append(\n                (u'error', u'result (id: %s) has no quantitative indicator(s)' % str(result.pk))\n            )\n\n        for indicator in result.indicators.filter(type=QUANTITATIVE):\n            if not indicator.measure:\n                all_checks_passed = False\n                checks.append((u'error', u'indicator (id: %s) has no measure specified' %\n                               str(indicator.pk)))\n\n            if not indicator.title:\n                all_checks_passed = False\n                checks.append((u'error', u'indicator (id: %s) has no title specified' %\n                               str(indicator.pk)))\n\n            if not indicator.baseline_value:\n                if DGIS_PROJECT:\n                    all_checks_passed = False\n                    checks.append((u'warning', u'indicator (id: %s) baseline has no value '\n                                               u'specified, however the value of \"N/A\" has been '\n                                               u'set for the attribute' % str(indicator.pk)))\n                elif indicator.baseline_year or indicator.baseline_comment:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator (id: %s) baseline has no value specified' %\n                                   str(indicator.pk)))\n\n            if not indicator.baseline_year:\n                if DGIS_PROJECT:\n                    all_checks_passed = False\n                    checks.append((u'warning', u'indicator (id: %s) baseline has no year '\n                                               u'specified, however the value of \"1\" has been '\n                                               u'set for the attribute' % str(indicator.pk)))\n                elif indicator.baseline_value or indicator.baseline_comment:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator (id: %s) baseline has no year specified' %\n                                   str(indicator.pk)))\n\n            for reference in indicator.references.all():\n                if not reference.reference:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator reference (id: %s) has no code '\n                                             u'specified' % str(reference.pk)))\n\n                if not reference.vocabulary:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator reference (id: %s) has no vocabulary '\n                                             u'specified' % str(reference.pk)))\n\n                if reference.vocabulary == '99' and not reference.vocabulary_uri:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator reference (id: %s) has vocabulary 99 '\n                                             u'(reporting organisation) but no vocabulary URI '\n                                             u'specified' % str(reference.pk)))\n\n            for period in indicator.periods.all():\n                if not period.period_start:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator period (id: %s) has no start date '\n                                             u'specified' % str(period.pk)))\n\n                if not period.period_end:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator period (id: %s) has no end date '\n                                             u'specified' % str(period.pk)))\n\n                if period.period_start and period.period_end and \\\n                        period.period_start > period.period_end:\n                    all_checks_passed = False\n                    checks.append((u'error', u'indicator period (id: %s) has a start date '\n                                             u'later than the end date' % str(period.pk)))\n\n                if not period.target_value:\n                    if DGIS_PROJECT:\n                        all_checks_passed = False\n                        checks.append((u'warning', u'indicator period (id: %s) has no target value '\n                                                   u'specified. The value \"N/A\" has been set for '\n                                                   u'the target value attribute' % str(period.pk)))\n                    elif (period.target_comment or period.target_locations.all() or\n                          period.target_dimensions.all()):\n                        all_checks_passed = False\n                        checks.append((u'error', u'indicator period (id: %s) has no target value, '\n                                                 u'but does have a target comment, target '\n                                                 u'location(s) or target dimension(s)' %\n                                       str(period.pk)))\n\n                if not period.actual_value:\n                    if DGIS_PROJECT:\n                        all_checks_passed = False\n                        checks.append((u'warning', u'indicator period (id: %s) has no actual value '\n                                                   u'specified. The value \"N/A\" has been set for '\n                                                   u'the actual value attribute' % str(period.pk)))\n                    elif (period.actual_comment or period.actual_locations.all() or\n                          period.actual_dimensions.all()):\n                        all_checks_passed = False\n                        checks.append((u'error', u'indicator period (id: %s) has no actual value, '\n                                                 u'but does have a actual comment, actual '\n                                                 u'location(s) or actual dimension(s)' %\n                                       str(period.pk)))\n\n    if project.results.all() and all_checks_passed:\n        checks.append((u'success', u'has valid result(s)'))\n\n    return all_checks_passed, checks\n", "path": "akvo/iati/checks/fields/results.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 lxml import etree\n\nfrom akvo.rsr.models.result.utils import QUANTITATIVE\n\nDGIS_VALIDATION_SET_NAME = u\"DGIS IATI\"\nNOT_AVAILABLE = u\"N/A\"\nNOT_AVAILABLE_YEAR = u\"1\"\n\n\ndef result(project):\n    \"\"\"\n    Generate the result elements.\n\n    :param project: Project object\n    :return: A list of Etree elements\n    \"\"\"\n    result_elements = []\n\n    DGIS_PROJECT = project.validations.filter(name=DGIS_VALIDATION_SET_NAME).count() == 1\n\n    for res in project.results.all():\n        if res.type or res.aggregation_status is not None or res.title or res.description or \\\n                res.indicators.all():\n            element = etree.Element(\"result\")\n\n            if res.type:\n                element.attrib['type'] = res.type\n\n            if res.aggregation_status is not None:\n                element.attrib['aggregation-status'] = '1' if res.aggregation_status else '0'\n\n            if res.title:\n                title_element = etree.SubElement(element, \"title\")\n                narrative_element = etree.SubElement(title_element, \"narrative\")\n                narrative_element.text = res.title\n\n            if res.description:\n                description_element = etree.SubElement(element, \"description\")\n                narrative_element = etree.SubElement(description_element, \"narrative\")\n                narrative_element.text = res.description\n\n            for indicator in res.indicators.filter(type=QUANTITATIVE):\n                if indicator.measure or indicator.ascending is not None or indicator.title or \\\n                        indicator.description or indicator.references.all() or \\\n                        indicator.baseline_year or indicator.baseline_value or \\\n                        indicator.baseline_comment or indicator.periods.all():\n                    indicator_element = etree.SubElement(element, \"indicator\")\n\n                    if indicator.measure:\n                        indicator_element.attrib['measure'] = indicator.measure\n\n                    if indicator.ascending is not None:\n                        indicator_element.attrib['ascending'] = '1' if indicator.ascending else '0'\n\n                    if indicator.title:\n                        title_element = etree.SubElement(indicator_element, \"title\")\n                        narrative_element = etree.SubElement(title_element, \"narrative\")\n                        narrative_element.text = indicator.title\n\n                    if indicator.description:\n                        description_element = etree.SubElement(indicator_element, \"description\")\n                        narrative_element = etree.SubElement(description_element, \"narrative\")\n                        narrative_element.text = indicator.description\n\n                    for reference in indicator.references.all():\n                        if reference.vocabulary or reference.reference or reference.vocabulary_uri:\n                            reference_element = etree.SubElement(indicator_element, \"reference\")\n\n                            if reference.vocabulary:\n                                reference_element.attrib['vocabulary'] = reference.vocabulary\n\n                            if reference.reference:\n                                reference_element.attrib['code'] = reference.reference\n\n                            if reference.vocabulary_uri:\n                                reference_element.attrib['indicator-uri'] = reference.vocabulary_uri\n\n                    if DGIS_PROJECT or indicator.baseline_year or indicator.baseline_value or \\\n                            indicator.baseline_comment:\n                            baseline_element = etree.SubElement(indicator_element, \"baseline\")\n\n                            if indicator.baseline_year:\n                                baseline_element.attrib['year'] = str(indicator.baseline_year)\n                            elif DGIS_PROJECT:\n                                baseline_element.attrib['year'] = NOT_AVAILABLE_YEAR\n\n                            if indicator.baseline_value:\n                                baseline_element.attrib['value'] = indicator.baseline_value\n                            elif DGIS_PROJECT:\n                                baseline_element.attrib['value'] = NOT_AVAILABLE\n\n                            if indicator.baseline_comment:\n                                comment_element = etree.SubElement(baseline_element, \"comment\")\n                                narrative_element = etree.SubElement(comment_element, \"narrative\")\n                                narrative_element.text = indicator.baseline_comment\n\n                    for period in indicator.periods.all():\n                        if period.period_start or period.period_end or period.target_value or \\\n                                period.target_locations.all() or period.target_dimensions.all() or \\\n                                period.target_comment or period.actual_value or \\\n                                period.actual_locations.all() or period.actual_dimensions.all() or \\\n                                period.actual_comment:\n                            period_element = etree.SubElement(indicator_element, \"period\")\n\n                            if period.period_start:\n                                period_start_element = etree.SubElement(period_element,\n                                                                        \"period-start\")\n                                period_start_element.attrib['iso-date'] = str(period.period_start)\n\n                            if period.period_end:\n                                period_end_element = etree.SubElement(period_element, \"period-end\")\n                                period_end_element.attrib['iso-date'] = str(period.period_end)\n\n                            if (DGIS_PROJECT or period.target_value or\n                                    period.target_locations.all() or\n                                    period.target_dimensions.all() or period.target_comment):\n                                target_element = etree.SubElement(period_element, \"target\")\n\n                                if period.target_value:\n                                    target_element.attrib['value'] = period.target_value\n                                elif DGIS_PROJECT:\n                                    target_element.attrib['value'] = NOT_AVAILABLE\n\n                                for target_location in period.target_locations.all():\n                                    target_location_element = etree.SubElement(target_element,\n                                                                               \"location\")\n                                    target_location_element.attrib['ref'] = target_location.location\n\n                                for target_dimension in period.target_dimensions.all():\n                                    if target_dimension.name or target_dimension.value:\n                                        target_dimension_element = etree.SubElement(target_element,\n                                                                                    \"dimension\")\n\n                                        if target_dimension.name:\n                                            target_dimension_element.attrib['name'] = \\\n                                                target_dimension.name\n\n                                        if target_dimension.value:\n                                            target_dimension_element.attrib['value'] = \\\n                                                target_dimension.value\n\n                                if period.target_comment:\n                                    comment_element = etree.SubElement(target_element, \"comment\")\n                                    narrative_element = etree.SubElement(comment_element,\n                                                                         \"narrative\")\n                                    narrative_element.text = period.target_comment\n\n                            if (DGIS_PROJECT or period.actual_value or\n                                    period.actual_locations.all() or\n                                    period.actual_dimensions.all() or period.actual_comment):\n                                actual_element = etree.SubElement(period_element, \"actual\")\n\n                                if period.actual_value:\n                                    actual_element.attrib['value'] = period.actual_value\n                                elif DGIS_PROJECT:\n                                    actual_element.attrib['value'] = NOT_AVAILABLE\n\n                                for actual_location in period.actual_locations.all():\n                                    actual_location_element = etree.SubElement(actual_element,\n                                                                               \"location\")\n                                    actual_location_element.attrib['ref'] = actual_location.location\n\n                                for actual_dimension in period.actual_dimensions.all():\n                                    if actual_dimension.name or actual_dimension.value:\n                                        actual_dimension_element = etree.SubElement(actual_element,\n                                                                                    \"dimension\")\n\n                                        if actual_dimension.name:\n                                            actual_dimension_element.attrib['name'] = \\\n                                                actual_dimension.name\n\n                                        if actual_dimension.value:\n                                            actual_dimension_element.attrib['value'] = \\\n                                                actual_dimension.value\n\n                                if period.actual_comment:\n                                    comment_element = etree.SubElement(actual_element, \"comment\")\n                                    narrative_element = etree.SubElement(comment_element,\n                                                                         \"narrative\")\n                                    narrative_element.text = period.actual_comment\n\n            result_elements.append(element)\n\n    return result_elements\n", "path": "akvo/iati/exports/elements/result.py"}]}