Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Transform" section, with merge indicators by title #1369

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions cove_iati/templates/cove_iati/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,31 @@ <h4><span class="glyphicon glyphicon-new-window"></span> Preview</h4>
</div>
{% endblock download_and_share %}

{% block transforms %}
<div class="panel panel-default">
<div class="panel-heading panel-heading-explore" data-toggle="collapse" data-target="#transform-body">
<h3 class="panel-title panel-title-explore"><span class="glyphicon glyphicon-wrench"></span>
{% trans "Transform" %}
<span class="glyphicon glyphicon-collapse-down pull-right"></span>
</h3>
</div>
<div id="transform-body" class="collapse {% if suffix %}in{% endif %}">
<div class="panel-body">
<p>
<h4>Merge indicators by title</h4>
<p>This function will merge together any indicators in the result block, that share the same title. No other data will be altered or changed. This function is designed for instances where multiple periods exist within the same result/indicator, but are not uniquely referenced in the IATI standard or CoVE spreadsheet.<p/>
{% if merge_indicator_output %}
<p><a href="{{ merge_indicator_output }}">Output (xml)</a> {{ merge_indicator_output_file_size|filesizeformat }}</p>
<p><a target="_blank" href="http://d-preview.codeforiati.org/upload?xmlurl={{ request.scheme }}://{{ request.get_host }}{{ merge_indicator_output }}" class="btn btn-success btn-sm">Generate a d-preview</a></p>
{% else %}
<p><a href="{% url 'explore_suffix' data_uuid 'merge_indicator' %}" class="btn btn-success btn-sm">Run</a></p>
{% endif %}
</p>
</div>
</div>
</div>
{% endblock %}

{% endblock explore_content %}

{% block extrafooterscript %}
Expand Down
1 change: 1 addition & 0 deletions cove_iati/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

urlpatterns = [
url(r'^$', cove_iati.views.data_input_iati, name='index'),
url(r'^data/(.+)/(.+)$', cove_iati.views.explore_iati, name='explore_suffix'),
url(r'^data/(.+)$', cove_iati.views.explore_iati, name='explore'),
url(r'^api_test', cove_iati.views.api_test, name='api_test'),
] + urlpatterns
Expand Down
18 changes: 17 additions & 1 deletion cove_iati/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.utils.translation import ugettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
import iatiutils.merge_indicator
from libcove.config import LibCoveConfig
from libcove.lib.converters import convert_spreadsheet, convert_json

Expand Down Expand Up @@ -86,6 +87,8 @@ def explore_data_context_iati(request, context, db_data, error):
else:
data_file = db_data.original_file.file.name

context['data_file'] = data_file

tree = get_tree(data_file)
context = common_checks_context_iati(context, db_data.upload_dir(), data_file, file_type, tree)
context['first_render'] = not db_data.rendered
Expand All @@ -112,7 +115,7 @@ def explore_data_context_iati(request, context, db_data, error):


@cove_web_input_error
def explore_iati(request, pk):
def explore_iati(request, pk, suffix=None):
context, db_data, error = explore_data_context(request, pk, get_file_type)
if error:
return error
Expand All @@ -137,6 +140,19 @@ def explore_iati(request, pk):
else:
with open(cached_context_path, 'w') as fp:
json.dump(context, fp)

merge_indicator_output_file_path = os.path.join(db_data.upload_dir(), "merged.xml")
if suffix == 'merge_indicator':
if not os.path.exists(merge_indicator_output_file_path):
with open(context["data_file"]) as input_file, open(merge_indicator_output_file_path, "wb") as output_file:
iatiutils.merge_indicator.merge_indicator(input_file, output_file)
with open(cached_context_path, 'w') as fp:
json.dump(context, fp)
if os.path.exists(merge_indicator_output_file_path):
upload_url = db_data.upload_url()
context["merge_indicator_output_file_size"] = os.path.getsize(merge_indicator_output_file_path)
context["merge_indicator_output"] = "{}{}{}".format(upload_url, "" if upload_url.endswith("/") else "/", "merged.xml")
context['suffix'] = suffix
return render(request, 'cove_iati/explore.html', context)


Expand Down
1 change: 1 addition & 0 deletions requirements_iati.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
# We've not done this yet because this requires changes to cove, and some
# careful testing, which we currently don't have time to do.
-e git+https://github.com/OpenDataServices/bdd-tester.git@e1a1a578e28222904f3f1567409b068222ec02e6#egg=bdd-tester
-e git+https://github.com/OpenDataServices/iati-utils.git@704fa589ad2d3743d3928dcbeeeb06a5e73f8437#egg=iatiutils