forked from praekelt/django-likes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
shaunsephton
committed
May 24, 2010
1 parent
38a03b4
commit f43ffd8
Showing
7 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function like(click_selector, url, replace_selector) { | ||
$(click_selector).click(function() { | ||
$.ajax({ | ||
url: url, | ||
success: function(html){ | ||
$(replace_selector).replaceWith(html); | ||
} | ||
}); | ||
return false; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from secretballot.middleware import SecretBallotIpUseragentMiddleware | ||
|
||
class SecretBallotUserIpUseragentMiddleware(SecretBallotIpUseragentMiddleware): | ||
def generate_token(self, request): | ||
if request.user.is_authenticated(): | ||
return request.user.username | ||
else: | ||
return super(SecretBallotUserIpUseragentMiddleware, self).generate_token(request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% if not content_obj.likes_closed %} | ||
<p class="likes"> | ||
{{ content_obj.vote_total }} | ||
<span> | ||
{% if can_vote %} | ||
<a class="liker" href="{% url like_modelbase content_obj.id 1 %}">I Like</a> | ||
<script type="text/javascript" src="/media/likes/includes/likes.js"></script> | ||
<script type="text/javascript"> | ||
$(function() { | ||
like(".liker", "{% url like_modelbase_ajax content_obj.id 1 %}", ".likes"); | ||
}); | ||
</script> | ||
{% else %} | ||
Likes | ||
{% endif %} | ||
</span> | ||
</p> | ||
{% endif %} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from secretballot.models import Vote | ||
|
||
from django import template | ||
|
||
register = template.Library() | ||
|
||
@register.inclusion_tag('likes/inclusion_tags/likes.html', takes_context=True) | ||
def likes(context, obj): | ||
request = context['request'] | ||
context.update({ | ||
'content_obj': obj, | ||
'can_vote': obj.can_vote(request), | ||
}) | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.conf.urls.defaults import patterns, url | ||
|
||
urlpatterns = patterns( | ||
'likes.views', | ||
url(r'^like/mb/(?P<id>\d+)/(?P<vote>\d+)$', 'like_modelbase', name='like_modelbase'), | ||
url(r'^like/mba/(?P<id>\d+)/(?P<vote>\d+)$', 'like_modelbase_ajax', name='like_modelbase_ajax'), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from content.models import ModelBase | ||
|
||
from secretballot import views | ||
|
||
def can_vote(request, content_type, object_id, vote): | ||
return content_type.model_class().objects.get(id=object_id).can_vote(request) | ||
|
||
def like_modelbase(request, id, vote): | ||
redirect_url = request.META['HTTP_REFERER'] | ||
return views.vote(request, content_type=ModelBase, object_id=id, vote=vote, redirect_url=redirect_url, can_vote_test=can_vote) | ||
|
||
def like_modelbase_ajax(request, id, vote): | ||
return views.vote(request, content_type=ModelBase, object_id=id, vote=vote, template_name='likes/inclusion_tags/likes.html', can_vote_test=can_vote, extra_context={'can_vote': False}) |