Skip to content

Commit

Permalink
Merge pull request #1620 from akvo/#1618-iati-export
Browse files Browse the repository at this point in the history
[#1618] Improve IATI export
  • Loading branch information
kardan committed Jun 23, 2015
2 parents 7a4156a + 0a2106a commit 41f9c67
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 33 deletions.
15 changes: 9 additions & 6 deletions akvo/iati/checks/v201.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,9 @@ def results(self):
u'specified' % str(result.pk)))

if not result.title:
checks.append((u'warning', u'result (id: %s) has no title '
u'specified' % str(result.pk)))
self.all_checks_passed = False
checks.append((u'error', u'result (id: %s) has no title '
u'specified' % str(result.pk)))

if not result.indicators.all() and not result.description:
self.all_checks_passed = False
Expand All @@ -634,12 +635,14 @@ def results(self):

for indicator in result.indicators.all():
if not indicator.measure:
checks.append((u'warning', u'indicator (id: %s) has no measure '
u'specified' % str(indicator.pk)))
self.all_checks_passed = False
checks.append((u'error', u'indicator (id: %s) has no measure '
u'specified' % str(indicator.pk)))

if not indicator.title:
checks.append((u'warning', u'indicator (id: %s) has no title '
u'specified' % str(indicator.pk)))
self.all_checks_passed = False
checks.append((u'error', u'indicator (id: %s) has no title '
u'specified' % str(indicator.pk)))

if (indicator.baseline_value and not indicator.baseline_year) or \
(not indicator.baseline_value and indicator.baseline_year):
Expand Down
28 changes: 14 additions & 14 deletions akvo/iati/elements/document_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def document_link(project):
current_image_element.attrib['url'] = "http://rsr.akvo.org" + project.current_image.url
current_image_element.attrib['format'] = "image/jpeg"

title_element = etree.SubElement(current_image_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")

if project.current_image_caption or project.current_image_credit:
title_element = etree.SubElement(current_image_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")
if project.current_image_caption and project.current_image_credit:
narrative_element.text = "%s, credit: %s" % (
project.current_image_caption,
Expand All @@ -33,6 +34,8 @@ def document_link(project):
narrative_element.text = project.current_image_caption
elif project.current_image_credit:
narrative_element.text = "Credit: %s" % (project.current_image_credit,)
else:
narrative_element.text = "Project photo"

category_element = etree.SubElement(current_image_element, "category")
category_element.attrib['code'] = "A12"
Expand All @@ -45,10 +48,9 @@ def document_link(project):
link_element.attrib['url'] = link.url
link_element.attrib['format'] = "application/http"

if link.caption:
title_element = etree.SubElement(link_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")
narrative_element.text = link.caption
title_element = etree.SubElement(link_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")
narrative_element.text = link.caption if link.caption else "Project link"

category_element = etree.SubElement(link_element, "category")
category_element.attrib['code'] = "A12"
Expand All @@ -67,10 +69,9 @@ def document_link(project):
if document.format:
document_element.attrib['format'] = document.format

if document.title:
title_element = etree.SubElement(document_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")
narrative_element.text = document.title
title_element = etree.SubElement(document_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")
narrative_element.text = document.title if document.title else "Project document"

if document.category:
category_element = etree.SubElement(document_element, "category")
Expand All @@ -87,10 +88,9 @@ def document_link(project):
update_element.attrib['url'] = "http://rsr.akvo.org/project/%s/update/%s/" % (str(project.pk), str(update.pk))
update_element.attrib['format'] = "application/http"

if update.title:
title_element = etree.SubElement(update_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")
narrative_element.text = update.title
title_element = etree.SubElement(update_element, "title")
narrative_element = etree.SubElement(title_element, "narrative")
narrative_element.text = update.title if update.title else "Project update"

category_element = etree.SubElement(update_element, "category")
category_element.attrib['code'] = "A12"
Expand Down
2 changes: 1 addition & 1 deletion akvo/iati/elements/reporting_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def reporting_org(project):
element.attrib['ref'] = org.iati_org_id

if project.sync_owner_secondary_reporter is not None:
element.attrib['secondary_reporter'] = '1' if project.sync_owner_secondary_reporter else '0'
element.attrib['secondary-reporter'] = '1' if project.sync_owner_secondary_reporter else '0'

if org.new_organisation_type:
element.attrib['type'] = str(org.new_organisation_type)
Expand Down
3 changes: 0 additions & 3 deletions akvo/iati/elements/sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def sector(project):
if sec.percentage:
element.attrib['percentage'] = str(sec.percentage)

if sec.text:
element.text = sec.text

sector_elements.append(element)

return sector_elements
10 changes: 9 additions & 1 deletion akvo/rsr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,18 @@ def __init__(self, user, *args, **kwargs):
)


class CustomLabelModelChoiceField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj):
if obj.is_published():
return mark_safe(u'<span class="noCheck">%s</span>' % obj.__unicode__())
else:
return mark_safe(u'<span class="noCheck">%s (not published)</span>' % obj.__unicode__())


class IatiExportForm(forms.ModelForm):
"""Form for adding an entry to the IATI export model."""
is_public = forms.BooleanField(required=False, label=_(u"Show IATI file on organisation page"))
projects = forms.ModelMultipleChoiceField(
projects = CustomLabelModelChoiceField(
widget=forms.CheckboxSelectMultiple,
queryset=Project.objects.all(),
label=_(u"Select the projects included in the export:")
Expand Down
13 changes: 10 additions & 3 deletions akvo/rsr/static/scripts-src/my-iati.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ function loadAsync(url, retryCount, retryLimit, label) {
}

function processResponse(label, response) {
var label_content, checks, all_checks_passed, span;
var label_content, checks, all_checks_passed, span, checks_response;

label_content = label.innerHTML;
label_content = label.innerHTML.replace("noCheck", "");
checks = JSON.parse(response);

all_checks_passed = checks.all_checks_passed;
checks_response = checks.checks;

if (all_checks_passed === "True") {
span = document.createElement("span");
Expand All @@ -51,9 +52,15 @@ function processResponse(label, response) {
label.innerHTML = '';
label.appendChild(span);

} else if (all_checks_passed === "False") {
} else {
span = document.createElement("span");
span.className = "error";
label_content += "<br/>";
for (var i = 0; i < checks_response.length; i++) {
if (checks_response[i][0] === "error") {
label_content += "- " + checks_response[i][1] + "<br/>";
}
}
span.innerHTML = label_content;

label.innerHTML = '';
Expand Down
13 changes: 10 additions & 3 deletions akvo/rsr/static/scripts-src/my-iati.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ function loadAsync(url, retryCount, retryLimit, label) {
}

function processResponse(label, response) {
var label_content, checks, all_checks_passed, span;
var label_content, checks, all_checks_passed, span, checks_response;

label_content = label.innerHTML;
label_content = label.innerHTML.replace("noCheck", "");
checks = JSON.parse(response);

all_checks_passed = checks.all_checks_passed;
checks_response = checks.checks;

if (all_checks_passed === "True") {
span = document.createElement("span");
Expand All @@ -51,9 +52,15 @@ function processResponse(label, response) {
label.innerHTML = '';
label.appendChild(span);

} else if (all_checks_passed === "False") {
} else {
span = document.createElement("span");
span.className = "error";
label_content += "<br/>";
for (var i = 0; i < checks_response.length; i++) {
if (checks_response[i][0] === "error") {
label_content += "- " + checks_response[i][1] + "<br/>";
}
}
span.innerHTML = label_content;

label.innerHTML = '';
Expand Down
9 changes: 7 additions & 2 deletions akvo/templates/myrsr/my_iati.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
{% block head %}
{{block.super}}
<style>
span.noCheck {
color: black;
}
span.error {
color: indianred;
}
Expand All @@ -27,6 +30,7 @@ <h3>{% trans "My IATI" %}{% if selected_org %} {% trans "for" %} {{selected_org.
{% endif %}
{% trans 'IATI stands for International Aid Transparency Initiative, which is a global reporting standard that makes it possible to compare and compile data sets from different projects and organisations. On this page it is possible to export an IATI file of the projects of your organisation or view previously exported files.' %}
{% if not selected_org %}
<br/><br/>
{% trans 'Since your account is connected to multiple organisations, please select an organisation first.' %}
<p>
<form method="" action="" id="select_org_form">
Expand All @@ -41,11 +45,12 @@ <h3>{% trans "My IATI" %}{% if selected_org %} {% trans "for" %} {{selected_org.
</form>
</p>
{% elif project_count > 0 %}
<br/><br/>
<p>
{% blocktrans %}
In order to see which of your projects is fully IATI compliant, you can
perform checks by clicking the "Perform checks" button. <br/>
Projects with all mandatory IATI information filled in will be
perform checks by clicking the "Perform checks" button. Projects with all
mandatory IATI information filled in will be
marked <span class="success">green</span> and projects with missing
information will be marked <span class="error">red</span>.
{% endblocktrans %}
Expand Down

0 comments on commit 41f9c67

Please sign in to comment.