diff --git a/djaopsp/static/js/assess-vue.js b/djaopsp/static/js/assess-vue.js index e1ce1b4a..37113c83 100644 --- a/djaopsp/static/js/assess-vue.js +++ b/djaopsp/static/js/assess-vue.js @@ -24,7 +24,7 @@ Vue.component('campaign-questions-list', { nbRequiredAnswers: this.$sample ? this.$sample.nbRequiredAnswers : 0, nbRequiredQuestions: this.$sample ? this.$sample.nbRequiredQuestions : 0, api_profiles_url: this.$urls.api_profiles, - profilesBySlug: {} + profilesBySlug: {}, } }, methods: { @@ -701,8 +701,15 @@ Vue.component('campaign-questions-list', { return parseInt(this.vsPeersToggle) > 0; }, }, + watch: { + itemsLoaded: function() { + var vm = this; + vm.$parent.items = vm.items; + } + }, mounted: function() { var vm = this; + vm.prefix = vm.$parent.$prefix; $("[id^='toggle-value-summary-']").change(function() { vm.valueSummaryToggle = $(this).prop('checked'); }); @@ -758,9 +765,6 @@ Vue.component('scorecard', { data: function() { return { url: this.$urls.survey_api_sample_answers, - api_assessment_freeze: this.$urls.api_assessment_freeze ? - this.$urls.api_assessment_freeze : this._safeUrl( - this.$urls.api_assessment_sample, '/freeze'), api_assessment_reset: this.$urls.api_assessment_reset ? this.$urls.api_assessment_reset : this._safeUrl( this.$urls.api_assessment_sample, '/reset'), @@ -772,8 +776,7 @@ Vue.component('scorecard', { params: {o: ""}, activeTile: null, summaryPerformance: this.$summary_performance ? this.$summary_performance : [], - freezeAssessmentDisabled: false, - verificationStatus: "" + verificationStatus: "", } }, methods: { @@ -931,29 +934,6 @@ Vue.component('scorecard', { row.default_unit.system === 'imperial' || row.default_unit.system === 'rank'); }, - freezeAssessment: function($event) { - var vm = this; - vm.freezeAssessmentDisabled = true; - vm.reqPost(vm.api_assessment_freeze, {is_frozen: true}, - function success(resp) { - vm.freezeAssessmentDisabled = false; - vm.$nextTick(function() { - var modalDialog = jQuery('#complete-assessment.modal'); - if( modalDialog ) modalDialog.modal('hide'); - if( resp.location ) { - window.location = resp.location; - } - }); - }, - function error(resp) { - vm.freezeAssessmentDisabled = false; - vm.$nextTick(function() { - var modalDialog = jQuery('#complete-assessment.modal'); - if( modalDialog ) modalDialog.modal('hide'); - vm.showErrorMessages(resp); - }); - }); - }, openLink: function(event) { var vm = this; var href = event.target.getAttribute('href'); @@ -983,6 +963,8 @@ Vue.component('scorecard', { vm.items = {results: [], count: 0}; vm.itemsLoaded = false; vm.get(); + vm.$parent.$children[0].get(); + /// Do a .get() whenever all survey responses are deleted. }); }, setActiveElement: function(practice) { @@ -1033,9 +1015,66 @@ Vue.component('scorecard', { var vm = this; vm.verificationStatus = vm.items.verified_status; }, + }, + mounted() { + var vm = this; + vm.prefix = vm.$parent.$prefix; } }); +Vue.component('assess-scorecard', { + data: function() { + return { + showScorecardToggle: 0, + activeSidebarItem: '', + prefixVal: null, + api_assessment_freeze: this.$urls.api_assessment_freeze ? + this.$urls.api_assessment_freeze : this._safeUrl( + this.$urls.api_assessment_sample, '/freeze'), + freezeAssessmentDisabled: false, + items: {} + } + }, + methods: { + setActive(slug) { + var vm = this; + vm.activeSidebarItem = slug; + }, + freezeAssessment: function($event) { + var vm = this; + vm.freezeAssessmentDisabled = true; + vm.reqPost(vm.api_assessment_freeze, {is_frozen: true}, + function success(resp) { + vm.freezeAssessmentDisabled = false; + vm.$nextTick(function() { + var modalDialog = jQuery('#complete-assessment.modal'); + if( modalDialog ) modalDialog.modal('hide'); + if( resp.location ) { + window.location = resp.location; + } + }); + }, + function error(resp) { + vm.freezeAssessmentDisabled = false; + vm.$nextTick(function() { + var modalDialog = jQuery('#complete-assessment.modal'); + if( modalDialog ) modalDialog.modal('hide'); + vm.showErrorMessages(resp); + }); + }); + }, + }, + watch: { + showScorecardToggle: function(val) { + var vm = this; + (vm.showScorecardToggle == 1) ? vm.$prefix = '' : vm.$prefix = vm.prefixVal; + } + }, + mounted() { + var vm = this; + vm.prefixVal = vm.$prefix; + }, +}); /** Component used to display requested scorecards diff --git a/djaopsp/templates/app/assess/_assess_component.html b/djaopsp/templates/app/assess/_assess_component.html new file mode 100644 index 00000000..0a3442f0 --- /dev/null +++ b/djaopsp/templates/app/assess/_assess_component.html @@ -0,0 +1,526 @@ + + +
+ {% block dashboard_nav %} + + {% endblock %} +
+
+
+ +
+ {% block fullviewport %} + {% endblock %} +
+ +
+
+ {% if request %} + {% for message in request|messages %} +
+ {% if 'safe' in message.tags %} +
{{ message|safe }}
+ {% else %} +
{{ message }}
+ {% endif %} + +
+ {% endfor %} + {% endif %} + {% if form %} + {% for message in form|messages %} +
+
{{ message }}
+ +
+ {% endfor %} + {% endif %} + {# #} +
+
+
+
+
+
+
+

+ {% trans %}Click to expand each icon tile.{% endtrans %}
+ {% trans %}If need be{% endtrans %}, + {% trans %}download{% endtrans %} + {% trans %}the questionnaire or{% endtrans %} + + {% trans %}invite a contributor{% endtrans %}. +

+
+
+
+
+ +
+
+ {# nav item #} + + {# /nav item #} + + {# expanded tabs go here #} +
+
+ + + + + + + + + + + + + + + + + + + + {% include "app/assess/_assess_row.html" %} + +
+ +
+ + Implemented as standard practice? +
+
+
+ +
+
+
+
+ +
+
+
+      + required answer + +
+
+
+
+
+
+ Practices + {% include "app/assess/_vs_peers_toggle.html" %} +
+
+
+
+
[[choice.text]] +
+
+
+ {% if not sample.is_frozen %} +
+
+
+ +
+
+
{# /.row (action buttons) #} +
+ {% endif %} +
+ {# /!showVsPeers #} +
+ + + + + + + + + {% include "app/assess/_assess_results_row.html" %} + + +
+
+
+ Practices + {% include "app/assess/_vs_peers_toggle.html" %} +
+
+
+ +
+
[[choice.text]]
+
+
+
+ {# /showVsPeers #} +
+ {# /expanded tab #} +
+ {# /v-for=icon #} + + {% block icons_actions %} + {% endblock %} + + + + {# /#syncBaselineAt #} + + {# /#syncEndsAt #} + {% include "app/_reset_assessment.html" %} + {% include "app/_complete_assessment.html" %} + {% block panel_footer %} + + {% endblock %} +
+
+
+
+ +
+
\ No newline at end of file diff --git a/djaopsp/templates/app/assess_scorecard/_assess_scorecard_toggle.html b/djaopsp/templates/app/assess_scorecard/_assess_scorecard_toggle.html new file mode 100644 index 00000000..d81d9bce --- /dev/null +++ b/djaopsp/templates/app/assess_scorecard/_assess_scorecard_toggle.html @@ -0,0 +1,10 @@ +
+
+ +
+
+ {% trans %}Assess{% endtrans %} + {% trans %}Scorecard{% endtrans %} +
+
\ No newline at end of file diff --git a/djaopsp/templates/app/assess_scorecard/_new_assess_row.html b/djaopsp/templates/app/assess_scorecard/_new_assess_row.html new file mode 100644 index 00000000..9b56dd9c --- /dev/null +++ b/djaopsp/templates/app/assess_scorecard/_new_assess_row.html @@ -0,0 +1,616 @@ +
+
+
+
+ + [[practice.title]] + + + [[practice.title]] + + + [[practice.title]] + +
+
+
+ + + +
+
+ +{# column headers #} +{# when enum choices are not shown in table header #} +
+
+{# when enum choices are shown in table header #} +
+ +
+ +
+
+ +
+
+ +{# Presents questions based on its ui_hint and default unit #} +
+ +
+ +{# The unit is fixed. question.ui_hint === 'revenue' #} +
+
+ + +
+
+ + +
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+
+ + +
+
+ +{# Energy consumed #} +{# - The unit is variable (out of an "energy units" drop down list) #} +{# - question.ui_hint === 'energy' #} +
+ +
+
+ +
+
+
+ + +
+
+ + enter data in tracking tool » +
+
+{# end of energy #} + + +{# water #} +{# - The unit is variable (out of an "water units" drop down list) #} +{# - question.ui_hint === 'water' #} +
+ +
+
+ +
+
+
+ + +
+
+ + enter data in tracking tool » +
+
+{# end of water #} + +{# waste #} +{# - The unit is variable (out of an "waste units" drop down list) #} +{# - question.ui_hint === 'waste' #} +
+ +
+
+ +
+
+
+ + +
+
+ + enter data in tracking tool » +
+
+{# end of waste #} + +{# GHG Emissions #} +
+ +
+
+ +
+
+
+ + +
+
+ + enter data in tracking tool » +
+
+{# end of scope ghg emissions #} + + +{# when question.unit is 'verifiability' #} +
+
+ + + + + + + + +
+
+ +
+
+ +{# when question.unit.system is 'enum' and UI hint computes to 'select' #} +
+ +
+ +{# when question.unit.system is 'enum' and UI hint computes to 'radio' #} +
+
{# form-check #} +
+ +
+ +
+
+ +{# Targets #} +
+
+ +
+
+{# end target #} +
+ +{# optional comments #} +
+
+
+
+ {# comments #} +
+
{% trans %}Notes, Public URL Links, and/or Uploaded Documents{% endtrans %}
+

+ You selected "Not Applicable", please explain. +

+ +
+
+ +
+
+
+ + [[collectedByPrintableName]] +
+ [[humanizeDate(collectedAtTime)]]
+ ([[humanizeTimeDelta(collectedAtTime)]]) +
+
+

+

+
+
+
+
+ {% trans %}No notes were added.{% endtrans %} +
+
+
+
+ + +
+
+ +
+
+
+
+
+ + +
+
+
+
+ +
+
+
+
+
+
+
+
+
diff --git a/djaopsp/templates/app/assess_scorecard/base.html b/djaopsp/templates/app/assess_scorecard/base.html new file mode 100644 index 00000000..3a571115 --- /dev/null +++ b/djaopsp/templates/app/assess_scorecard/base.html @@ -0,0 +1,20 @@ +{% extends "app/base.html" %} + +{% block app_content %} +{% block scorecard_content %} +{% endblock %} +{% endblock %} + +{% block app_bodyscripts %} +{% if ASSETS_DEBUG %} + + + + + + +{% else %} + +{% endif %} +{% block assess_scorecard_scripts %}{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/djaopsp/templates/app/assess_scorecard/index.html b/djaopsp/templates/app/assess_scorecard/index.html new file mode 100644 index 00000000..aa2d0b38 --- /dev/null +++ b/djaopsp/templates/app/assess_scorecard/index.html @@ -0,0 +1,18 @@ +{% extends "app/assess_scorecard/base.html" %} + +{% block supercontent %} +
+ +
+ {% block app_content %} +
+ {% include 'app/assess/_assess_component.html' %} +
+
+ {% include 'app/scorecard/_scorecard_component.html' %} +
+ {% endblock %} +
+
+
+{% endblock %} diff --git a/djaopsp/templates/app/scorecard/_scorecard_component.html b/djaopsp/templates/app/scorecard/_scorecard_component.html new file mode 100644 index 00000000..cd1414f7 --- /dev/null +++ b/djaopsp/templates/app/scorecard/_scorecard_component.html @@ -0,0 +1,933 @@ + + +
+ {% block dashboard_nav %} + + {% endblock %} +
+
+
+ +
+ {% block fullviewport %} + {% endblock %} +
+ +
+
+ {% if request %} + {% for message in request|messages %} +
+ {% if 'safe' in message.tags %} +
{{ message|safe }}
+ {% else %} +
{{ message }}
+ {% endif %} + +
+ {% endfor %} + {% endif %} + {% if form %} + {% for message in form|messages %} +
+
{{ message }}
+ +
+ {% endfor %} + {% endif %} + {# #} +
+
+
+
+
+
+ {% if not sample.is_frozen %} +
+
+ {% trans %}This report is a work in + progress.{% endtrans %} + {% trans %}Once you are ready, please click the "Complete" + button at the + bottom of the page to create a frozen report. The report + will then + appear under "Historical assessments" and can be shared + with + customers and stakeholders.{% endtrans %} +
+
+ {% endif %} +
+
+
+
+ +
+
+

{{ sample.account.printable_name }}

+

{{ sample.campaign.title }}

+
{{ sample.created_at|date }}
+
+
+
+
+
+ {% for highlight in highlights %} +
+
+ +
+ {{ highlight.text }}
+
+
+ {% endfor %} +
+
+
+
+ Contact Information +
    +
  • {% if sample.account.email %} + {{ sample.account.email }}{% else %} +  {% endif %}
  • +
  • {% if sample.account.phone %} + {{ sample.account.phone }}{% else %} +  {% endif %}
  • +
+
+
+
+
+
+ {% if summary_performance %} +
+ +
+ {% endif %} +
+
+
+ {# /.col-sm-8 #} +
+
+
+
+
+ {% include "app/_score_arcs.html" %} +
+
+ source: {{ request|site_url }} +
+
+
+
+ {# /.row #} +
+
+ {% if verification_enabled %} +
+ + +
+ {% endif %} +
+
+ {# /.row #} +
+ {# /#summary #} +
+ {% if not sample.is_frozen %} + {% if urls.assess_mandatory_segment and not is_mandatory_segment_present %} +
+
+

+ {% if sample.campaign.description %} + {{ sample.campaign.description }} + {% endif %} +

+

+ {% trans %}Click Assess in the horizontal progress bar + at the top of + the page to get started!{% endtrans %} +

+
+ {% endif %}{# /no answer on mandatory segment #} + {% endif %}{# /not sample.is_frozen #} +
+ +
+
+
+
+
+ + {# segment title #} +
+
+
+ +
+ [[practice.title]] +
+ {% if not sample.is_frozen %} + + {% endif %} + + {# scorecard for segment #} +
+
+
+ {# XXX copy/pasted from _tile_chart.html? #} +
+
+ +
+
+
+
{% trans %}There is not + enough data + available to benchmark with + peers.{% endtrans %}
+
+ +
+
+ {# /.col-sm-8 #} +
+
+ [[asPercent(practice.normalized_score)]] +
+
+ {# /.col-sm-4 #} +
+ {# /scorecard for segment #} + + {# summary of tile sections #} +
+
+
+
+
+ +
+ [[subheading.title]] + ([[asPercent(subheading.normalized_score)]]) + +
+
+
+ +
+
+
+
There is not enough + data available + to benchmark with peers. +
+
+ +
+
+
+

+ {% trans %}Benchmarking is based on responses + from{% endtrans %} + ?[[getNbRespondents(practice)]] + {% trans %}companies responding on practices in the + industry + segment.{% endtrans %} +

+
+ {# /practice.indent == 0 #} + +
+ {# tile title #} +
+
+ +
+ [[practice.title]] +
+ + {# summary when no tile sections #} +
+
+
+ {# XXX copy/pasted from _tile_chart.html? #} +
+
+ +
+
+
+
{% trans %}There is not + enough data + available to benchmark with + peers.{% endtrans %}
+
+ +
+
+ {# /.col-sm-8 #} +
+
+ [[asPercent(practice.normalized_score)]] +
+
+ {# /.col-sm-4 #} +
+
+ {# /practice.indent > 0 #} + +
+ {# /.isChartHeading - i.e. heading with charts and score #} + + {# Beginning of details section #} +
+
+
+
+
+
+ +
+ [[practice.title]] +
+
+
+ {# /.row #} + + {# different layout for differnt type of questions. #} +
+ + + + + + + + + + +
+ [[year]] +
[[total.title]] + [[getColValue(total, year)]] +
+ [[getCaptionTitle(practice)]] +
+
+ {# /.isDataMetricsHeader #} +
+ {# /!isChartHeading(practice) && !isPractice(practice) - i.e. regular heading #} + +
+
+
+
+ [[practice.title]] + +
+
+
+ {% trans %}Implementation rate{% endtrans %} +
+ [[practice.nb_respondents]] {% trans %} + respondents{% endtrans %} +
+
+ [[asPercent(getRate(practice))]] +
+
+
+
+ {% trans %}Opportunity score{% endtrans %} +
+ [[getOpportunity(practice)]] +
+
+ {# XXX Temporarily disabled until we handle special 2-values case #} + {#
#} + {#
#} + {#
#} + {#
#} + {#
#} + {# [[asPercent(value[1])]] #} + {#
#} + {# [[value[0] ]] #} + {#
#} + {#
#} + {#
#} + {#
#} +
+ {# /practice-related information #} +
+
+
+
+
+ [[getPrimaryAnswer(practice).measured + ? + getMeasured(getPrimaryAnswer(practice)) + : + "-"]] +
+
+
+
+ ({% trans %}planned{% endtrans %}: + [[getPrimaryPlanned(practice).measured]]) +
+
+
+
+
+
+ {# /.row assessment answer #} + {% include "app/scorecard/_secondary_answers.html" %} +
+ {# /isEnumUnit(practice) #} + +
+
+
+
+ [[practice.title]] + +
+
+
+
+

+

+
+
+
+ {# /.row assessment answer #} + {% include "app/scorecard/_secondary_answers.html" %} +
+ {# /isFreetextUnit(practice) #} + +
+
+
+
+ [[practice.title]] + +
+
+
+
+ ‐ +
+
+ 0-10 employees + 11-50 employees + 51-200 employees + 201-500 employees + 501-1,000 employees + 1,001-5,000 employees + 5,001-10,000 employees + 10,001+ employees +
+
+
+ {# /.row #} +
+ {# /isEmployeeCountUIHint(practice) #} + +
+
+ +
+
+ + [[getPrimaryAnswer(practice).measured]] + + + ‐ + +
+
+
+ {# /.row #} + {% include "app/scorecard/_secondary_answers.html" %} +
+ {# /isNumberUnit(practice) #} + +
+
+
+
+ [[practice.title]] + +
+
+
+
+ + [[getPrimaryAnswer(practice).measured]] + + + ‐ + +
+
+
+ {# /.row #} + {% include "app/scorecard/_secondary_answers.html" %} +
+ {# /isDatetimeUnit(practice) #} + {# End of details section #} + +
+ {# /v-for=getEntries() #} +
+ {# /v-if=itemsLoaded && items.results.length > 0 #} + + {% if not sample.is_frozen %} +
+ {% if segments_candidates and (not urls.assess_mandatory_segment or is_mandatory_segment_present) %} +
+ + {% endif %} +
{# /#add-segments-actions #} + {% endif %} +
+ {# /# details #} + {#
#} + {#
#} + {##} + {#
#} + {#
#} + {# #} + {#   {% trans %}#} + {# Download#} + {# (xlsx){% endtrans %}#} + {# #} + {# #} + {#
#} + {# {% if sample.is_frozen %}#} + {# actions only available when a scorecard is frozen #} + {# {% if urls.share %}#} + {# #} + {# XXX disabled until functionality is implemented #} + {# #} + {# {% endif %}#} + {# {% else %}#} + {# actions only available when a scorecard is active #} + {# #} + {#
#} + {# {% if not urls.assess_mandatory_segment or is_mandatory_segment_present %}#} + {#
#} + {# #} + {# #} + {#
#} + {#

#} + {# {% trans %}You can only record a response once all#} + {# sections have#} + {# been answered. Required questions with missing#} + {# answers are#} + {# highlighted with a red vertical bar to the#} + {# right.{% endtrans %}#} + {#

#} + {# {% endif %}#} + {#
#} + {# {% endif %}#} + {#
#} + {#
#} + {# /#next-actions #} +
+ + {% include "app/_reset_assessment.html" %} + {% include "app/_complete_assessment.html" %} +
+
+
+
+ +
+
\ No newline at end of file diff --git a/djaopsp/templates/base.html b/djaopsp/templates/base.html index 93ea7c95..89b094a0 100644 --- a/djaopsp/templates/base.html +++ b/djaopsp/templates/base.html @@ -35,6 +35,7 @@
+ {% block supercontent %}
{% block dashboard_nav %}
+ {% endblock %}
diff --git a/djaopsp/urls/views/reports.py b/djaopsp/urls/views/reports.py index 0ad3c1f5..0b403c07 100644 --- a/djaopsp/urls/views/reports.py +++ b/djaopsp/urls/views/reports.py @@ -12,6 +12,7 @@ from ...views.downloads import ImproveContentPDFView from ...views.scorecard import (ScorecardIndexView, ScorecardHistoryView, ScorecardRedirectView, DataValuesView) +from ...views.assess_scorecard import AssessScorecardView from ...views.share import ShareView, ShareRedirectView @@ -33,6 +34,9 @@ AssessPracticesView.as_view(), name='assess_practices'), path('assess//', AssessRedirectView.as_view(), name='assess_redirect'), + path('assess2///', + AssessScorecardView.as_view(), name='assess_scorecard'), + # Target and improvement plan path('improve//print/', ImproveContentPDFView.as_view(), name='improve_print'), diff --git a/djaopsp/views/assess_scorecard.py b/djaopsp/views/assess_scorecard.py new file mode 100644 index 00000000..84e9f058 --- /dev/null +++ b/djaopsp/views/assess_scorecard.py @@ -0,0 +1,138 @@ +import logging + +from deployutils.apps.django.templatetags.deployutils_prefixtags import ( + site_url) +from deployutils.helpers import update_context_urls +from django.db.models import Q +from django.views.generic.base import TemplateView +from survey.models import Answer +from survey.settings import DB_PATH_SEP +from survey.utils import get_question_model + +from ..compat import reverse +from ..mixins import SectionReportMixin +from ..utils import get_highlights, get_summary_performance + +LOGGER = logging.getLogger(__name__) + +from survey.models import Choice + + +class AssessScorecardView(SectionReportMixin, TemplateView): + """ + Profile scorecard page + """ + template_name = 'app/assess_scorecard/index.html' + URL_PATH_SEP = '/' + breadcrumb_url = 'assess_practices' + + def get_reverse_kwargs(self): + """ + List of kwargs taken from the url that needs to be passed through + to ``reverse``. + """ + return [self.account_url_kwarg, self.sample_url_kwarg, + self.path_url_kwarg] + + @property + def campaign_mandatory_segments(self): + # pylint:disable=attribute-defined-outside-init + if not hasattr(self, '_campaign_mandatory_segments'): + self._campaign_mandatory_segments = [] + campaign_slug = self.sample.campaign.slug + campaign_prefix = "%s%s%s" % ( + DB_PATH_SEP, campaign_slug, DB_PATH_SEP) + if get_question_model().objects.filter( + path__startswith=campaign_prefix).exists(): + self._campaign_mandatory_segments = [campaign_prefix] + return self._campaign_mandatory_segments + + @property + def is_mandatory_segment_present(self): + # pylint:disable=attribute-defined-outside-init + if not hasattr(self, '_is_mandatory_segment_present'): + filter_args = None + for seg_path in self.campaign_mandatory_segments: + if filter_args: + filter_args |= Q(question__path__startswith=seg_path) + else: + filter_args = Q(question__path__startswith=seg_path) + self._is_mandatory_segment_present = False + if filter_args: + queryset = Answer.objects.filter( + filter_args, sample=self.sample) + self._is_mandatory_segment_present = queryset.exists() + return self._is_mandatory_segment_present + + def get_template_names(self): + candidates = ['app/scorecard/%s.html' % self.sample.campaign] + candidates += super(AssessScorecardView, self).get_template_names() + return candidates + + def get_context_data(self, **kwargs): + context = super(AssessScorecardView, self).get_context_data(**kwargs) + context.update({ + 'prefix': self.full_path, + 'nb_answers': self.nb_answers, + 'nb_questions': self.nb_questions, + 'units': {}, + 'verification_enabled': self.account in self.verifier_accounts, + 'highlights': get_highlights(self.sample), + 'is_mandatory_segment_present': self.is_mandatory_segment_present, + 'summary_performance': get_summary_performance( + self.improvement_sample) + }) + + for unit_slug in ('verifiability', 'supporting-document', + 'completeness'): + context['units'].update({ + unit_slug.replace('-', '_'): Choice.objects.filter( + unit__slug=unit_slug).order_by('rank')}) + if not self.sample.is_frozen: + context.update({ + 'nb_required_answers': self.nb_required_answers, + 'nb_required_questions': self.nb_required_questions, + }) + if not self.segments_available: + update_context_urls(context, { + 'complete': "#" # When there are no answers yet, we want + # to show the assess step on the scorecard. + }) + if self.campaign_mandatory_segments: + update_context_urls(context, { + 'assess_mandatory_segment': reverse('assess_practices', + args=(self.account, self.sample, self.sample.campaign)), + }) + update_context_urls(context, { + 'pages_index': reverse('pages_index'), + 'scorecard_download': reverse('assess_download', + args=(self.account, self.sample)), + 'survey_api_sample_answers': reverse('api_sample_content', + args=(self.account, self.sample, '-'))[:-2], + 'api_account_benchmark': reverse( + 'survey_api_sample_benchmarks_index', + args=(self.account, self.sample)), + 'assess_base': reverse('assess_practices', + args=(self.sample.account, self.sample, '-'))[:-2], + 'api_assessment_freeze': reverse('survey_api_sample_freeze_index', + args=(self.sample.account, self.sample)), + 'api_assessment_reset': reverse('survey_api_sample_reset_index', + args=(self.sample.account, self.sample)), + 'api_assessment_notes': reverse('api_verifier_notes_index', + args=(self.sample.account, self.sample)), + 'api_asset_upload_complete': self.request.build_absolute_uri( + reverse('pages_api_upload_asset', args=(self.sample.account,))), + 'track_metrics_index': reverse( + 'track_metrics_index', args=(self.account,)), + 'api_profiles': site_url("/api/accounts/users"), + 'api_content': reverse('api_sample_content', + args=(self.account, self.sample, + self.full_path.lstrip(self.URL_PATH_SEP))), + 'api_assessment_sample': reverse('survey_api_sample', + args=(self.account, self.sample)), + 'api_aggregate_metric_base': reverse( + 'survey_api_aggregate_metric_base', args=(self.account,)), + 'api_asset_upload_start': self.request.build_absolute_uri( + reverse('pages_api_upload_asset', args=(self.account,))), + }) + return context