'''

@author: olivier.massot, 2018
'''
from django.template.library import Library

from main.forms import CommentForm
from main.models import Comment

register = Library()

@register.inclusion_tag('_comment_div.html', takes_context=True)
def comments_for(context, obj):
    return {'obj': obj, 'user': context.request.user}

@register.simple_tag
def comment_new_form(target_obj):
    new_comment = Comment()
    new_comment.content_type = target_obj.get_content_type()
    new_comment.object_id = target_obj.id
    return CommentForm(instance=new_comment)

@register.simple_tag
def comment_edition_form(comment):
    return CommentForm(instance=comment)
