Skip to content

Commit

Permalink
more whitespace'
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Jan 23, 2010
2 parents d65af79 + 8841dcf commit e1050c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -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 %}
2 changes: 1 addition & 1 deletion django_histograms/templates/histograms/report.html
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions django_histograms/templatetags/histograms.py
Expand Up @@ -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)
16 changes: 12 additions & 4 deletions django_histograms/utils.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

0 comments on commit e1050c2

Please sign in to comment.