Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Handle anonymous users by not showing the button #6

Merged
merged 3 commits into from Nov 29, 2011
Jump to file or symbol
Failed to load files and symbols.
+18 −11
Split
@@ -1,7 +1,9 @@
{% block phileo_widget_form %}
<form class="phileo {{ is_liked }} {{ like_type }}" action="{{ like_url }}" method="POST" id="{{ widget_id }}">{% csrf_token %}
{% block phileo_widget_button %}
- <input type="submit" class="phileo-toggle" value="Like" />
+ {% if user.is_authenticated %}
+ <input type="submit" class="phileo-toggle" value="Like" />
+ {% endif %}
{% endblock phileo_widget_button %}
{% block phileo_widget_count %}
<span class="phileo-count">
@@ -78,22 +78,27 @@ def phileo_widget(user, obj, widget_id=None, like_type="like", toggle_class="phi
receiver_object_id = obj.pk
).count()
- liked = user.liking.filter(
- receiver_content_type = ct,
- receiver_object_id = obj.pk
- ).exists()
-
if widget_id == None:
widget_id = "phileo_%s_%s_%s" % (like_type, ct.pk, obj.pk)
like_count_id = "%s_count" % widget_id
-
- like_url = reverse("phileo_like_toggle", kwargs={
- "content_type_id": ct.pk,
- "object_id": obj.pk
- })
+
+ if user.is_anonymous():
+ liked = False
+ like_url = settings.LOGIN_URL
+ else:
+ like_url = reverse("phileo_like_toggle", kwargs={
+ "content_type_id": ct.id,
+ "object_id": obj.pk
+ })
+ liked = Like.objects.filter(
+ sender = user,
+ receiver_content_type = ct,
+ receiver_object_id = obj.pk
+ ).exists()
return {
+ "user": user,
"like_url": like_url,
"widget_id": widget_id,
"like_type": like_type,