Skip to content

Commit

Permalink
Don't explode when anonymous users view bookmarkable objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
adammck committed Dec 7, 2011
1 parent 3aadefc commit c9acf78
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion hunchworks/templatetags/bookmark_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ def bookmarks(context, obj):
if "request" not in context:
return { }

# Silently abort if the user isn't logged in, since anonymous users can't
# bookmark things. (They shouldn't even be *seeing* bookmarkable objects
# right now, but that will probably change.)
user = context["request"].user
if not user.is_authenticated():
return { }

content_type = ContentType.objects.get_for_model(obj)

bookmark_count = models.Bookmark.objects.filter(
user_profile=context['request'].user.get_profile(),
user_profile=user.get_profile(),
content_type=content_type,
object_id=obj.id
).count()
Expand Down

0 comments on commit c9acf78

Please sign in to comment.