Skip to content

Commit

Permalink
[#1618] Update of 'Perform checks' functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Jun 16, 2015
1 parent 0256b70 commit b4fc345
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
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 b4fc345

Please sign in to comment.