Skip to content
Permalink
Browse files

Merge pull request #557 from PublicMapping/feature/gravelius-html-repr

Represent Gravelius scores as decimal number
  • Loading branch information...
rmartz committed Dec 20, 2018
2 parents b6cb7bf + 348811d commit 05b118d7228d2804a68ee1d406c6575d0b161599
Showing with 17 additions and 3 deletions.
  1. +17 −3 django/publicmapping/redistricting/calculators.py
@@ -173,6 +173,20 @@ def percentage(self, span=False):
c = Context({'percentage': self.result['value'] * 100})
return t.render(c)

def decimal(self, span=False):
"""
Return the calculator's result value as a properly localized
decimal number
@return: A string representing the result as a decimal
"""
if span:
t = Template('<span>{{ value|floatformat:2 }}</span>')
else:
t = Template('{{ value|floatformat:2 }}')
c = Context({'value': self.result['value']})
return t.render(c)

def get_value(self, argument, district=None):
"""
Get the value of an argument if it is a literal or a subject.
@@ -752,12 +766,12 @@ def compute(self, **kwargs):
def html(self):
"""
Generate an HTML representation of the compactness score. This
is represented as a percentage or "n/a"
is represented as a decimal value or "n/a"
@return: A number formatted similar to "1.00%", or "n/a"
@return: A number formatted similar to "1.00", or "n/a"
"""
if self.result is not None and 'value' in self.result:
return '<span>%s</span>' % self.percentage()
return '<span>%s</span>' % self.decimal()
else:
return _("n/a")

0 comments on commit 05b118d

Please sign in to comment.
You can’t perform that action at this time.