Esempio n. 1
0
def indicators_edit(indicatorgroup=None, indicator=None):
    indicatorgroups = dqindicators.indicatorGroups()
    if (request.method == 'POST'):
        data = {
            'name': request.form['name'],
            'description': request.form['description'],
            'indicatorgroup_id': request.form['indicatorgroup_id'],
            'longdescription': request.form['longdescription'],
            'indicator_type': request.form.get("indicator_type"),
            'indicator_category_name': request.form.get("indicator_category_name"),
            'indicator_subcategory_name': request.form.get("indicator_subcategory_name"),
            'indicator_ordinal': request.form.get("indicator_ordinal", None),
            'indicator_noformat': request.form.get("indicator_noformat", None),
            'indicator_order': request.form.get("indicator_order", None),
            'indicator_weight': request.form.get("indicator_weight", None)
        }
        indicator = dqindicators.updateIndicator(indicatorgroup, indicator, data)
        flash('Successfully updated Indicator', 'success')
    else:
        indicator = dqindicators.indicators(indicatorgroup, indicator)
    return render_template("indicator_edit.html", 
                         indicatorgroups=indicatorgroups, 
                         indicator=indicator,
                         admin=usermanagement.check_perms('admin'),
                         loggedinuser=current_user)
Esempio n. 2
0
def organisation_survey_view(organisation_code, workflow, workflow_name, organisationsurvey, allowed_to_edit):
    organisation = Organisation.query.filter_by(
        organisation_code=organisation_code).first_or_404()

    surveydata = dqsurveys.getSurveyData(organisation_code, workflow_name)
    surveydata_allworkflows = dqsurveys.getSurveyDataAllWorkflows(organisation_code)

    indicators = dqindicators.indicators("pwyf2013")
    org_indicators = dqorganisations._organisation_indicators_split(
        organisation, 2)
        
    twentytwelvedata=get_organisation_results(organisation_code, indicators)
    publishedstatuses = dqsurveys.publishedStatus()
    publishedstatuses = dict(map(lambda ps: (ps.id, ps), publishedstatuses))
    publishedformats = dqsurveys.publishedFormat()
    publishedformats = dict(map(lambda pf: (pf.id, pf), publishedformats))

    template_path = "surveys/_survey_"+workflow.WorkflowType.name+".html"
    return render_template(
        template_path, 
        organisation=organisation,
        indicators=indicators,
        org_indicators = org_indicators,
        twentytwelvedata=twentytwelvedata,
        old_publication_status=old_publication_status,
        publishedstatuses=publishedstatuses,
        workflow=workflow,
        surveydata=surveydata_allworkflows,
        organisationsurvey=organisationsurvey,
        allowed_to_edit=allowed_to_edit,
        publishedformats=publishedformats,
        admin=usermanagement.check_perms('admin'),
        loggedinuser=current_user)
Esempio n. 3
0
def indicators(indicatorgroup=None):
    indicators = dqindicators.indicators(indicatorgroup)
    indicatorgroup = dqindicators.indicatorGroups(indicatorgroup)
    return render_template("indicators.html", 
                        indicatorgroup=indicatorgroup, 
                        indicators=indicators,
                        admin=usermanagement.check_perms('admin'),
                        loggedinuser=current_user)
Esempio n. 4
0
def __survey_process(organisation, workflow, request, 
                     organisationsurvey, published_accepted):

    indicators = dqindicators.indicators(app.config["INDICATOR_GROUP"])
    form_indicators = request.form.getlist('indicator')

    workflow_id = workflow.Workflow.id
    currentworkflow_deadline = organisationsurvey.currentworkflow_deadline

    for indicator in indicators:
        data = {
            'organisationsurvey_id': organisationsurvey.id,
            'indicator_id': str(indicator.id),
            'workflow_id': workflow_id,
        }

        if indicator.id not in form_indicators:
            # It's an IATI indicator...
            data['published_status'] = dqsurveys.publishedStatusByName('always').id
            data['published_format'] = dqsurveys.publishedFormatByName('iati').id
        else:
            data['published_status'] = request.form.get(str(indicator.id)+"-published")

            if indicator.indicator_noformat:
                data['published_format'] = dqsurveys.publishedFormatByName('document').id
            else:
                data['published_format'] = request.form.get(str(indicator.id) + "-publishedformat")      

            if indicator.indicator_ordinal:
                data['ordinal_value'] = request.form.get(str(indicator.id) + "-ordinal_value")
            else:
                data['ordinal_value'] = None

        data['published_comment'] = request.form.get(str(indicator.id)+"-comments")
        data['published_source'] = request.form.get(str(indicator.id)+"-source")
        data['published_accepted'] = published_accepted(str(indicator.id))
        
        surveydata = dqsurveys.addSurveyData(data)
    
    if 'submit' in request.form:
        if workflow.Workflow.id == organisationsurvey.currentworkflow_id:
        # save data, change currentworkflow_id to leadsto
            dqsurveys.advanceSurvey(organisationsurvey)
            flash('Successfully submitted survey data', 'success')
        else:
            flash("Your survey data was updated.", 'warning')
    else:
        time_remaining_notice = getTimeRemainingNotice(
            organisationsurvey.currentworkflow_deadline)

        flash('Note: your survey has not yet been submitted. '
              + time_remaining_notice, 'warning')
