elif project_count == 1:
                        pk = project.response.json()['objects'][0]['id']
                        ok, message, data = put_an_activity(
                            activities[i], pk, user)
                        log(message, data)
                        print message.format(**data)
                    elif project_count > 1:
                        data = dict(iati_id=iati_id,
                                    event=ERROR_MULTIPLE_OBJECTS,
                                    extra=internal_id)
                        log(None, data)
                        print(
                            "**** Error updating iati-activity: {iati_id}. "
                            "More than one project with internal ID {extra} exists."
                            .format(**data))
                else:
                    message = "Iati-activity {iati_id} has no participating-orgs, aborting"
                    data = dict(
                        iati_id=iati_id,
                        event=ERROR_NO_ORGS,
                    )
                    log(message, data)
                    print(message.format(**data))


if __name__ == '__main__':
    upload_activities(sys.argv)
    log_file = init_log(CORDAID_UPLOAD_CSV_FILE)
    names = (u'iati_id', u'pk', u'event', u'extra')
    print_log(log_file, names)
示例#2
0
                activity.get(AKVO_NS + 'photo-id')
            ] = dict(
                internal_project_id=activity.get(AKVO_NS + 'internal-project-id'),
                image_caption=activity.get(AKVO_NS + 'image-caption', '').strip(),
                image_credit=activity.get(AKVO_NS + 'photo-credit', '').strip(),
            )
            cordaid_budget = activity.findall('budget[@' + AKVO_NS + 'budget-from="Cordaid"]')
            others_budget = activity.findall('budget[@' + AKVO_NS + 'budget-from="Others"]')
            budgets.append(
                dict(
                    internal_project_id=activity.get(AKVO_NS + 'internal-project-id'),
                    cordaid_funding=Decimal(cordaid_budget[0].find('value').text if cordaid_budget else 0),
                    others_funding=Decimal(others_budget[0].find('value').text if others_budget else 0),
                )
            )
            publishing_statuses[
                activity.get(AKVO_NS + 'internal-project-id')
            ] = activity.get(AKVO_NS + 'publish') == 'true'
        return photos, budgets, publishing_statuses


if __name__ == '__main__':
    django.setup()
    photos, budgets, publishing_statuses = get_post_process_data()
    set_publishing_status(publishing_statuses)
    import_images(CORDAID_PROJECT_IMAGES_DIR, photos)
    fix_funding(budgets)
    log_file = init_log(CORDAID_ACTIVITIES_CSV_FILE)
    names = ('internal_id', 'pk', 'label', 'event', 'extra')
    print_log(log_file, names)
                    import pdb
                    pdb.set_trace()
                    ok, pk = find_org(user_cred, reporting_org_id,
                                      internal_org_id)
                    if pk:
                        ok, message, data = put_an_org(organisations[i],
                                                       user_cred, pk)
                        log(message, data)
                        print message.format(**data)
                    else:
                        ok, message, data = post_an_org(
                            organisations[i], user_cred)
                        log(message, data)
                        print message.format(**data)
                        if ok:
                            post_an_internal_id(user_cred, reporting_org_id,
                                                internal_org_id, data['pk'])
                else:
                    print "No internal org ID"


if __name__ == '__main__':
    import pdb
    pdb.set_trace()
    upload_organisations(sys.argv)
    log_file = init_log(ORGANISATIONS_UPLOAD_LOG_FILE)
    names = (u'pk', u'other_id', u'event', u'extra')
    print_log(log_file, names)

STATIC_ROOT = "/var/akvo/rsr/static/"
STATIC_URL = "/static/"
示例#4
0

def get_organisation_type(new_organisation_type):
    types = dict(zip([int(type) for type, name in IATI_LIST_ORGANISATION_TYPE[1:]],
                     Organisation.NEW_TO_OLD_TYPES
                     ))
    return types[new_organisation_type]


def normalize_url(url):
    if url is None:
        return ""
    url = url.strip().lower()
    if url and not url.startswith("http"):
        if url.startswith("www"):
            url = u"http://%s" % url
        else:
            url = u""
    return url

if __name__ == '__main__':
    django.setup()
    # business_units = import_cordaid_benchmarks(CORDAID_INDICATORS_CSV)
    business_units = find_benchmarknames_and_BUs()
    business_units = find_cordaid_business_units(business_units)
    create_cats_and_benches(business_units)
    # import_orgs(CORDAID_ORGANISATIONS_XML)
    log_file = init_log(CORDAID_ORG_CSV_FILE)
    names = (u'internal_id', u'pk', u'label', u'event', u'extra')
    print_log(log_file, names, True)
