Skip to content

Commit

Permalink
Add toggle class to widget
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman committed Oct 31, 2011
1 parent fde4fa4 commit 27adf64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion phileo/__init__.py
@@ -1,2 +1,2 @@
# following PEP 386
__version__ = "0.2.dev3"
__version__ = "0.2.dev4"
2 changes: 1 addition & 1 deletion phileo/templates/phileo/_widget.html
@@ -1,4 +1,4 @@
<div class="phileo">
<a id="{{ like_link }}"></a>
<a class="{{ toggle_class }}" id="{{ like_link }}"></a>
<span class="{{ like_span_total }}">{{ likes_count }}</span>
</div>
11 changes: 9 additions & 2 deletions phileo/templatetags/phileo_tags.py
Expand Up @@ -2,6 +2,7 @@
from django.conf import settings
from django.core.urlresolvers import reverse

from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType

from phileo.models import Like
Expand Down Expand Up @@ -67,14 +68,20 @@ def likes_css():

@register.inclusion_tag("phileo/_widget.html")
def likes_widget(user, obj, like_link_id="likes", like_span_total_class="phileo-count", toggle_class="phileo-liked"):
ct = ContentType.objects.get_for_model(obj)
likes_count = Like.objects.filter(
receiver_content_type = ContentType.objects.get_for_model(obj),
receiver_content_type = ct,
receiver_object_id = obj.pk
).count()
liked = user.liking.filter(
receiver_content_type = ct,
receiver_object_id = obj.pk
).exists()
return {
"like_link": like_link_id,
"like_span_total": like_span_total_class,
"likes_count": likes_count
"likes_count": likes_count,
"toggle_class": toggle_class if liked else ""
}


Expand Down

0 comments on commit 27adf64

Please sign in to comment.