Beispiel #1
0
def show_activity(package_name, iati_identifier):
    refresh = request.args.get("refresh", False)
    iati_identifier = urllib.unquote(iati_identifier)
    url, revision, filepath = fetch.latest_package_version(package_name, refresh)
    fetch.download_package(url, filepath)

    try:
        activity = helpers.fetch_activity(filepath, iati_identifier)
    except:
        return abort(404)
    activity_str = helpers.activity_to_string(activity)

    # load the tests
    all_tests_list = helpers.load_expressions_from_csvfile(config.TESTS_FILE)
    current_test = helpers.select_expression(all_tests_list, request.args.get('test'), config.DEFAULT_TEST)
    tests_to_run = all_tests_list if current_test[0] is None else [current_test[1]]
    # run tests
    activity_results = helpers.test_activity(activity, tests_to_run)

    kwargs = {
        "package_name": package_name,
        "activity": activity_str,
        "activity_results": activity_results,

        "all_tests_list": all_tests_list,
        "tests_run_list": tests_to_run,
        "current_test": current_test,
    }
    return render_template('activity.html', **kwargs)
Beispiel #2
0
def show_package(package_name):
    refresh = request.args.get("refresh", False)
    url, revision, filepath = fetch.latest_package_version(package_name, refresh)
    fetch.download_package(url, filepath)

    # load the tests
    all_tests_list = helpers.load_expressions_from_csvfile(config.TESTS_FILE)
    current_test = helpers.select_expression(all_tests_list, request.args.get('test'), config.DEFAULT_TEST)
    tests_to_run = all_tests_list if current_test[0] is None else [current_test[1]]

    # load and set the filter
    all_filters_list = helpers.load_expressions_from_csvfile(config.FILTERS_FILE)
    current_filter = helpers.select_expression(all_filters_list, request.args.get('filter'), config.DEFAULT_FILTER)

    page = int(request.args.get('page', 1))
    offset = (page - 1) * config.PER_PAGE

    activities, num_activities = helpers.load_and_filter_activities_from_package(filepath, current_filter[1], offset=offset)
    activities_results = [helpers.test_activity(activity, tests_to_run) for activity in activities]

    pagination = Pagination(page, config.PER_PAGE, num_activities)

    kwargs = {
        "package_name": package_name,
        "revision": revision,
        "activities_results": activities_results,

        "all_tests_list": all_tests_list,
        "tests_run_list": tests_to_run,
        "current_test": current_test,

        "all_filters_list": all_filters_list,
        "current_filter": current_filter,

        "pagination": pagination,
    }
    return render_template('package.html', **kwargs)