def organisation_publication_complete(organisation_code, aggregation_type):
    aggregation_type=integerise(request.args.get('aggregation_type', 2))
    all_aggregation_types = dqaggregationtypes.aggregationTypes()

    organisation = Organisation.query.filter_by(
        organisation_code=organisation_code).first_or_404()

    aggregate_results = dqorganisations._organisation_indicators_complete_split(
        organisation, aggregation_type)
        
    organisation_survey = dqsurveys.getSurvey(organisation_code)
    surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code)

    surveydata, surveydata_workflow = get_survey_data_and_workflow(
        organisation_survey, surveydata)

    published_status_by_id = dict(map(id_tuple, dqsurveys.publishedStatus()))
    publishedformats = dict(map(id_tuple, dqsurveys.publishedFormatsAll()))

    published_status_by_id[None] = {
        'name': 'Unknown',
        'publishedstatus_class': 'label-inverse'
        }

    publishedformats[None] = {
        'name': 'Unknown',
        'format_class': 'label-inverse'
        }

    latest_runtime=1

    years = dict(get_ordinal_values_years())

    return render_template("organisation_index_complete.html",
                           organisation=organisation,
                           results=aggregate_results,
                           runtime=latest_runtime,
                           all_aggregation_types=all_aggregation_types,
                           aggregation_type=aggregation_type,
                           surveydata=surveydata,
                           published_status=published_status_by_id,
                           published_format=publishedformats,
                           surveydata_workflow=surveydata_workflow,
                           admin=usermanagement.check_perms('admin'),
                           loggedinuser=current_user,
                           years=years)
示例#2
0
def _organisation_publication_detail(organisation_code, aggregation_type, is_admin):
    organisation = Organisation.query.filter_by(
        organisation_code=organisation_code).first_or_404()

    packages = dqorganisations.organisationPackages(
        organisation.organisation_code)

    all_aggregation_types = dqaggregationtypes.aggregationTypes()

    aggregate_results = dqorganisations._organisation_detail(organisation, aggregation_type)

    txt = render_template("organisation_detail.html", 
                          organisation=organisation, packages=packages, 
                          results=aggregate_results,
                           all_aggregation_types=all_aggregation_types,
                           aggregation_type=aggregation_type,
                         admin=is_admin,
                         loggedinuser=current_user)
    return txt
def organisation_publication_unauthorised(organisation_code, aggregation_type):
    aggregation_type=integerise(request.args.get('aggregation_type', 2))
    all_aggregation_types = dqaggregationtypes.aggregationTypes()

    organisation = Organisation.query.filter_by(
        organisation_code=organisation_code).first_or_404()

    aggregate_results = dqorganisations._organisation_indicators(
        organisation, aggregation_type)

    packages = dqorganisations.organisationPackages(organisation_code)

    return render_template("organisation_publication_public.html",
                           organisation=organisation,
                           results=aggregate_results,
                           all_aggregation_types=all_aggregation_types,
                           aggregation_type=aggregation_type,
                           packages=packages,
                           admin=usermanagement.check_perms('admin'),
                           loggedinuser=current_user)
def get_aggregation_type(aggregationtype_id):
    def get_data():
        fields = ['name', 'description', 'test_id', 'test_result']
        return dict([ (f, request.form.get(f)) for f in fields ])

    if not request.method == 'POST':
        if aggregationtype_id:
            return dqaggregationtypes.aggregationTypes(
                aggregationtype_id)
        else:
            return {}
    else:
        data = get_data()
        if data['test_id']=="":
            data['test_id'] = None

        if aggregationtype_id:
            return \
                dqaggregationtypes.updateAggregationType(aggregationtype_id, 
                                                         data)
        else:
            return dqaggregationtypes.addAggregationType(data)
def aggregationtypes(aggregationtype_id=None):
    ats=dqaggregationtypes.aggregationTypes()
    return render_template("aggregation_types.html", aggregationtypes=ats,
             admin=usermanagement.check_perms('admin'),
             loggedinuser=current_user)
