示例#1
0
 def _get_html(self):
     from doccomment import get_parser_module
     return get_parser_module().parse(self.body)
示例#2
0
from django.contrib.comments.models import Comment
from django.utils import simplejson
from django.conf import settings

from models import Document
from models import DocumentVersion
from models import DocumentElement
from forms import DocumentForm


# Get class to use for checking user permissions
from doccomment import get_permission_class
Permission = get_permission_class()
# Get class for parsing author input to HTML
from doccomment import get_parser_module
Parser = get_parser_module()

@user_passes_test(Permission.user_can_view_published)
def ajax_get_comment_count(request, v_id):
    version = get_object_or_404(DocumentVersion, pk=v_id)
    document = version.document
    
    # XHR calls only, unless in DEBUG mode
    if not request.is_ajax() and not settings.DEBUG:
        return HttpResponseForbidden('Are you lost?')
        
    # for each page element, get number of comment;
    page_elem = [{} for i in xrange(version.elem_count)]
    for de in version.documentelement_set.all():
        elem = page_elem[de.position]
        elem['id'] = de.position