Esempio n. 5
0
def organisation_survey_view(organisation_code, workflow, 
                             workflow_name, organisationsurvey, 
                             allowed_to_edit):
    organisation = Organisation.query.filter_by(
        organisation_code=organisation_code).first_or_404()

    # the next line may be being called for its side effects
    dqsurveys.getSurveyData(organisation_code, workflow_name)

    surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code)
    try:
        print surveydata['cso']
    except Exception:
        pass

    indicators = dqindicators.indicators(app.config["INDICATOR_GROUP"])
    org_indicators = dqorganisations._organisation_indicators_split(
        organisation, 2)

    twentytwelvedata = iatidq.survey.mapping.get_organisation_results(
        organisation_code, 
        [i[1]["indicator"]["name"] for i in org_indicators["zero"].items()]
        )

    publishedstatuses = dict(map(id_tuple, dqsurveys.publishedStatus()))
    publishedformats  = dict(map(id_tuple, dqsurveys.publishedFormatAll()))
    years = get_ordinal_values_years()
    year_data = dict(years)
    years.pop()
    donorresponses = donorresponse.RESPONSE_IDS

    old_publication_status = get_old_publication_status()

    admin = usermanagement.check_perms('admin')
    loggedinuser = current_user

    org_indicators['commitment'] = util.resort_sqlalchemy_indicator(org_indicators['commitment'])
    org_indicators['zero'] = util.resort_dict_indicator(org_indicators['zero'])

    return render_template(
        "surveys/_survey_%s.html" % workflow.WorkflowType.name,
        **locals())
Esempio n. 6
0
def checkSurveyData(organisation_code):
    # for each currently active stage of the workflow
    # check if there is an indicator at each stage of the workflow
    # if not, then create one

    allindicators = dqindicators.indicators(app.config["INDICATOR_GROUP"])
    allindicators = map(lambda x: x.id, allindicators)
  
    organisation = dqorganisations.organisations(organisation_code)
    org_indicators = dqorganisations._organisation_indicators_split(organisation, 2)["zero"].keys()

    survey = getSurvey(organisation_code).OrganisationSurvey

    survey_data = getSurveyDataAllWorkflows(organisation_code)
    for workflow_name, v in survey_data.items():
        workflow = workflowByName(workflow_name)
        survey_indicators = v.keys()
        for indicator in org_indicators:
            if indicator not in survey_indicators:
                return False
    return True 
Esempio n. 7
0
def indicatortests(indicatorgroup=None, indicator=None):
    alltests = dqindicators.allTests()
    indicator = dqindicators.indicators(indicatorgroup, indicator)
    indicatorgroup = dqindicators.indicatorGroups(indicatorgroup)
    if (request.method == 'POST'):
        for test in request.form.getlist('test'):
            data = {
                    'indicator_id': indicator.id,
                    'test_id': test
            }
            if dqindicators.addIndicatorTest(data):
                flash('Successfully added test to your indicator.', 'success')
            else:
                flash("Couldn't add test to your indicator.", 'error')
    indicatortests = dqindicators.indicatorTests(indicatorgroup.name, indicator.name)
    return render_template("indicatortests.html", 
                         indicatorgroup=indicatorgroup, 
                         indicator=indicator, 
                         indicatortests=indicatortests, 
                         alltests=alltests,
                         admin=usermanagement.check_perms('admin'),
                         loggedinuser=current_user)
Esempio n. 8
0
def repairSurveyData(organisation_code):
    # for each currently active stage of the workflow
    # check if there is an indicator at each stage of the workflow
    # if not, then create one
    changes = False
    changed_indicators = []

    allindicators = dqindicators.indicators(app.config["INDICATOR_GROUP"])
    allindicators = map(lambda x: x.id, allindicators)
  
    organisation = dqorganisations.organisations(organisation_code)
    org_indicators = dqorganisations._organisation_indicators_split(organisation, 2)["zero"]

    survey = getSurvey(organisation_code).OrganisationSurvey

    survey_data = getSurveyDataAllWorkflows(organisation_code)
    for workflow_name, v in survey_data.items():
        workflow = workflowByName(workflow_name)
        survey_indicators = v.keys()
        for indicator, indicatordata in org_indicators.items():
            if indicator not in survey_indicators:
                print "NOT FOUND:", indicator
                data = {
                    'organisationsurvey_id' : survey.id,
                    'workflow_id' : workflow.Workflow.id,
                    'indicator_id' : indicator,
                    'published_status' : None,
                    'published_source' : None,
                    'published_comment' : None,
                    'published_accepted' : None,
                    'published_format' : None,
                    'ordinal_value' : None
                }
                addSurveyData(data)
                changes = True
                changed_indicators.append(indicatordata["indicator_name"])
            else:
                print "FOUND:", indicator
    return {'changes': changes, 'changed_indicators': changed_indicators}
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())