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

[#1770] Small changes in IATI import code #1850

Merged
merged 1 commit into from
Oct 9, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions akvo/iati/imports/iati_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 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 >.

from ...rsr.models.iati_import import IatiImport
from ...rsr.models.iati_import_log import IatiImportLog
from ...rsr.models.iati_project_import import IatiProjectImport
from .iati_import_activity import IatiImportActivity
Expand Down Expand Up @@ -188,11 +189,11 @@ def __init__(self, iati_import):
self.set_start_date()

# Check or download file
self.set_status(2)
self.set_status(IatiImport.RETRIEVING_STATUS)
if self.check_file():

# Start import process
self.set_status(3)
self.set_status(IatiImport.IN_PROGRESS_STATUS)
self.file = self.iati_import.local_file
self.activities = self.get_activities()
if self.activities and self.check_version():
Expand All @@ -206,10 +207,10 @@ def __init__(self, iati_import):
IatiImportLog.CRITICAL_ERROR)

# Import process complete
self.set_status(4)
self.set_status(IatiImport.COMPLETED_STATUS)

# Finish import
if not self.iati_import.status == 4:
self.set_status(5)
if not self.iati_import.status == IatiImport.COMPLETED_STATUS:
self.set_status(IatiImport.CANCELLED_STATUS)
self.set_end_date()
self.send_mail()
13 changes: 6 additions & 7 deletions akvo/iati/imports/iati_import_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,19 @@ def set_sync_owner(self):
organisation = get_model('rsr', 'organisation').objects.get(iati_org_id=iati_org_id)
except ObjectDoesNotExist:
add_log(self.iati_import, 'reporting_org',
'Reporting organisation not present in RSR.', self.project,
'Reporting organisation not present in RSR', self.project,
IatiImportLog.CRITICAL_ERROR)
return False

if not organisation.can_become_reporting:
add_log(self.iati_import, 'reporting_org',
'Reporting organisation not allowed to import projects in RSR.',
'Reporting organisation not allowed to import projects in RSR',
self.project, IatiImportLog.CRITICAL_ERROR)
return False

if not self.created and sync_owner and sync_owner != organisation:
add_log(self.iati_import, 'sync_owner',
'Project has a different sync_owner (%s).' % sync_owner.name,
'Project has a different sync_owner (%s)' % sync_owner.name,
self.project, IatiImportLog.CRITICAL_ERROR)
return False

Expand All @@ -174,7 +174,7 @@ def set_sync_owner(self):
return True

add_log(self.iati_import, 'reporting_org',
'Reporting organisation not correctly specified.', self.project,
'Reporting organisation not correctly specified', self.project,
IatiImportLog.CRITICAL_ERROR)
return False

Expand Down Expand Up @@ -241,9 +241,8 @@ def __init__(self, iati_import, activity, user, activities_globals):
for field in FIELDS:
try:
with transaction.atomic():
changes = getattr(fields, field)(
self.iati_import, self.activity, self.project, self.globals
)
changes = getattr(fields, field)(self.iati_import, self.activity,
self.project, self.globals)
except Exception as e:
changes = []
add_log(self.iati_import, field, str(e), self.project,
Expand Down
8 changes: 6 additions & 2 deletions akvo/rsr/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,15 @@ def import_iati_file(sender, **kwargs):
"""
iati_import = kwargs.get("instance", None)

if iati_import and iati_import.status == 1:
if iati_import and iati_import.status == get_model('rsr', 'IatiImport').PENDING_STATUS:
post_save.disconnect(import_iati_file, sender=sender)
iati_import.save()
try:
with transaction.atomic():
IatiImportProcess(iati_import)
except Exception as e:
add_log(iati_import, 'general', str(e), None, 1)
add_log(iati_import, 'general', str(e), None,
get_model('rsr', 'IatiImportLog').CRITICAL_ERROR)
iati_import.status = get_model('rsr', 'IatiImport').CANCELLED_STATUS
iati_import.save()
post_save.connect(import_iati_file, sender=sender)
1 change: 0 additions & 1 deletion akvo/templates/iati_import/import_done_message.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ <h2>General information</h2>
<b>Import id:</b> {{ iati_import.pk }}<br/>
<b>Site:</b> {{ site }}<br/>
{% if iati_import.url %}<b>IATI file:</b> <a href="{{ iati_import.url }}">{{ iati_import.url }}</a><br/>{% endif %}
<b>Organisation:</b> {{ iati_import.reporting_organisation.name }} ({{ iati_import.reporting_organisation.iati_org_id }})<br/>
<b>Start date:</b> {{ iati_import.start_date }}<br/>
<b>End date:</b> {{ iati_import.end_date }}<br/>
<b>Number of projects processed:</b> {{ project_count }} ({{ projects_created }} created, {{ projects_updated }} updated)<br/>
Expand Down