示例#5
0
                activity.get(AKVO_NS + 'photo-id')
            ] = dict(
                internal_project_id=activity.get(AKVO_NS + 'internal-project-id'),
                image_caption=activity.get(AKVO_NS + 'image-caption', '').strip(),
                image_credit=activity.get(AKVO_NS + 'photo-credit', '').strip(),
            )
            cordaid_budget = activity.findall('budget[@' + AKVO_NS + 'budget-from="Cordaid"]')
            others_budget = activity.findall('budget[@' + AKVO_NS + 'budget-from="Others"]')
            budgets.append(
                dict(
                    internal_project_id=activity.get(AKVO_NS + 'internal-project-id'),
                    cordaid_funding=Decimal(cordaid_budget[0].find('value').text if cordaid_budget else 0),
                    others_funding=Decimal(others_budget[0].find('value').text if others_budget else 0),
                )
            )
            publishing_statuses[
                activity.get(AKVO_NS + 'internal-project-id')
            ] = activity.get(AKVO_NS + 'publish') == 'true'
        return photos, budgets, publishing_statuses


if __name__ == '__main__':
    django.setup()
    photos, budgets, publishing_statuses = get_post_process_data()
    set_publishing_status(publishing_statuses)
    import_images(CORDAID_PROJECT_IMAGES_DIR, photos)
    fix_funding(budgets)
    log_file = init_log(CORDAID_ACTIVITIES_CSV_FILE)
    names = (u'internal_id', u'pk', u'label', u'event', u'extra')
    print_log(log_file, names)
示例#6
0
                    ok, pk = find_org(user_cred, reporting_org_id,
                                      internal_org_id)
                    if pk:
                        ok, message, data = put_an_org(organisations[i],
                                                       user_cred, pk)
                        log(message, data)
                        print message.format(**data)
                    else:
                        ok, message, data = post_an_org(
                            organisations[i], user_cred)
                        log(message, data)
                        print message.format(**data)
                        if ok:
                            post_an_internal_id(user_cred, reporting_org_id,
                                                internal_org_id, data['pk'])
                else:
                    print "No internal org ID"


if __name__ == '__main__':
    django.setup()
    import pdb
    pdb.set_trace()
    upload_organisations(sys.argv)
    log_file = init_log(ORGANISATIONS_UPLOAD_LOG_FILE)
    names = (u'pk', u'other_id', u'event', u'extra')
    print_log(log_file, names)

STATIC_ROOT = "/var/akvo/rsr/static/"
STATIC_URL = "/static/"
示例#7
0
def get_organisation_type(new_organisation_type):
    types = dict(
        zip([int(type) for type, name in IATI_LIST_ORGANISATION_TYPE[1:]],
            Organisation.NEW_TO_OLD_TYPES))
    return types[new_organisation_type]


def normalize_url(url):
    if url is None:
        return ""
    url = url.strip().lower()
    if url and not url.startswith("http"):
        if url.startswith("www"):
            url = u"http://%s" % url
        else:
            url = u""
    return url


if __name__ == '__main__':
    django.setup()
    # business_units = import_cordaid_benchmarks(CORDAID_INDICATORS_CSV)
    business_units = find_benchmarknames_and_BUs()
    business_units = find_cordaid_business_units(business_units)
    create_cats_and_benches(business_units)
    # import_orgs(CORDAID_ORGANISATIONS_XML)
    log_file = init_log(CORDAID_ORG_CSV_FILE)
    names = (u'internal_id', u'pk', u'label', u'event', u'extra')
    print_log(log_file, names, True)
                    if not ok:
                        continue #error msg already output
                    project_count = project.response.json()['meta']['total_count']
                    if project_count == 0:
                        ok, message, data = post_an_activity(activities[i], user)
                        log(message, data)
                        print message.format(**data)
                    elif project_count == 1:
                        pk = project.response.json()['objects'][0]['id']
                        ok, message, data = put_an_activity(activities[i], pk, user)
                        log(message, data)
                        print message.format(**data)
                    elif project_count > 1:
                        data = dict(iati_id=iati_id, event=ERROR_MULTIPLE_OBJECTS, extra=internal_id)
                        log(None, data)
                        print(
                            "**** Error updating iati-activity: {iati_id}. "
                                "More than one project with internal ID {extra} exists.".format(**data)
                        )
                else:
                    message = "Iati-activity {iati_id} has no participating-orgs, aborting"
                    data = dict(iati_id = iati_id, event = ERROR_NO_ORGS,)
                    log(message, data)
                    print(message.format(**data))

if __name__ == '__main__':
    upload_activities(sys.argv)
    log_file = init_log(CORDAID_UPLOAD_CSV_FILE)
    names = (u'iati_id', u'pk', u'event', u'extra')
    print_log(log_file, names)