def like_toggle(request, content_type_id, object_id): content_type = get_object_or_404(ContentType, pk=content_type_id) obj = content_type.get_object_for_this_type(pk=object_id) if not request.user.has_perm("phileo.can_like", obj): return HttpResponseForbidden() like, liked = Like.like(request.user, content_type, object_id) if liked: object_liked.send(sender=Like, like=like, request=request) else: object_unliked.send(sender=Like, object=obj, request=request) if request.is_ajax(): html_ctx = widget_context(request.user, obj) template = "phileo/_widget.html" if request.GET.get("t") == "b": template = "phileo/_widget_brief.html" data = { "html": render_to_string(template, html_ctx, context_instance=RequestContext(request)), "likes_count": html_ctx["like_count"], "liked": html_ctx["liked"], } return HttpResponse(json.dumps(data), content_type="application/json") return redirect(request.META.get("HTTP_REFERER", "/"))
def like_toggle(request, content_type_id, object_id): content_type = get_object_or_404(ContentType, pk=content_type_id) obj = content_type.get_object_for_this_type(pk=object_id) if not request.user.has_perm("phileo.can_like", obj): return HttpResponseForbidden() like, liked = Like.like(request.user, content_type, object_id) if liked: object_liked.send(sender=Like, like=like, request=request) else: object_unliked.send(sender=Like, object=obj, request=request) if request.is_ajax(): html_ctx = widget_context(request.user, obj) template = "phileo/_widget.html" if request.GET.get("t") == "b": template = "phileo/_widget_brief.html" data = { "html": render_to_string( template, html_ctx, context_instance=RequestContext(request) ), "likes_count": html_ctx["like_count"], "liked": html_ctx["liked"], } return HttpResponse(json.dumps(data), content_type="application/json") return redirect(request.META.get("HTTP_REFERER", "/"))
def dehydrate(self, bundle): user = bundle.obj.user bundle.data['user_avatar'] = avatar(user.email, 64) bundle.data['user_name'] = user.username bundle.data['timesince'] = humanize.naturaltime( bundle.data['created_time']) bundle.data['comments_count'] = comments_count(bundle.obj) bundle.data['favicon'] = bundle.obj.favicon bundle.data['list_name'] = bundle.obj.list.name bundle.data['list_id'] = bundle.obj.list.id #: screenshot bundle.data['screenshot_image'] = bundle.obj.screenshot_image #: snapshot has_snapshot = False try: bundle.obj.snapshot except Snapshot.DoesNotExist: pass else: has_snapshot = True bundle.data['has_snapshot'] = has_snapshot #: like url like_info = widget_context(bundle.request.user, bundle.obj) bundle.data['like_info'] = like_info return bundle
def dehydrate(self, bundle): user = bundle.obj.user bundle.data['user_avatar'] = avatar(user.email, 64) bundle.data['user_name'] = user.username bundle.data['timesince'] = humanize.naturaltime(bundle.data['created_time']) bundle.data['comments_count'] = comments_count(bundle.obj) bundle.data['favicon'] = bundle.obj.favicon bundle.data['list_name'] = bundle.obj.list.name bundle.data['list_id'] = bundle.obj.list.id #: snapshot has_snapshot = False try: bundle.obj.snapshot except Snapshot.DoesNotExist: pass else: has_snapshot = True bundle.data['has_snapshot'] = has_snapshot #: like url like_info = widget_context(bundle.request.user, bundle.obj) bundle.data['like_info'] = like_info return bundle
def phileo_widget_brief(user, obj): return widget_context(user, obj)