示例#6
0
def organisation_publication(organisation_code=None, aggregation_type=2):
    check_perms = usermanagement.check_perms(
        'organisation', 'view', {'organisation_code': organisation_code}
        )
    
    if check_perms:
        aggregation_type=integerise(request.args.get('aggregation_type', 2))
        all_aggregation_types = dqaggregationtypes.aggregationTypes()

        organisation = Organisation.query.filter_by(
            organisation_code=organisation_code).first_or_404()

        aggregate_results = dqorganisations._organisation_indicators_split(
            organisation, aggregation_type)
        
        organisation_survey = dqsurveys.getSurvey(organisation_code)
        surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code)
        if organisation_survey:
            if organisation_survey.Workflow.name in ['donorreview', 
                                                     'pwyfreview']:
                surveydata = surveydata["researcher"]
                surveydata_workflow = 'donorreview'
            elif organisation_survey.Workflow.name in ['donorcomments',
                                                       'pwyffinal']:
                surveydata = surveydata["pwyfreview"]
                surveydata_workflow = 'donorcomments'
            elif organisation_survey.Workflow.name == 'finalised':
                surveydata = surveydata["pwyffinal"]
                surveydata_workflow = 'finalised'
            else:
                surveydata = None
                surveydata_workflow=None
        else:
            surveydata = None
            surveydata_workflow=None
        published_status = dqsurveys.publishedStatus()

        published_status_by_id = dict(map(lambda x: (x.id, x), 
                                          published_status))

        publishedformats = dqsurveys.publishedFormatsAll()
        publishedformats = dict(map(lambda pf: (pf.id, pf), publishedformats))

        published_status_by_id[None] = {
            'name': 'Unknown',
            'publishedstatus_class': 'label-inverse'
            }

        publishedformats[None] = {
            'name': 'Unknown',
            'format_class': 'label-inverse'
            }

        latest_runtime=1

        return render_template("organisation_indicators.html", 
                               organisation=organisation,
                               results=aggregate_results, 
                               runtime=latest_runtime,
                               all_aggregation_types=all_aggregation_types,
                               aggregation_type=aggregation_type,
                               surveydata=surveydata,
                               published_status=published_status_by_id,
                               published_format=publishedformats,
                               surveydata_workflow=surveydata_workflow,
                         admin=usermanagement.check_perms('admin'),
                         loggedinuser=current_user)
    else:
        aggregation_type=integerise(request.args.get('aggregation_type', 2))
        all_aggregation_types = dqaggregationtypes.aggregationTypes()

        organisation = Organisation.query.filter_by(
            organisation_code=organisation_code).first_or_404()

        aggregate_results = dqorganisations._organisation_indicators(
            organisation, aggregation_type)

        packages = dqorganisations.organisationPackages(organisation_code)

        return render_template("organisation_publication_public.html", 
                               organisation=organisation,
                               results=aggregate_results, 
                               all_aggregation_types=all_aggregation_types,
                               aggregation_type=aggregation_type,
                               packages=packages,
                         admin=usermanagement.check_perms('admin'),
                         loggedinuser=current_user)
示例#7
0
def packages(package_name=None, runtime_id=None):
    if package_name is None:
        packages = Package.query.filter_by(active=True).order_by(
            Package.package_name).all()
        return render_template("packages.html", 
             packages=packages,
             admin=usermanagement.check_perms('admin'),
             loggedinuser=current_user)

    # Get package data
    package = db.session.query(Package,
                         PackageGroup
                         ).filter(Package.package_name == package_name
                                  ).outerjoin(PackageGroup).first()

    def get_pconditions():
        return {}
        # Publisher conditions have been removed in favour
        #  of organisation conditions. need to consider how to
        #  possibly include this again here.
        """if p is None:
            p = db.session.query(Package).\
                filter(Package.package_name == id).first()
            return {}
        else:
        # Get publisher-specific conditions.
            return PublisherCondition.query.filter_by(
                publisher_id=p[1].id).all()"""

    #pconditions = get_pconditions()
    pconditions = {}

    # Get list of runtimes
    try:
        runtimes = db.session.query(AggregateResult.runtime_id,
                                    Runtime.runtime_datetime
            ).filter(AggregateResult.package_id==package.Package.id
            ).distinct(
            ).join(Runtime
            ).all()
    except Exception:
        return abort(404)

    def get_latest_runtime():
        if runtime_id:
            # If a runtime is specified in the request, get the data
            return (db.session.query(Runtime
                        ).filter(Runtime.id==runtime_id
                        ).first(), False)
        else:
            # Select the highest runtime; then get data for that one
            runtime = db.session.query(Runtime,
                                    func.max(Runtime.id)
                    ).join(AggregateResult
                    ).group_by(Runtime.id
                    ).filter(AggregateResult.package_id==package.Package.id
                    ).first()
            return runtime.Runtime, True

    try:
        latest_runtime, latest = get_latest_runtime()
    except Exception:
        latest_runtime = None
        latest = None

    aggregation_type=integerise(request.args.get('aggregation_type', 2))
    all_aggregation_types = dqaggregationtypes.aggregationTypes()

    if latest_runtime:
        aggregate_results = package_aggregation(package, latest_runtime, aggregation_type)

        aggregate_results = summary.agr_results(aggregate_results, 
                                                   pconditions, 
                                                mode="publisher")
    else:
        aggregate_results = None
        pconditions = None
        flat_results = None
        latest_runtime = None

    organisations = dqpackages.packageOrganisations(package.Package.id)
 
    return render_template("package.html", package=package, runtimes=runtimes, 
                           results=aggregate_results, 
                           latest_runtime=latest_runtime, latest=latest, 
                           pconditions=pconditions,
                           organisations=organisations,
                           all_aggregation_types=all_aggregation_types,
                           aggregation_type=aggregation_type,
                           admin=usermanagement.check_perms('admin'),
                           loggedinuser=current_user)
