We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fix IATI export for qualitative indicators


--- 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/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.iati.exports.elements.utils import has_data, has_qs_data
10 from akvo.rsr.models.result.utils import QUANTITATIVE, QUALITATIVE
11 
12 DGIS_VALIDATION_SET_NAME = "DGIS IATI"
13 NOT_AVAILABLE = "N/A"
14 NOT_AVAILABLE_YEAR = "1"
15 
16 
17 def result(project):
18     """
19     Generate the result elements.
20 
21     :param project: Project object
22     :return: A list of Etree elements
23     """
24     result_elements = []
25 
26     DGIS_PROJECT = project.validations.filter(name=DGIS_VALIDATION_SET_NAME).count() == 1
27 
28     for res in project.results.all():
29         if (has_data(res, ['type', 'title', 'description', ])
30                 or res.aggregation_status is not None
31                 or res.indicators.all()):
32             element = etree.Element("result")
33 
34             if res.type:
35                 element.attrib['type'] = res.type
36 
37             if res.aggregation_status is not None:
38                 element.attrib['aggregation-status'] = '1' if res.aggregation_status else '0'
39 
40             if res.title:
41                 title_element = etree.SubElement(element, "title")
42                 narrative_element = etree.SubElement(title_element, "narrative")
43                 narrative_element.text = res.title
44 
45             if res.description:
46                 description_element = etree.SubElement(element, "description")
47                 narrative_element = etree.SubElement(description_element, "narrative")
48                 narrative_element.text = res.description
49 
50             for indicator in res.indicators.all():
51                 if not indicator.export_to_iati:
52                     continue
53 
54                 if (has_data(indicator, ['measure', 'title', 'description', 'baseline_year',
55                                          'baseline_value', 'baseline_comment', ])
56                         or indicator.ascending is not None
57                         or has_qs_data(indicator, ['references', 'periods', ])):
58                     add_indicator_element(element, indicator, DGIS_PROJECT)
59 
60             result_elements.append(element)
61 
62     return result_elements
63 
64 
65 def add_indicator_element(result_element, indicator, is_dgis_project):
66     indicator_element = etree.SubElement(result_element, "indicator")
67 
68     if indicator.type == QUALITATIVE:
69         indicator_element.attrib['measure'] = '5'
70 
71     elif indicator.measure:
72         indicator_element.attrib['measure'] = indicator.measure
73 
74     if indicator.ascending is not None:
75         indicator_element.attrib['ascending'] = '1' if indicator.ascending else '0'
76 
77     if indicator.title:
78         title_element = etree.SubElement(indicator_element, "title")
79         narrative_element = etree.SubElement(title_element, "narrative")
80         narrative_element.text = indicator.title
81 
82     if indicator.description:
83         description_element = etree.SubElement(indicator_element, "description")
84         narrative_element = etree.SubElement(description_element, "narrative")
85         narrative_element.text = indicator.description
86 
87     for reference in indicator.references.all():
88         add_reference_element(indicator_element, reference)
89 
90     add_baseline_element(is_dgis_project, indicator_element, indicator)
91 
92     for period in indicator.periods.all():
93         add_period_element(is_dgis_project, indicator_element, period)
94 
95 
96 def add_reference_element(indicator_element, reference):
97     if has_data(reference, ['vocabulary', 'reference', 'vocabulary_uri', ]):
98         reference_element = etree.SubElement(indicator_element, "reference")
99 
100         if reference.vocabulary:
101             reference_element.attrib['vocabulary'] = reference.vocabulary
102 
103         if reference.reference:
104             reference_element.attrib['code'] = reference.reference
105 
106         if reference.vocabulary_uri:
107             reference_element.attrib['indicator-uri'] = reference.vocabulary_uri
108 
109 
110 def add_baseline_element(is_dgis_project, indicator_element, indicator):
111     if is_dgis_project or has_data(indicator,
112                                    ['baseline_year', 'baseline_value', 'baseline_comment', ]):
113         baseline_element = etree.SubElement(indicator_element, "baseline")
114 
115         if indicator.baseline_year:
116             baseline_element.attrib['year'] = str(indicator.baseline_year)
117         elif is_dgis_project:
118             baseline_element.attrib['year'] = NOT_AVAILABLE_YEAR
119 
120         if indicator.baseline_value:
121             baseline_element.attrib['value'] = indicator.baseline_value
122         elif is_dgis_project:
123             baseline_element.attrib['value'] = NOT_AVAILABLE
124 
125         if indicator.baseline_comment:
126             comment_element = etree.SubElement(baseline_element, "comment")
127             narrative_element = etree.SubElement(comment_element, "narrative")
128             narrative_element.text = indicator.baseline_comment
129 
130 
131 def add_period_element(is_dgis_project, indicator_element, period):
132     if (has_data(period, ['period_start', 'period_end', 'target_value', 'target_comment',
133                           'actual_value', 'narrative', 'actual_comment'])
134             or has_qs_data(period, ['target_locations', 'actual_locations'])):
135         period_element = etree.SubElement(indicator_element, "period")
136 
137         if period.period_start:
138             period_start_element = etree.SubElement(period_element,
139                                                     "period-start")
140             period_start_element.attrib['iso-date'] = str(period.period_start)
141 
142         if period.period_end:
143             period_end_element = etree.SubElement(period_element, "period-end")
144             period_end_element.attrib['iso-date'] = str(period.period_end)
145 
146         add_target_element(is_dgis_project, period, period_element)
147         # FIXME: We don't yet allow disaggregations on targets
148 
149         add_actual_element(is_dgis_project, period, period_element)
150         add_actual_dimension_elements(is_dgis_project, period, period_element)
151 
152 
153 def add_target_element(is_dgis_project, period, period_element):
154     if (is_dgis_project or has_data(period, ['target_value', 'target_comment', ])
155             or has_qs_data(period, ['target_locations', ])):
156         target_element = etree.SubElement(period_element, "target")
157 
158         if period.target_value:
159             target_element.attrib['value'] = period.target_value
160         elif is_dgis_project:
161             target_element.attrib['value'] = NOT_AVAILABLE
162 
163         for target_location in period.target_locations.all():
164             target_location_element = etree.SubElement(target_element,
165                                                        "location")
166             target_location_element.attrib['ref'] = target_location.location
167 
168         if period.target_comment:
169             comment_element = etree.SubElement(target_element, "comment")
170             narrative_element = etree.SubElement(comment_element,
171                                                  "narrative")
172             narrative_element.text = period.target_comment
173 
174 
175 def add_actual_element(is_dgis_project, period, period_element):
176     if (is_dgis_project
177             or has_data(period, ['actual_value', 'narrative', 'actual_comment', ])
178             or has_qs_data(period, ['actual_locations'])):
179         actual_element = etree.SubElement(period_element, "actual")
180 
181         if period.indicator.type == QUANTITATIVE:
182             if period.actual_value:
183                 actual_element.attrib['value'] = period.actual_value
184             elif is_dgis_project:
185                 actual_element.attrib['value'] = NOT_AVAILABLE
186 
187         else:
188             if period.narrative:
189                 actual_element.attrib['value'] = period.narrative
190 
191         for actual_location in period.actual_locations.all():
192             actual_location_element = etree.SubElement(actual_element,
193                                                        "location")
194             actual_location_element.attrib['ref'] = actual_location.location
195 
196         if period.actual_comment:
197             comment_element = etree.SubElement(actual_element, "comment")
198             narrative_element = etree.SubElement(comment_element,
199                                                  "narrative")
200             narrative_element.text = period.actual_comment
201 
202 
203 def add_actual_dimension_elements(is_dgis_project, period, period_element):
204     if (is_dgis_project
205             or has_data(period, ['actual_value', 'narrative', 'actual_comment', ])
206             or has_qs_data(period, ['actual_locations'])):
207 
208         qs = period.disaggregations.select_related('dimension_value', 'dimension_value__name')
209         for period_disaggregation in qs.all():
210             actual_element = etree.SubElement(period_element, "actual")
211 
212             if period_disaggregation.value:
213                 actual_element.attrib['value'] = str(period_disaggregation.value)
214 
215             elif is_dgis_project:
216                 actual_element.attrib['value'] = NOT_AVAILABLE
217 
218             dimension_element = etree.SubElement(actual_element, 'dimension')
219             dimension_element.attrib['value'] = period_disaggregation.dimension_value.value
220             dimension_element.attrib['name'] = period_disaggregation.dimension_value.name.name
221
```
--- 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/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
@@ -67,7 +67,6 @@
 
     if indicator.type == QUALITATIVE:
         indicator_element.attrib['measure'] = '5'
-
     elif indicator.measure:
         indicator_element.attrib['measure'] = indicator.measure
 
@@ -117,10 +116,11 @@
         elif is_dgis_project:
             baseline_element.attrib['year'] = NOT_AVAILABLE_YEAR
 
-        if indicator.baseline_value:
-            baseline_element.attrib['value'] = indicator.baseline_value
-        elif is_dgis_project:
-            baseline_element.attrib['value'] = NOT_AVAILABLE
+        if indicator.type == QUANTITATIVE:
+            if indicator.baseline_value:
+                baseline_element.attrib['value'] = indicator.baseline_value
+            elif is_dgis_project:
+                baseline_element.attrib['value'] = NOT_AVAILABLE
 
         if indicator.baseline_comment:
             comment_element = etree.SubElement(baseline_element, "comment")
@@ -155,10 +155,11 @@
             or has_qs_data(period, ['target_locations', ])):
         target_element = etree.SubElement(period_element, "target")
 
-        if period.target_value:
-            target_element.attrib['value'] = period.target_value
-        elif is_dgis_project:
-            target_element.attrib['value'] = NOT_AVAILABLE
+        if period.indicator.type == QUANTITATIVE:
+            if period.target_value:
+                target_element.attrib['value'] = period.target_value
+            elif is_dgis_project:
+                target_element.attrib['value'] = NOT_AVAILABLE
 
         for target_location in period.target_locations.all():
             target_location_element = etree.SubElement(target_element,

{"golden_diff": "diff --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@@ -67,7 +67,6 @@\n \n     if indicator.type == QUALITATIVE:\n         indicator_element.attrib['measure'] = '5'\n-\n     elif indicator.measure:\n         indicator_element.attrib['measure'] = indicator.measure\n \n@@ -117,10 +116,11 @@\n         elif is_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 is_dgis_project:\n-            baseline_element.attrib['value'] = NOT_AVAILABLE\n+        if indicator.type == QUANTITATIVE:\n+            if indicator.baseline_value:\n+                baseline_element.attrib['value'] = indicator.baseline_value\n+            elif is_dgis_project:\n+                baseline_element.attrib['value'] = NOT_AVAILABLE\n \n         if indicator.baseline_comment:\n             comment_element = etree.SubElement(baseline_element, \"comment\")\n@@ -155,10 +155,11 @@\n             or has_qs_data(period, ['target_locations', ])):\n         target_element = etree.SubElement(period_element, \"target\")\n \n-        if period.target_value:\n-            target_element.attrib['value'] = period.target_value\n-        elif is_dgis_project:\n-            target_element.attrib['value'] = NOT_AVAILABLE\n+        if period.indicator.type == QUANTITATIVE:\n+            if period.target_value:\n+                target_element.attrib['value'] = period.target_value\n+            elif is_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", "issue": "Fix IATI export for qualitative indicators\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\nfrom lxml import etree\n\nfrom akvo.iati.exports.elements.utils import has_data, has_qs_data\nfrom akvo.rsr.models.result.utils import QUANTITATIVE, QUALITATIVE\n\nDGIS_VALIDATION_SET_NAME = \"DGIS IATI\"\nNOT_AVAILABLE = \"N/A\"\nNOT_AVAILABLE_YEAR = \"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 (has_data(res, ['type', 'title', 'description', ])\n                or res.aggregation_status is not None\n                or 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.all():\n                if not indicator.export_to_iati:\n                    continue\n\n                if (has_data(indicator, ['measure', 'title', 'description', 'baseline_year',\n                                         'baseline_value', 'baseline_comment', ])\n                        or indicator.ascending is not None\n                        or has_qs_data(indicator, ['references', 'periods', ])):\n                    add_indicator_element(element, indicator, DGIS_PROJECT)\n\n            result_elements.append(element)\n\n    return result_elements\n\n\ndef add_indicator_element(result_element, indicator, is_dgis_project):\n    indicator_element = etree.SubElement(result_element, \"indicator\")\n\n    if indicator.type == QUALITATIVE:\n        indicator_element.attrib['measure'] = '5'\n\n    elif 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        add_reference_element(indicator_element, reference)\n\n    add_baseline_element(is_dgis_project, indicator_element, indicator)\n\n    for period in indicator.periods.all():\n        add_period_element(is_dgis_project, indicator_element, period)\n\n\ndef add_reference_element(indicator_element, reference):\n    if has_data(reference, ['vocabulary', '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\ndef add_baseline_element(is_dgis_project, indicator_element, indicator):\n    if is_dgis_project or has_data(indicator,\n                                   ['baseline_year', 'baseline_value', '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 is_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 is_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\ndef add_period_element(is_dgis_project, indicator_element, period):\n    if (has_data(period, ['period_start', 'period_end', 'target_value', 'target_comment',\n                          'actual_value', 'narrative', 'actual_comment'])\n            or has_qs_data(period, ['target_locations', 'actual_locations'])):\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        add_target_element(is_dgis_project, period, period_element)\n        # FIXME: We don't yet allow disaggregations on targets\n\n        add_actual_element(is_dgis_project, period, period_element)\n        add_actual_dimension_elements(is_dgis_project, period, period_element)\n\n\ndef add_target_element(is_dgis_project, period, period_element):\n    if (is_dgis_project or has_data(period, ['target_value', 'target_comment', ])\n            or has_qs_data(period, ['target_locations', ])):\n        target_element = etree.SubElement(period_element, \"target\")\n\n        if period.target_value:\n            target_element.attrib['value'] = period.target_value\n        elif is_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        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\ndef add_actual_element(is_dgis_project, period, period_element):\n    if (is_dgis_project\n            or has_data(period, ['actual_value', 'narrative', 'actual_comment', ])\n            or has_qs_data(period, ['actual_locations'])):\n        actual_element = etree.SubElement(period_element, \"actual\")\n\n        if period.indicator.type == QUANTITATIVE:\n            if period.actual_value:\n                actual_element.attrib['value'] = period.actual_value\n            elif is_dgis_project:\n                actual_element.attrib['value'] = NOT_AVAILABLE\n\n        else:\n            if period.narrative:\n                actual_element.attrib['value'] = period.narrative\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        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\ndef add_actual_dimension_elements(is_dgis_project, period, period_element):\n    if (is_dgis_project\n            or has_data(period, ['actual_value', 'narrative', 'actual_comment', ])\n            or has_qs_data(period, ['actual_locations'])):\n\n        qs = period.disaggregations.select_related('dimension_value', 'dimension_value__name')\n        for period_disaggregation in qs.all():\n            actual_element = etree.SubElement(period_element, \"actual\")\n\n            if period_disaggregation.value:\n                actual_element.attrib['value'] = str(period_disaggregation.value)\n\n            elif is_dgis_project:\n                actual_element.attrib['value'] = NOT_AVAILABLE\n\n            dimension_element = etree.SubElement(actual_element, 'dimension')\n            dimension_element.attrib['value'] = period_disaggregation.dimension_value.value\n            dimension_element.attrib['name'] = period_disaggregation.dimension_value.name.name\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 lxml import etree\n\nfrom akvo.iati.exports.elements.utils import has_data, has_qs_data\nfrom akvo.rsr.models.result.utils import QUANTITATIVE, QUALITATIVE\n\nDGIS_VALIDATION_SET_NAME = \"DGIS IATI\"\nNOT_AVAILABLE = \"N/A\"\nNOT_AVAILABLE_YEAR = \"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 (has_data(res, ['type', 'title', 'description', ])\n                or res.aggregation_status is not None\n                or 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.all():\n                if not indicator.export_to_iati:\n                    continue\n\n                if (has_data(indicator, ['measure', 'title', 'description', 'baseline_year',\n                                         'baseline_value', 'baseline_comment', ])\n                        or indicator.ascending is not None\n                        or has_qs_data(indicator, ['references', 'periods', ])):\n                    add_indicator_element(element, indicator, DGIS_PROJECT)\n\n            result_elements.append(element)\n\n    return result_elements\n\n\ndef add_indicator_element(result_element, indicator, is_dgis_project):\n    indicator_element = etree.SubElement(result_element, \"indicator\")\n\n    if indicator.type == QUALITATIVE:\n        indicator_element.attrib['measure'] = '5'\n    elif 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        add_reference_element(indicator_element, reference)\n\n    add_baseline_element(is_dgis_project, indicator_element, indicator)\n\n    for period in indicator.periods.all():\n        add_period_element(is_dgis_project, indicator_element, period)\n\n\ndef add_reference_element(indicator_element, reference):\n    if has_data(reference, ['vocabulary', '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\ndef add_baseline_element(is_dgis_project, indicator_element, indicator):\n    if is_dgis_project or has_data(indicator,\n                                   ['baseline_year', 'baseline_value', '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 is_dgis_project:\n            baseline_element.attrib['year'] = NOT_AVAILABLE_YEAR\n\n        if indicator.type == QUANTITATIVE:\n            if indicator.baseline_value:\n                baseline_element.attrib['value'] = indicator.baseline_value\n            elif is_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\ndef add_period_element(is_dgis_project, indicator_element, period):\n    if (has_data(period, ['period_start', 'period_end', 'target_value', 'target_comment',\n                          'actual_value', 'narrative', 'actual_comment'])\n            or has_qs_data(period, ['target_locations', 'actual_locations'])):\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        add_target_element(is_dgis_project, period, period_element)\n        # FIXME: We don't yet allow disaggregations on targets\n\n        add_actual_element(is_dgis_project, period, period_element)\n        add_actual_dimension_elements(is_dgis_project, period, period_element)\n\n\ndef add_target_element(is_dgis_project, period, period_element):\n    if (is_dgis_project or has_data(period, ['target_value', 'target_comment', ])\n            or has_qs_data(period, ['target_locations', ])):\n        target_element = etree.SubElement(period_element, \"target\")\n\n        if period.indicator.type == QUANTITATIVE:\n            if period.target_value:\n                target_element.attrib['value'] = period.target_value\n            elif is_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        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\ndef add_actual_element(is_dgis_project, period, period_element):\n    if (is_dgis_project\n            or has_data(period, ['actual_value', 'narrative', 'actual_comment', ])\n            or has_qs_data(period, ['actual_locations'])):\n        actual_element = etree.SubElement(period_element, \"actual\")\n\n        if period.indicator.type == QUANTITATIVE:\n            if period.actual_value:\n                actual_element.attrib['value'] = period.actual_value\n            elif is_dgis_project:\n                actual_element.attrib['value'] = NOT_AVAILABLE\n\n        else:\n            if period.narrative:\n                actual_element.attrib['value'] = period.narrative\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        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\ndef add_actual_dimension_elements(is_dgis_project, period, period_element):\n    if (is_dgis_project\n            or has_data(period, ['actual_value', 'narrative', 'actual_comment', ])\n            or has_qs_data(period, ['actual_locations'])):\n\n        qs = period.disaggregations.select_related('dimension_value', 'dimension_value__name')\n        for period_disaggregation in qs.all():\n            actual_element = etree.SubElement(period_element, \"actual\")\n\n            if period_disaggregation.value:\n                actual_element.attrib['value'] = str(period_disaggregation.value)\n\n            elif is_dgis_project:\n                actual_element.attrib['value'] = NOT_AVAILABLE\n\n            dimension_element = etree.SubElement(actual_element, 'dimension')\n            dimension_element.attrib['value'] = period_disaggregation.dimension_value.value\n            dimension_element.attrib['name'] = period_disaggregation.dimension_value.name.name\n", "path": "akvo/iati/exports/elements/result.py"}]}