Permalink
Browse files

like/unlike in progress

  • Loading branch information...
1 parent 37571d9 commit b3bafec8642227697c6604adbbe9b78a7b994c9e @macadames macadames committed Apr 14, 2011
@@ -3,12 +3,16 @@
{% with content.likes as likes %}
{% if not likes.i_like %}
- <li class="i_like">
- I like
+ <li class="i_like"
+ id="toggle_like_{{ content.id }}">
+ <a class="toggle_like"
+ href="#">{% blocktrans %}I like{% endblocktrans %}</a>
</li>
{% else %}
- <li class="i_unlike">
- I don't like
+ <li class="i_unlike"
+ id="toggle_like_{{ content.id }}">
+ <a class="toggle_like"
+ href="#">{% blocktrans %}I don't like{% endblocktrans %}</a>
</li>
{% endif %}
@@ -0,0 +1,9 @@
+from django.conf.urls.defaults import *
+from twistranet.core.views import AsView
+from views import *
+
+
+urlpatterns = patterns('sharing',
+ url(r'^like_toggle_by_id/(\d+)$', AsView(LikeToggleView, lookup = 'id'), name=LikeToggleView.name),
+ url(r'^like_toggle_by_slug/(\d+)$', AsView(LikeToggleView, lookup = 'slug'), name=LikeToggleView.name),
+)
@@ -23,7 +23,7 @@
from twistranet.twistapp.forms import form_registry
from twistranet.twistapp.lib.log import *
from twistranet.core.views import *
-from models import Tag
+
class LikeToggleView(BaseObjectActionView):
@@ -42,6 +42,11 @@ def prepare_view(self, *args, **kw):
super(LikeToggleView, self).prepare_view(*args, **kw)
if not self.content.likes['i_like']:
self.content.like()
+ ilike = True
else:
self.content.unlike()
+ ilike = False
+ data = {'i_like' : ilike, 'n_likes' : self.content.likes.n_likes}
+ return HttpResponse( json.dumps(data),
+ mimetype='text/plain')
@@ -130,8 +130,8 @@
.postmetadata .add-comment { background: url(../images/icons/comment_blue_16.png) top left no-repeat; }
.postmetadata .add-comment:hover { background: url(../images/icons/comment_red_16.png) top left no-repeat;}
- .postmetadata .view-all-comments { background: url(../images/icons/comment_red_16.png) top left no-repeat; }
- .postmetadata .view-all-comments:hover { background: url(../images/icons/comment_blue_16.png) top left no-repeat;}
+ .postmetadata .view-all-comments { background: url(../images/icons/comment_blue_16.png) top left no-repeat; }
+ .postmetadata .view-all-comments:hover { background: url(../images/icons/comment_red_16.png) top left no-repeat;}
#pagenavigator {
clear: both;
@@ -0,0 +1,21 @@
+// Share/Like js helpers
+
+jq(function()
+{
+ jq(".i_like,.i_unlike,.toggle_like").click(function(e)
+ {
+ if (jq(e.target).is( "a" )) obj = jq(this).parent();
+ else obj =this;
+ e.preventDefault();
+ var ID = jq(obj).attr("id").replace('toggle_like_','');
+ jq.ajax({
+ type: "GET",
+ url: home_url + "share/like_toggle_by_id/" + ID,
+ cache: false,
+ success: function(data){
+ console.log(data);
+ }
+ });
+ return false;
+ })
+});
@@ -33,7 +33,8 @@
<script type="text/javascript" src="{% url twistranet_home %}static/js/jquery.dd.js" charset="utf-8"></script>
<script type="text/javascript" src="{% url twistranet_home %}static/js/fileuploader.js" charset="utf-8"></script>
<script type="text/javascript" src="{% url twistranet_home %}static/js/tn_quickupload_helpers.js" charset="utf-8"></script>
- <script type="text/javascript" src="{% url twistranet_home %}static/js/comments.js" charset="utf-8"></script>
+ <script type="text/javascript" src="{% url twistranet_home %}static/js/comments.js" charset="utf-8"></script>
+ <script type="text/javascript" src="{% url twistranet_home %}static/js/sharing.js" charset="utf-8"></script>
<script type="text/javascript" src="{% url twistranet_home %}static/js/tn.js" charset="utf-8"></script>
{% block local_js %}{% endblock %}
{% if form %}{{ form.media }}{% endif %}
@@ -1,3 +1,4 @@
+{% comment %} XXX TODO JMG : never use {{ content.id }} ad css id >> need also some refactoring in comment.js {% endcomment %}
{% load i18n %}
{% with content.comments.count as comment_count %}
<li
@@ -87,7 +87,10 @@
# Search engine
(r'^search/', include('twistranet.search.urls')),
-
+
+ # Like and Share engine
+ (r'^share/', include('twistranet.sharing.urls')),
+
# Tags management
(r'^tags/', include('twistranet.tagging.urls')),

0 comments on commit b3bafec

Please sign in to comment.