Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more whitespace'

  • Loading branch information...
commit e1050c2031e357fe6bc970569fb962bef7d7a0c0 2 parents d65af79 + 8841dcf
@alex authored
View
2  README.rst
@@ -18,4 +18,4 @@ Using histograms in other pages
You can use the built-in ``histogram_for`` template tag::
{% load histograms %}
- {% histogram_for 'appname.Model' 'histogram_field' %}
+ {% histogram_for appname.Model 'histogram_field' 1 1 %}
View
2  django_histograms/templates/histograms/report.html
@@ -20,7 +20,7 @@ <h2 style="padding-top: 1em;">{{ label }} ({{ count }})</h2>
{% if day_labels %}
<span class="label">{{ forloop.counter }}</span>
{% endif %}
- <span class="count" style="height: {% widthratio num total 100 %}%">
+ <span class="count" style="height: {% widthratio num total ratio %}%">
({{ num }})
</span>
</a>
View
4 django_histograms/templatetags/histograms.py
@@ -10,10 +10,10 @@
@tag(register, [Model(), Variable(), Optional([Variable(), Variable()])])
-def histogram_for(model, attname, months=2, day_labels=True):
+def histogram_for(context, model, attname, months=2, day_labels=True):
return Histogram(model, attname, months=months).render(css=True, day_labels=day_labels)
@tag(register, [Model(), Variable(), Optional([Variable(), Variable()])])
-def histogram_for_days(model, attname, days=31, day_labels=True):
+def histogram_for_days(context, model, attname, days=31, day_labels=True):
return Histogram(model, attname, days=days).render(css=True, day_labels=day_labels)
View
16 django_histograms/utils.py
@@ -64,7 +64,7 @@ def __init__(self, model, attname, queryset=None, months=None, days=None):
self.model = model
self.attname = attname
self._queryset = None
- assert(months or days, 'You must pass either months or days, not both.')
+ assert months or days, 'You must pass either months or days, not both.'
self.months = months
self.days = days
@@ -104,14 +104,22 @@ def get_report(self):
qs = self.get_query_set().values(self.attname).annotate(
num=Count("pk")
- ).filter(**{"%s__gt" % self.attname: cutoff})
+ ).filter(**{"%s__gt" % str(self.attname): cutoff})
for data in qs.iterator():
idx = grouper(data[self.attname])
months[idx][1][day_grouper(data[self.attname])] += data["num"]
months[idx][2] += data["num"]
- print months
+
+ total = sum(o for m in months.itervalues() for o in m[1])
+ max_num = max(o for m in months.itervalues() for o in m[1])
+ if not (total and max_num):
+ ratio = 0
+ else:
+ ratio = total / max_num * 100
+
return {
"results": months.values(),
- "total": sum(o for m in months.itervalues() for o in m[1]),
+ "total": total,
+ "ratio": ratio
}
Please sign in to comment.
Something went wrong with that request. Please try again.