def long_display_name(self): if self.is_snapshot: return format_html( "Snapshot of {0} > {1}", self.get_organization().title, self.copied_from.display_name() ) if self.organization: return format_html("{0} > {1}", self.get_organization().title, self.hr_name or self.name) else: return self.name
def render(f): title = { "public": _("Public Facility"), "private": _("Private Facility"), "transport": _("Transport") }[f.fields["type"]] return format_html(u"%s: %s<br /># %s" % (title, f.fields.get("name", ""), f.fields.get("number", "")))
def piecewise_rows(self): rows = [] d_text = lambda slug: format_html('<i class="icon icon-spinner status-{0}"></i>', slug) def _create_stat_cell(stat_type, slug): stat_cell = self.table_cell(None, d_text(slug)) stat_cell.update( css_class="%s %s" % (stat_type, slug), ) return stat_cell for section in self.indicators: for indicator in section: self.statistics_rows[0].append(_create_stat_cell('average', indicator.slug)) self.statistics_rows[1].append(_create_stat_cell('median', indicator.slug)) self.statistics_rows[2].append(_create_stat_cell('std', indicator.slug)) self.statistics_rows[3].append(_create_stat_cell('total', indicator.slug)) for u, user in enumerate(self.users): row_data = [user.username_in_report] for section in self.indicators: for indicator in section: table_cell = self.table_cell(None, d_text(indicator.slug)) table_cell.update( css_class=indicator.slug ) row_data.append(table_cell) rows.append({ 'data': row_data, 'css_id': user.user_id, }) return rows
def _link(g, text): params = copy(self.request_params) params["group"] = g.get_id return format_html(u'<a href="{details}">{text}</a>', text=text, details=url_and_params(self.next_report_class.get_url(domain=self.domain, render_as=self.render_next), params))
def default_nav_link(nav_report, i, report_cls): url = report_cls.get_url(nav_report.domain, render_as=nav_report.render_next) if getattr(nav_report, 'preserve_url_params', False): url = url_and_params(url, nav_report.request_params) return format_html(u'<a href="{details}">{val}</a>', val=list_prompt(i, report_cls.name), details=url)
def _referral_link(i): params = copy(self.request_params) params["next_report"] = ReferralListReport.slug return format_html(u'<a href="{next}">{val}</a>', val=list_prompt(i, _(ReferralListReport.name)), next=url_and_params( SubCenterSelectionReport.get_url(self.domain, render_as=self.render_next), params ))
def _indicator_nav_link(i, indicator_set): params = copy(self.request_params) params["indicators"] = indicator_set.slug params["next_report"] = IndicatorNav.slug return format_html(u'<a href="{next}">{val}</a>', val=list_prompt(i, indicator_set.name), next=url_and_params( SubCenterSelectionReport.get_url(self.domain, render_as=self.render_next), params ))
def _nav_link(indicator): params = copy(self.request_params) params["indicators"] = self.indicator_set.slug params["indicator"] = indicator.slug return format_html(u'<a href="{next}">{val}</a>', val=self.count(indicator), next=url_and_params( IndicatorClientList.get_url(domain=self.domain, render_as=self.render_next), params ))
def get_chart(self, indicator): # this is a serious hack for now pie_class = 'sparkpie' num, denom = self.get_indicator_data(indicator) chart_template = ( '<span data-numerator="{num}" ' 'data-denominator="{denom}" class="{pie_class}"></span>' ) return format_html(chart_template, num=num, denom=denom - num, pie_class=pie_class)
def _fmt_result(item_config, value): params = copy(self.request_params) params['category'] = item_config['slug'] params['date'] = self.get_date().strftime(DATE_FORMAT) return format_html(u'<a href="{next}">{val}</a>', val=value, next=url_and_params( VaccinationClientList.get_url(self.domain, render_as=self.render_next), params ))
def _nav_link(indicator): params = copy(self.request_params) params['indicator'] = indicator.slug del params['next_report'] return format_html(u'{chart}<a href="{next}">{val}</a>', val=self.get_indicator_value(indicator), chart=self.get_chart(indicator), next=url_and_params( IndicatorClientList.get_url(self.domain, render_as=self.render_next), params ))
def _nav_link(indicator): params = copy(self.request_params) params["indicators"] = self.set_slug params['indicator'] = indicator.slug return format_html(u'{chart}<a href="{next}">{val}</a>', val=self.data_provider.get_indicator_value(indicator), chart=self.data_provider.get_chart(indicator), next=url_and_params( MyPerformanceList.get_url(domain=self.domain, render_as=self.render_next), params, ) )
def get_chart(self, indicator): # this is a serious hack for now pie_class = 'sparkpie' split = self.get_indicator_value(indicator).split("/") chart_template = ( '<span data-numerator="{num}" ' 'data-denominator="{denom}" class="{pie_class}"></span>' ) if len(split) == 2: return format_html(chart_template, num=split[0], denom=int(split[1]) - int(split[0]), pie_class=pie_class) return '' # no chart
def download_commcare_users(request, domain): response = HttpResponse(mimetype=Format.from_format("xlsx").mimetype) response["Content-Disposition"] = 'attachment; filename="%s_users.xlsx"' % domain try: dump_users_and_groups(response, domain) except GroupNameError as e: group_urls = [reverse("group_members", args=[domain, group.get_id]) for group in e.blank_groups] def make_link(url, i): return format_html('<a href="{}" target="_blank">{}</a>', url, _("Blank Group %s") % i) group_links = [make_link(url, i + 1) for i, url in enumerate(group_urls)] msg = format_html( _("The following groups have no name. " "Please name them before continuing: {}"), mark_safe(", ".join(group_links)), ) messages.error(request, msg, extra_tags="html") return HttpResponseRedirect(reverse("upload_commcare_users", args=[domain])) return response
def download_commcare_users(request, domain): response = HttpResponse(mimetype=Format.from_format('xlsx').mimetype) response['Content-Disposition'] = 'attachment; filename=%s_users.xlsx' % domain try: dump_users_and_groups(response, domain) except GroupNameError as e: group_urls = [ reverse('group_members', args=[domain, group.get_id]) for group in e.blank_groups ] def make_link(url, i): return format_html( '<a href="{}">{}</a>', url, _('Blank Group %s') % i ) group_links = [ make_link(url, i + 1) for i, url in enumerate(group_urls) ] msg = format_html( _( 'The following groups have no name. ' 'Please name them before continuing: {}' ), mark_safe(', '.join(group_links)) ) messages.error(request, msg, extra_tags='html') return HttpResponseRedirect( reverse('upload_commcare_users', args=[domain]) ) return response
def make_link(url, i): return format_html( '<a href="{}" target="_blank">{}</a>', url, _('Blank Group %s') % i )
def _awcc_link(g): params["group"] = g.get_id return format_html(u'<a href="{details}">{awcc}</a>', awcc=get_awcc(g), details=url_and_params(url, params))
def long_display_name(self): if self.is_snapshot: return format_html("Snapshot of {}", self.copied_from.display_name()) return self.hr_name or self.name
def make_link(url, i): return format_html('<a href="{}" target="_blank">{}</a>', url, _('Blank Group %s') % i)