Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion phileo/templates/phileo/_widget.html
Original file line number Diff line number Diff line change
@@ -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">
Expand Down
25 changes: 15 additions & 10 deletions phileo/templatetags/phileo_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down