-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1447] IATI export: performance increase through React checks
- Loading branch information
1 parent
8af3c9e
commit 88388f4
Showing
9 changed files
with
238 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from akvo.rsr.models import Project | ||
from django.http import Http404 | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
|
||
|
||
class ProjectIatiCheckView(APIView): | ||
""" | ||
List the result of IATI checks of a Project. | ||
""" | ||
def get_object(self, pk): | ||
try: | ||
return Project.objects.get(pk=pk) | ||
except Project.DoesNotExist: | ||
raise Http404 | ||
|
||
def get(self, request, pk, format=None): | ||
project = self.get_object(pk) | ||
check_results = project.check_mandatory_fields() | ||
response = { | ||
'all_checks_passed': str(check_results[0]), | ||
'checks': check_results[1], | ||
} | ||
|
||
return Response(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** @jsx React.DOM */ | ||
|
||
// Akvo RSR is covered by the GNU Affero General Public License. | ||
// See more details in the license.txt file located at the root folder of the | ||
// Akvo RSR module. For additional details on the GNU license please see | ||
// < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
|
||
function loadAsync(url, retryCount, retryLimit, label) { | ||
var xmlHttp; | ||
|
||
xmlHttp = new XMLHttpRequest(); | ||
|
||
xmlHttp.onreadystatechange = function() { | ||
if (xmlHttp.readyState == XMLHttpRequest.DONE) { | ||
|
||
if(xmlHttp.status == 200){ | ||
processResponse(label, xmlHttp.responseText); | ||
} else { | ||
if (retryCount >= retryLimit) { | ||
return; | ||
} else { | ||
retryCount = retryCount + 1; | ||
loadAsync(url, retryCount, retryLimit); | ||
} | ||
} | ||
} else { | ||
return; | ||
} | ||
}; | ||
|
||
xmlHttp.open("GET", url, true); | ||
xmlHttp.send(); | ||
} | ||
|
||
function processResponse(label, response) { | ||
var label_content, checks, all_checks_passed, span; | ||
|
||
label_content = label.innerHTML; | ||
checks = JSON.parse(response); | ||
|
||
all_checks_passed = checks.all_checks_passed; | ||
|
||
if (all_checks_passed === "True") { | ||
span = document.createElement("span"); | ||
span.className = "success"; | ||
span.innerHTML = label_content; | ||
|
||
label.innerHTML = ''; | ||
label.appendChild(span); | ||
|
||
} else if (all_checks_passed === "False") { | ||
span = document.createElement("span"); | ||
span.className = "error"; | ||
span.innerHTML = label_content; | ||
|
||
label.innerHTML = ''; | ||
label.appendChild(span); | ||
} | ||
} | ||
|
||
function getProjectLabels() { | ||
var labels; | ||
|
||
labels = document.getElementById('id_projects').getElementsByTagName('label'); | ||
|
||
for (var i = 0; i < labels.length; i++) { | ||
var project_id; | ||
|
||
project_id = labels[i].getElementsByTagName('input')[0].value; | ||
loadAsync('/rest/v1/project_iati_check/' + project_id + '/?format=json', 0, 3, labels[i]); | ||
} | ||
} | ||
|
||
function loadComponent(component_id) { | ||
var Container; | ||
|
||
Container = React.createClass({displayName: 'Container', | ||
render: function() { | ||
return ( | ||
React.DOM.a( {onClick:getProjectLabels}, "Perform checks") | ||
); | ||
} | ||
}); | ||
|
||
React.render( | ||
Container(null ), | ||
document.getElementById(component_id) | ||
); | ||
} | ||
|
||
loadComponent('react_iati_checks'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** @jsx React.DOM */ | ||
|
||
// Akvo RSR is covered by the GNU Affero General Public License. | ||
// See more details in the license.txt file located at the root folder of the | ||
// Akvo RSR module. For additional details on the GNU license please see | ||
// < http://www.gnu.org/licenses/agpl.html >. | ||
|
||
|
||
function loadAsync(url, retryCount, retryLimit, label) { | ||
var xmlHttp; | ||
|
||
xmlHttp = new XMLHttpRequest(); | ||
|
||
xmlHttp.onreadystatechange = function() { | ||
if (xmlHttp.readyState == XMLHttpRequest.DONE) { | ||
|
||
if(xmlHttp.status == 200){ | ||
processResponse(label, xmlHttp.responseText); | ||
} else { | ||
if (retryCount >= retryLimit) { | ||
return; | ||
} else { | ||
retryCount = retryCount + 1; | ||
loadAsync(url, retryCount, retryLimit); | ||
} | ||
} | ||
} else { | ||
return; | ||
} | ||
}; | ||
|
||
xmlHttp.open("GET", url, true); | ||
xmlHttp.send(); | ||
} | ||
|
||
function processResponse(label, response) { | ||
var label_content, checks, all_checks_passed, span; | ||
|
||
label_content = label.innerHTML; | ||
checks = JSON.parse(response); | ||
|
||
all_checks_passed = checks.all_checks_passed; | ||
|
||
if (all_checks_passed === "True") { | ||
span = document.createElement("span"); | ||
span.className = "success"; | ||
span.innerHTML = label_content; | ||
|
||
label.innerHTML = ''; | ||
label.appendChild(span); | ||
|
||
} else if (all_checks_passed === "False") { | ||
span = document.createElement("span"); | ||
span.className = "error"; | ||
span.innerHTML = label_content; | ||
|
||
label.innerHTML = ''; | ||
label.appendChild(span); | ||
} | ||
} | ||
|
||
function getProjectLabels() { | ||
var labels; | ||
|
||
labels = document.getElementById('id_projects').getElementsByTagName('label'); | ||
|
||
for (var i = 0; i < labels.length; i++) { | ||
var project_id; | ||
|
||
project_id = labels[i].getElementsByTagName('input')[0].value; | ||
loadAsync('/rest/v1/project_iati_check/' + project_id + '/?format=json', 0, 3, labels[i]); | ||
} | ||
} | ||
|
||
function loadComponent(component_id) { | ||
var Container; | ||
|
||
Container = React.createClass({ | ||
render: function() { | ||
return ( | ||
<a onClick={getProjectLabels}>Perform checks</a> | ||
); | ||
} | ||
}); | ||
|
||
React.render( | ||
<Container />, | ||
document.getElementById(component_id) | ||
); | ||
} | ||
|
||
loadComponent('react_iati_checks'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters