def organisation_edit(organisation_code=None): packages = dqpackages.packages() packagegroups = dqpackages.packageGroups() organisation = dqorganisations.organisations(organisation_code) if request.method == 'POST': if 'addpackages' in request.form: add_packages(organisation) elif 'addpackagegroup' in request.form: add_packagegroup(organisation) elif 'updateorganisation' in request.form: update_organisation(organisation_code) organisationpackages = dqorganisations.organisationPackages( organisation.organisation_code) return render_template( "organisation_edit.html", organisation=organisation, packages=packages, packagegroups=packagegroups, donorresponses=donorresponse.RESPONSE_TYPES, organisationpackages=organisationpackages, admin=usermanagement.check_perms('admin'), loggedinuser=current_user)
def organisations_index(organisation_code=None): aggregation_type=integerise(request.args.get('aggregation_type', 2)) template_args = {} org_packages = dqorganisations.organisationPackages(organisation_code) organisation = dqorganisations.organisations(organisation_code) packagegroups = dqorganisations.organisationPackageGroups(organisation_code) irs = [ir for ir in get_info_results(org_packages, organisation)] coverage = get_coverage(organisation, irs) organisation_survey = dqsurveys.getSurvey(organisation_code) surveydata = dqsurveys.getSurveyDataAllWorkflows(organisation_code) surveydata, _ = dqsurveys.get_survey_data_and_workflow( organisation_survey, surveydata) summary_data = get_summary_data(organisation, aggregation_type) allowed_to_view_survey = usermanagement.check_perms( "survey", "view") allowed_to_edit_survey_researcher = usermanagement.check_perms( "survey_researcher", "edit", {"organisation_code": organisation_code}) show_researcher_button = ( allowed_to_edit_survey_researcher and ( (organisation_survey and organisation_survey.Workflow.name == 'researcher') or (not organisation_survey) ) ) template_args = dict(organisation=organisation, summary_data=summary_data, packagegroups=packagegroups, coverage=coverage, surveydata=surveydata, admin=usermanagement.check_perms('admin'), loggedinuser=current_user, allowed_to_view_survey=allowed_to_view_survey, show_researcher_button=show_researcher_button) return render_template("organisation_index.html", **template_args)
def organisations_coverage(): organisations = dqorganisations.organisations() coverage_data = {} for organisation in organisations: org_packages = dqorganisations.organisationPackages(organisation.organisation_code) irs = [ir for ir in get_info_results(org_packages, organisation)] coverage_data[organisation.id] = (get_coverage(organisation, irs)) return render_template("organisations_coverage.html", organisations=organisations, coverage_data=coverage_data, admin=usermanagement.check_perms('admin'), loggedinuser=current_user )
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 organisations_index(organisation_code=None): info_results = { } aggregation_type=integerise(request.args.get('aggregation_type', 2)) template_args = {} org_packages = dqorganisations.organisationPackages(organisation_code) def get_info_results(): for _, p in org_packages: package_id = p.package_id from sqlalchemy import func runtime = db.session.query( func.max(InfoResult.runtime_id)).filter( InfoResult.package_id == package_id ).first() import iatidq.inforesult runtime, = runtime results = iatidq.inforesult.info_results(package_id, runtime, organisation.id) if "coverage" in results: try: yield int(results["coverage_current"]) except TypeError: yield 0 organisation = dqorganisations.organisations(organisation_code) packagegroups = dqorganisations.organisationPackageGroups(organisation_code) info_results["coverage_current"] = \ reduce(operator.add, [ir for ir in get_info_results()], 0) # coverage_total = organisation.organisation_total_spend # FIXME: use organisation_total_spend # when data is imported to db coverage_total = (organisation.organisation_total_spend)*1000000 coverage_found = info_results["coverage_current"] if (coverage_total and coverage_found): coverage_pct = int((float(coverage_found)/float(coverage_total))*100) coverage = { 'total': coverage_total, 'found': coverage_found, 'pct': coverage_pct } else: coverage = { 'total': None, 'found': None, 'pct': None } 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 else: surveydata = None try: summary_data = _organisation_indicators_summary(organisation, aggregation_type) except Exception, e: summary_data = None
def organisation_edit(organisation_code=None): packages = dqpackages.packages() packagegroups = dqpackages.packageGroups() organisation = dqorganisations.organisations(organisation_code) if request.method == 'POST': if 'addpackages' in request.form: condition = request.form['condition'] def add_org_pkg(package): data = { 'organisation_id': organisation.id, 'package_id': package, 'condition': condition } if dqorganisations.addOrganisationPackage(data): flash('Successfully added package to your organisation.', 'success') else: flash("Couldn't add package to your organisation.", 'error') packages = request.form.getlist('package') [ add_org_pkg(package) for package in packages ] elif 'addpackagegroup' in request.form: condition = request.form['condition'] data = { 'organisation_id': organisation.id, 'packagegroup_id': request.form['packagegroup'], 'condition': condition } add_packagegroups = dqorganisations.addOrganisationPackageFromPackageGroup(data) if 'applyfuture' in request.form: if dqorganisations.addOrganisationPackageGroup(data): flash('All future packages in this package group will be added to this organisation', 'success') else: flash('Could not ensure that all packages in this package group will be added to this organisation', 'error') if add_packagegroups: flash('Successfully added ' + str(add_packagegroups) + ' packages to your organisation.', 'success') else: flash("No packages were added to your organisation. This could be because you've already added all existing ones.", 'error') elif 'updateorganisation' in request.form: data = { 'organisation_code': request.form['organisation_code'], 'organisation_name': request.form['organisation_name'] } organisation = dqorganisations.updateOrganisation( organisation_code, data) organisationpackages = dqorganisations.organisationPackages( organisation.organisation_code) return render_template( "organisation_edit.html", organisation=organisation, packages=packages, packagegroups=packagegroups, organisationpackages=organisationpackages, admin=usermanagement.check_perms('admin'), loggedinuser=current_user)
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)
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())