Handle anonymous users by not showing the button #6

merged 3 commits into from Nov 29, 2011


None yet

2 participants


A rehash of the old anonymous users pull request, as requested.

If an anonymous user access a page with a like widget, the page breaks. This is because the AnonymousUser class does not have a likes collection, whereas the normal User class does. This patch checks for anonymous users before attempting to get their likes. Additionally, the likes widget does NOT show the like button if the user is not logged in.

Tim Heap added some commits Nov 28, 2011
Tim Heap Handle anonymous users by not showing the button 1ce168e
Tim Heap Include the user in the phileo_widget context
Anonymous user detection wasnt working correctly, as the user was not
always in the template context at render time. This resulted in the
'like' button just plain old not being shown in some circumstances,
which is incorrect. By explicitly including the user in the context,
this problem is solved
@paltman paltman and 1 other commented on an outdated diff Nov 29, 2011
- 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 = ContentType.objects.get_for_model(obj),
paltman Nov 29, 2011

could we just use ct here instead of another ContentType query?

timheap Nov 29, 2011

Yup, I missed the ct variable there. Ill make use of it instead of querying for it again.

@paltman paltman merged commit 957252a into pinax:master Nov 29, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment