Skip to content

Instantly share code, notes, and snippets.

@zzgvh
Created October 1, 2015 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zzgvh/834b2c7b964bb57aa360 to your computer and use it in GitHub Desktop.
Save zzgvh/834b2c7b964bb57aa360 to your computer and use it in GitHub Desktop.
from akvo.rsr.fields import ValidXMLCharField
from akvo.rsr.models import Transaction
class IATITransaction():
def __init__(self, transaction, iati_import, activity, project, activities_globals):
self.transaction = transaction
self.iati_import = iati_import
self.activity = activity
self.project = project
self.activities_globals = activities_globals
excludes = ['project']
transaction_fields = Transaction._meta.get_all_field_names()
for f in [field for field in transaction_fields if not field in excludes]:
getattr(self, f, self.default)(f)
def default(self, field):
if isinstance(Transaction._meta.get_field(field), ValidXMLCharField):
element = self.transaction.find(field.replace("_", "-"))
if element and 'code' in element.attrib.keys():
max_length = Transaction._meta.get_field(field).max_length
if len(element.attrib['code']) <= max_length:
return element.attrib['code']
else:
add_log(self.iati_import, field,
'code too long ({} characters allowed)'.format(max_length), self.project)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment