def comments_likes(request, target, form, expand=True): dajax = Dajax() response_format = 'html' object_id = form.get('object_id', 0) update = form.get('update', 0) if update: obj = UpdateRecord.objects.get(pk=object_id) else: obj = Object.objects.get(pk=object_id) profile = request.user.profile if obj: if form.get('like', 0) == unicode(obj.id): obj.likes.add(profile) if hasattr(obj, 'score'): obj.score += 1 obj.save() elif form.get('unlike', 0) == unicode(obj.id): obj.likes.remove(profile) if hasattr(obj, 'score'): obj.score -= 1 obj.save() elif form.get('dislike', 0) == unicode(obj.id): obj.dislikes.add(profile) if hasattr(obj, 'score'): obj.score += 1 obj.save() elif form.get('undislike', 0) == unicode(obj.id): obj.dislikes.remove(profile) if hasattr(obj, 'score'): obj.score -= 1 obj.save() elif form.get('commentobject', 0) == unicode(obj.id) and 'comment' in form: comment = Comment(author=profile, body=form.get('comment')) comment.save() if hasattr(obj, 'score'): obj.score += 1 obj.save() obj.comments.add(comment) likes = obj.likes.all() dislikes = obj.dislikes.all() comments = obj.comments.all() ilike = profile in likes idislike = profile in dislikes icommented = comments.filter(author=profile).exists() or \ comments.filter(author__default_group__in=[ profile.default_group_id] + [i.id for i in profile.other_groups.all().only('id')]).exists() output = render_to_string('core/tags/comments_likes', {'object': obj, 'is_update': update, 'profile': profile, 'likes': likes, 'dislikes': dislikes, 'comments': comments, 'ilike': ilike, 'idislike': idislike, 'icommented': icommented, 'expand': expand}, context_instance=RequestContext(request), response_format=response_format) dajax.add_data({'target': target, 'content': output}, 'anaf.add_data') return dajax.json()
def comments_likes(request, target, form, expand=True): dajax = Dajax() response_format = 'html' object_id = form.get('object_id', 0) update = form.get('update', 0) if update: obj = UpdateRecord.objects.get(pk=object_id) else: obj = Object.objects.get(pk=object_id) profile = request.user.profile if obj: if form.get('like', 0) == unicode(obj.id): obj.likes.add(profile) if hasattr(obj, 'score'): obj.score += 1 obj.save() elif form.get('unlike', 0) == unicode(obj.id): obj.likes.remove(profile) if hasattr(obj, 'score'): obj.score -= 1 obj.save() elif form.get('dislike', 0) == unicode(obj.id): obj.dislikes.add(profile) if hasattr(obj, 'score'): obj.score += 1 obj.save() elif form.get('undislike', 0) == unicode(obj.id): obj.dislikes.remove(profile) if hasattr(obj, 'score'): obj.score -= 1 obj.save() elif form.get('commentobject', 0) == unicode( obj.id) and 'comment' in form: comment = Comment(author=profile, body=form.get('comment')) comment.save() if hasattr(obj, 'score'): obj.score += 1 obj.save() obj.comments.add(comment) likes = obj.likes.all() dislikes = obj.dislikes.all() comments = obj.comments.all() ilike = profile in likes idislike = profile in dislikes icommented = comments.filter(author=profile).exists() or \ comments.filter(author__default_group__in=[ profile.default_group_id] + [i.id for i in profile.other_groups.all().only('id')]).exists() output = render_to_string('core/tags/comments_likes', { 'object': obj, 'is_update': update, 'profile': profile, 'likes': likes, 'dislikes': dislikes, 'comments': comments, 'ilike': ilike, 'idislike': idislike, 'icommented': icommented, 'expand': expand }, context_instance=RequestContext(request), response_format=response_format) dajax.add_data({'target': target, 'content': output}, 'anaf.add_data') return dajax.json()
def comments_likes(context, object, expand=True): "Comments and Likes/Dislikes box for an object" request = context['request'] response_format = 'html' if 'response_format' in context: response_format = context['response_format'] update = isinstance(object, UpdateRecord) profile = request.user.profile if request.POST.get('like', 0) == unicode(object.id): object.likes.add(profile) if hasattr(object, 'score'): object.score += 1 object.save() elif request.POST.get('unlike', 0) == unicode(object.id): object.likes.remove(profile) if hasattr(object, 'score'): object.score -= 1 object.save() elif request.POST.get('dislike', 0) == unicode(object.id): object.dislikes.add(profile) if hasattr(object, 'score'): object.score += 1 object.save() elif request.POST.get('undislike', 0) == unicode(object.id): object.dislikes.remove(profile) if hasattr(object, 'score'): object.score -= 1 object.save() elif request.POST.get('commentobject', 0) == unicode( object.id) and 'comment' in request.POST: comment = Comment(author=profile, body=request.POST.get('comment')) comment.save() if hasattr(object, 'score'): object.score += 1 object.save() object.comments.add(comment) likes = object.likes.all() dislikes = object.dislikes.all() comments = object.comments.all() ilike = profile in likes idislike = profile in dislikes icommented = comments.filter(author=profile).exists() or \ comments.filter(author__default_group__in=[ profile.default_group_id] + [i.id for i in profile.other_groups.all().only('id')]).exists() return Markup( render_to_string('core/tags/comments_likes', { 'object': object, 'is_update': update, 'profile': profile, 'likes': likes, 'dislikes': dislikes, 'comments': comments, 'ilike': ilike, 'idislike': idislike, 'icommented': icommented, 'expand': expand }, context_instance=RequestContext(request), response_format=response_format))
def comments_likes(context, object, expand=True): "Comments and Likes/Dislikes box for an object" request = context['request'] response_format = 'html' if 'response_format' in context: response_format = context['response_format'] update = isinstance(object, UpdateRecord) profile = request.user.profile if request.POST.get('like', 0) == unicode(object.id): object.likes.add(profile) if hasattr(object, 'score'): object.score += 1 object.save() elif request.POST.get('unlike', 0) == unicode(object.id): object.likes.remove(profile) if hasattr(object, 'score'): object.score -= 1 object.save() elif request.POST.get('dislike', 0) == unicode(object.id): object.dislikes.add(profile) if hasattr(object, 'score'): object.score += 1 object.save() elif request.POST.get('undislike', 0) == unicode(object.id): object.dislikes.remove(profile) if hasattr(object, 'score'): object.score -= 1 object.save() elif request.POST.get('commentobject', 0) == unicode(object.id) and 'comment' in request.POST: comment = Comment(author=profile, body=request.POST.get('comment')) comment.save() if hasattr(object, 'score'): object.score += 1 object.save() object.comments.add(comment) likes = object.likes.all() dislikes = object.dislikes.all() comments = object.comments.all() ilike = profile in likes idislike = profile in dislikes icommented = comments.filter(author=profile).exists() or \ comments.filter(author__default_group__in=[ profile.default_group_id] + [i.id for i in profile.other_groups.all().only('id')]).exists() return Markup(render_to_string('core/tags/comments_likes', {'object': object, 'is_update': update, 'profile': profile, 'likes': likes, 'dislikes': dislikes, 'comments': comments, 'ilike': ilike, 'idislike': idislike, 'icommented': icommented, 'expand': expand}, context_instance=RequestContext(request), response_format=response_format))