-
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.
Merge pull request #1583 from akvo/#1447_iati_export_perf
[#1447] IATI export performance
- Loading branch information
Showing
17 changed files
with
311 additions
and
26 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
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,112 @@ | ||
/** @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 >. | ||
|
||
var i18n; | ||
|
||
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); | ||
return true; | ||
} else { | ||
if (retryCount >= retryLimit) { | ||
return false; | ||
} else { | ||
retryCount = retryCount + 1; | ||
loadAsync(url, retryCount, retryLimit); | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
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', | ||
getInitialState: function() { | ||
return {active_button: true}; | ||
}, | ||
|
||
handleClick: function() { | ||
this.setState({active_button: false}); | ||
getProjectLabels(); | ||
}, | ||
|
||
render: function() { | ||
if (this.state.active_button) { | ||
return ( | ||
React.DOM.p(null, | ||
React.DOM.button( {onClick:this.handleClick, className:"btn btn-primary"}, i18n.perform_checks) | ||
) | ||
); | ||
} else { | ||
return ( | ||
React.DOM.p(null) | ||
); | ||
} | ||
} | ||
}); | ||
|
||
React.render( | ||
Container(null ), | ||
document.getElementById(component_id) | ||
); | ||
} | ||
|
||
i18n = JSON.parse(document.getElementById("perform-checks-text").innerHTML); | ||
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,112 @@ | ||
/** @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 >. | ||
|
||
var i18n; | ||
|
||
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); | ||
return true; | ||
} else { | ||
if (retryCount >= retryLimit) { | ||
return false; | ||
} else { | ||
retryCount = retryCount + 1; | ||
loadAsync(url, retryCount, retryLimit); | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
}; | ||
|
||
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({ | ||
getInitialState: function() { | ||
return {active_button: true}; | ||
}, | ||
|
||
handleClick: function() { | ||
this.setState({active_button: false}); | ||
getProjectLabels(); | ||
}, | ||
|
||
render: function() { | ||
if (this.state.active_button) { | ||
return ( | ||
<p> | ||
<button onClick={this.handleClick} className='btn btn-primary'>{i18n.perform_checks}</button> | ||
</p> | ||
); | ||
} else { | ||
return ( | ||
<p></p> | ||
); | ||
} | ||
} | ||
}); | ||
|
||
React.render( | ||
<Container />, | ||
document.getElementById(component_id) | ||
); | ||
} | ||
|
||
i18n = JSON.parse(document.getElementById("perform-checks-text").innerHTML); | ||
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
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
Oops, something went wrong.