dlamotte / django-tagging

Automatically exported from code.google.com/p/django-tagging
Other
0 stars 0 forks source link

[PATCH] Float precision problem on Tag.objects.cloud_for_model #223

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'm having trouble with float precision in the
`Tag.objects.cloud_for_model` method. The problem causes the no creation of
the `font_size` attribute on the `Tag` object, what may cause problems to
the users. In my case, for instance, I had a server error in *all my pages*
due a `{{ tag.font_size|add:"10" }}` code in my base template.

This error can be shown by the following code:

{{{
from django.core.management import setup_environ
from blog import settings
setup_environ(settings)

from diario.models import Entry
from tagging.models import Tag

tagcloud = Tag.objects.cloud_for_model(Entry)
for tag in tagcloud:
        debug = 'tag: %s, count: %d, font_size:%s'
        print debug % (tag.name, tag.count, str(getattr(tag,
                'font_size', '***ERROR***')))
}}}

If I run the code above with the current version of the django-tagging, I
got the following output:

{{{
tag: debian, count: 5, font_size:4
tag: django, count: 3, font_size:3
tag: geoip, count: 1, font_size:1
tag: go, count: 1, font_size:1
tag: google, count: 1, font_size:1
tag: hello, count: 1, font_size:1
tag: ipython, count: 2, font_size:2
tag: programming, count: 1, font_size:1
tag: python, count: 6, font_size:***ERROR***
tag: seo, count: 1, font_size:1
tag: shell, count: 2, font_size:2
tag: sitemaps, count: 1, font_size:1
tag: sysadmin, count: 3, font_size:3
tag: ubuntu, count: 1, font_size:1
}}}

_Note the `font_size:***ERROR***` of the python's tag._

I fixed the problem but I don't know if my patch is the best way to solve
this issue and if it isn't, I'll be glad to know how to fix it. :)

After adding my patch and running the same code above, I got the following
output:

{{{
tag: debian, count: 5, font_size:4
tag: django, count: 3, font_size:3
tag: geoip, count: 1, font_size:1
tag: go, count: 1, font_size:1
tag: google, count: 1, font_size:1
tag: hello, count: 1, font_size:1
tag: ipython, count: 2, font_size:2
tag: programming, count: 1, font_size:1
tag: python, count: 6, font_size:4
tag: seo, count: 1, font_size:1
tag: shell, count: 2, font_size:2
tag: sitemaps, count: 1, font_size:1
tag: sysadmin, count: 3, font_size:3
tag: ubuntu, count: 1, font_size:1
}}}

_Note the `font_size:***ERROR***` of the python's tag that now shows the
correct value._

Original issue reported on code.google.com by arthur.furlan on 18 Nov 2009 at 2:38

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Related to issue #91.

Original comment by arthur.furlan on 18 Nov 2009 at 2:43