Пример #1
0
def threaded_comment_json(comment, viewer):
    coll = ContentType.objects.get_for_model(Collaboration)
    all = ThreadedComment.objects.filter(content_type=coll, object_pk=comment.content_object.pk, site__pk=settings.SITE_ID)
    all = fill_tree(all)
    all = annotate_tree_properties(all)

    return {
        'type': 'discussion',
        'form': comments.get_form()(comment.content_object).__unicode__(),
        'editing': True,
        'can_edit': True,
        'discussion': {
            'id': comment.id,
            'max_length': COMMENT_MAX_LENGTH,
            'thread': [{ 'open': obj.open if hasattr(obj, "open") else None,
                         'close': [ i for i in obj.close ] if hasattr(obj, "close") else None,
                         'id': obj.id,
                         'author': obj.name,
                         'author_username': obj.user.username,
                         'submit_date': pretty_date(obj.submit_date),
                         'title': obj.title,
                         'content': obj.comment,
                         'can_edit': True if obj.user == viewer else False
                       } for obj in all]
         }
    }
Пример #2
0
def threaded_comment_json(comment, viewer):
    coll = ContentType.objects.get_for_model(Collaboration)
    all = ThreadedComment.objects.filter(
        content_type=coll, object_pk=comment.content_object.pk, site__pk=settings.SITE_ID
    )
    all = fill_tree(all)
    all = annotate_tree_properties(all)

    return {
        "type": "discussion",
        "form": comments.get_form()(comment.content_object).__unicode__(),
        "editing": True,
        "can_edit": True,
        "discussion": {
            "id": comment.id,
            "max_length": COMMENT_MAX_LENGTH,
            "thread": [
                {
                    "open": obj.open if hasattr(obj, "open") else None,
                    "close": [i for i in obj.close] if hasattr(obj, "close") else None,
                    "id": obj.id,
                    "author": obj.name,
                    "author_username": obj.user.username,
                    "submit_date": pretty_date(obj.submit_date),
                    "title": obj.title,
                    "content": obj.comment,
                    "can_edit": True if obj.user == viewer else False,
                }
                for obj in all
            ],
        },
    }
Пример #3
0
def threaded_comment_json(request, comment):
    viewer = request.user
    coll = ContentType.objects.get_for_model(Collaboration)
    all = ThreadedComment.objects.filter(content_type=coll,
                                         object_pk=comment.content_object.pk,
                                         site__pk=settings.SITE_ID)
    all = fill_tree(all)
    all = list(annotate_tree_properties(all))

    rand = ''.join([choice(letters) for i in range(5)])
    citations = threaded_comment_citations(all, viewer)

    return {
        'type': 'discussion',
        'form': comments.get_form()(comment.content_object).__unicode__(),
        'editing': True,
        'can_edit': True,
        'discussion': {
            'id': comment.id,
            'max_length': COMMENT_MAX_LENGTH,
            'thread': [{'open': obj.open if hasattr(obj, "open") else None,
                        'close': [i for i in obj.close]
                        if hasattr(obj, "close") else None,
                        'id': obj.id,
                        'author': obj.name,
                        'author_username': obj.user.username,
                        'submit_date': pretty_date(obj.submit_date),
                        'title': obj.title,
                        'content': obj.comment,
                        'can_edit': True if obj.user == viewer else False}
                       for obj in all]
        },
        'assets': dict([('%s_%s' % (rand, ann.asset.pk),
                        ann.asset.sherd_json(request)) for ann in citations
                       if (ann.title != "Annotation Deleted" and
                           ann.title != 'Asset Deleted')]),
        'annotations': [ann.sherd_json(request, rand, ('title', 'author'))
                        for ann in citations],
    }