def organisation_publication_unauthorised(organisation_code, aggregation_type):
    aggregation_type=integerise(request.args.get('aggregation_type', 2))
    all_aggregation_types = dqaggregationtypes.aggregationTypes()

    organisation = Organisation.query.filter_by(
        organisation_code=organisation_code).first_or_404()

    aggregate_results = dqorganisations._organisation_indicators_complete_split(
        organisation, aggregation_type)

    packages = dqorganisations.organisationPackages(organisation_code)

    org_indicators = dqindicators.indicators(app.config["INDICATOR_GROUP"])

    lastyearsdata = iatidq.survey.mapping.get_organisation_results(
        organisation_code, 
        [i.name for i in org_indicators]
        )

    publishedformats = dict(map(name_tuple, dqsurveys.publishedFormatsAll()))

    def annotate(res):
        tmp = dict(res)
        name = res["indicator"]["name"]
        lyd = lastyearsdata[name]
        tmp["lastyearsdata"] = lyd
        tmp["lastyearsdata_iati"] = lyd["iati_manual"] == "iati"
        tmp["lastyearsdata_manual"] = lyd["iati_manual"] == "manual"

        def format_and_title():
            if float(lyd["total_points"]) > 0:
                if tmp["lastyearsdata_iati"]:
                    return ("success", "IATI")
                else:
                    pub_format = publishedformats[lyd["publication_format"]]
                    return (pub_format["format_class"],
                            pub_format["title"])
            elif lyd["publication_status"] == "sometimes":
                return ("default", "Sometimes published")
            else:
                return ("inverse", "Not published")

        ly_format, ly_title = format_and_title()
        tmp["lastyearsdata_format"] = ly_format
        tmp["lastyearsdata_title"] = ly_title

        tmp["uses_iati"] = res.get("results_pct", 0) > 0

        return tmp

    result = {
        "commitment": map(annotate, 
                          util.resort_sqlalchemy_indicator(
                aggregate_results['commitment']).values()),
        "publication_organisation": map(annotate,
                                        util.resort_dict_indicator(
                aggregate_results['publication_organisation']).values()),
        "publication_activity": map(annotate,
                                    util.resort_dict_indicator(
                aggregate_results['publication_activity']).values())
        }

    published_status_by_id = dict(map(id_tuple, dqsurveys.publishedStatus()))

    published_status_by_id[None] = {
        'name': 'Unknown',
        'publishedstatus_class': 'label-inverse'
        }

    publishedformats[None] = {
        'name': 'Unknown',
        'format_class': 'label-inverse'
        }

    latest_runtime=1

    years = dict(get_ordinal_values_years())

    payload = {
        "links": {
            "login": url_for('login', next='/organisations/' 
                             + organisation.organisation_code 
                             + '/publication'),
            "orgpage": url_for('organisations', 
			   organisation_code=organisation.organisation_code)
            },
        "organisation": organisation.as_dict(),
        "result": result
        }
    
    json_data = json.dumps(payload, indent=2)

    return render_template("organisation_index_public_2014.html",
                           organisation=organisation,
                           results=aggregate_results,
                           all_aggregation_types=all_aggregation_types,
                           aggregation_type=aggregation_type,
                           packages=packages,
                           admin=usermanagement.check_perms('admin'),
                           loggedinuser=current_user,
                           lastyearsdata=lastyearsdata,
                           publishedformats=publishedformats,
                           years=years,
                           json_data=json_data,
                           old_publication_status = surveys.get_old_publication_status())