Beispiel #1
0
def reporting_org(element, resource=no_resource, major_version='1'):
    try:
        xml = element.xpath("./reporting-org")[0]
    except IndexError:
        if major_version == '1':
            return None
        raise
    data = {
        "ref": xval(xml, "@ref"),
        "name": xval(xml, TEXT_ELEMENT[major_version], u""),
    }
    try:
        data.update({
            "type":
            codelists.by_major_version[major_version].OrganisationType.
            from_string(xval(xml, "@type"))
        })
    except (MissingValue, ValueError) as exe:
        data['type'] = None
        iati_identifier = xval(xml, "/iati-identifier/text()", 'no_identifier')
        log.warn(_(
            u"Failed to import a valid reporting-org.type in activity {0}, error was: {1}"
            .format(iati_identifier, exe),
            logger='activity_importer',
            dataset=resource.dataset_id,
            resource=resource.url),
                 exc_info=exe)

    return Organisation.as_unique(db.session, **data)
Beispiel #2
0
def reporting_org(element, resource=no_resource, major_version='1'):
    try:
        xml = element.xpath("./reporting-org")[0]
    except IndexError:
        if major_version == '1':
            return None
        raise
    data = {
        "ref": xval(xml, "@ref"),
        "name": xval(xml, TEXT_ELEMENT[major_version], u""),
    }
    try:
        data.update({
            "type": codelists.by_major_version[major_version].OrganisationType.from_string(xval(xml, "@type"))
        })
    except (MissingValue, ValueError) as exe:
        data['type'] = None
        iati_identifier = xval(xml, "/iati-identifier/text()", 'no_identifier')
        log.warn(
            _(u"Failed to import a valid reporting-org.type in activity {0}, error was: {1}".format(
                iati_identifier, exe),
            logger='activity_importer', dataset=resource.dataset_id, resource=resource.url),
            exc_info=exe
        )

    return Organisation.as_unique(db.session, **data)
Beispiel #3
0
def participating_orgs(xml):
    ret = []
    seen = set()
    for ele in [e for e in xml if e.xpath("@ref")]:
        role = cl.OrganisationRole.from_string(xval(ele, "@role").title())
        organisation = Organisation.as_unique(db.session, ref=xval(ele, "@ref"))
        if not (role, organisation.ref) in seen:
            seen.add((role, organisation.ref))
            ret.append(Participation(role=role, organisation=organisation))
    return ret
Beispiel #4
0
def parse_org(xml, resource=no_resource):
    data = {
        "ref": xval(xml, "@ref", u""),
        "name": xval(xml, 'text()', u""),
    }
    try:
        data['type'] = cl.OrganisationType.from_string(xval(xml, "@type"))
    except (MissingValue, ValueError):
        data['type'] = None
    return Organisation.as_unique(db.session, **data)
Beispiel #5
0
def parse_org(xml, resource=no_resource):
    data = {
        "ref": xval(xml, "@ref", u""),
        "name": xval(xml, 'text()', u""),
    }
    try:
        data['type'] = cl.OrganisationType.from_string(xval(xml, "@type"))
    except (MissingValue, ValueError):
        data['type'] = None
    return Organisation.as_unique(db.session, **data)
Beispiel #6
0
def parse_org(xml, resource=no_resource, major_version='1'):
    data = {
        "ref": xval(xml, "@ref", u""),
        "name": xval(xml, TEXT_ELEMENT[major_version], u""),
    }
    try:
        data['type'] = codelists.by_major_version[major_version].OrganisationType.from_string(xval(xml, "@type"))
    except (MissingValue, ValueError):
        data['type'] = None
    return Organisation.as_unique(db.session, **data)
Beispiel #7
0
def reporting_org(xml):
    data = {
        "ref": xval(xml, "@ref"),
        "name": xval(xml, 'text()', u""),
    }
    try:
        data.update({
            "type": cl.OrganisationType.from_string(xval(xml, "@type"))
        })
    except MissingValue:
        pass
    return Organisation.as_unique(db.session, **data)
Beispiel #8
0
def reporting_org(element, resource=no_resource):
    xml = element.xpath("./reporting-org")[0]
    data = {
        "ref": xval(xml, "@ref"),
        "name": xval(xml, 'text()', u""),
    }
    try:
        data.update({
            "type": cl.OrganisationType.from_string(xval(xml, "@type"))
        })
    except (MissingValue, ValueError) as exe:
        data['type'] = None
        iati_identifier = xval(xml, "/iati-identifier/text()", 'no_identifier')
        log.warn(
            _(u"Failed to import a valid reporting-org.type in activity {0}, error was: {1}".format(
                iati_identifier, exe),
            logger='activity_importer', dataset=resource.dataset_id, resource=resource.url),
            exc_info=exe
        )

    return Organisation.as_unique(db.session, **data)
Beispiel #9
0
def reporting_org(element, resource=no_resource):
    xml = element.xpath("./reporting-org")[0]
    data = {
        "ref": xval(xml, "@ref"),
        "name": xval(xml, 'text()', u""),
    }
    try:
        data.update(
            {"type": cl.OrganisationType.from_string(xval(xml, "@type"))})
    except (MissingValue, ValueError) as exe:
        data['type'] = None
        iati_identifier = xval(xml, "/iati-identifier/text()", 'no_identifier')
        log.warn(_(
            u"Failed to import a valid reporting-org.type in activity {0}, error was: {1}"
            .format(iati_identifier, exe),
            logger='activity_importer',
            dataset=resource.dataset_id,
            resource=resource.url),
                 exc_info=exe)

    return Organisation.as_unique(db.session, **data)
Beispiel #10
0
 def from_org(org):
     return Organisation.as_unique(db.session, ref=org) if org else None