Skip to content

Commit

Permalink
[#1770] Added project condition import
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Sep 8, 2015
1 parent 999aef6 commit c311104
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions akvo/iati/imports/fields/__init__.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 .conditions import conditions
from .contacts import contacts
from .dates import actual_end_date, actual_start_date, planned_end_date, planned_start_date
from .defaults import (currency, default_aid_type, default_finance_type, default_flow_type,
Expand All @@ -21,6 +22,7 @@
'actual_end_date',
'actual_start_date',
'background',
'conditions',
'contacts',
'currency',
'current_image',
Expand Down
49 changes: 49 additions & 0 deletions akvo/iati/imports/fields/conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-

# 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 >.

from ..utils import get_text

from django.db.models import get_model


def conditions(activity, project, activities_globals):
"""
Retrieve and store the conditions.
The conditions will be extracted from the 'conditions' elements in the 'conditions' element.
:param activity: ElementTree; contains all data of the activity
:param project: Project instance
:param activities_globals: Dictionary; contains all global activities information
:return: List; contains fields that have changed
"""
imported_conditions = []
changes = []

conditions_element = activity.find('conditions')

if not conditions_element is None and 'attached' in conditions_element.attrib.keys() and \
conditions_element.attrib['attached'] == '1':
for condition in conditions_element.findall('condition'):
condition_type = condition.attrib['type'] if 'type' in condition.attrib.keys() else ''
condition_text = get_text(condition, activities_globals['version'])

cond, created = get_model('rsr', 'projectcondition').objects.get_or_create(
project=project,
type=condition_type,
text=condition_text
)
imported_conditions.append(cond)
if created:
changes.append(u'added condition (id: %s): %s' % (str(cond.pk), cond))

for condition in project.conditions.all():
if not condition in imported_conditions:
changes.append(u'deleted condition (id: %s): %s' %
(str(condition.pk),
condition.__unicode__()))
condition.delete()

return changes
1 change: 1 addition & 0 deletions akvo/iati/imports/iati_import_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'related_projects',
'contacts',
'results',
'conditions',
]


Expand Down

0 comments on commit c311104

Please sign in to comment.