def threaded_comment_json(request, comment): viewer = request.user coll = ContentType.objects.get_for_model(Collaboration) all_comments = ThreadedComment.objects.filter( content_type=coll, object_pk=comment.content_object.pk, site__pk=settings.SITE_ID) all_comments = fill_tree(all_comments) all_comments = list(annotate_tree_properties(all_comments)) rand = ''.join([choice(letters) for i in range(5)]) citations = threaded_comment_citations(all_comments, viewer) asset_resource = AssetResource() sherd_resource = SherdNoteResource() 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_comments] }, 'assets': dict([('%s_%s' % (rand, ann.asset.pk), asset_resource.render_one(request, ann.asset)) for ann in citations if (ann.title != "Annotation Deleted" and ann.title != 'Asset Deleted')]), 'annotations': [sherd_resource.render_one(request, ann, rand) for ann in citations], }
def threaded_comment_json(request, comment): viewer = request.user coll = ContentType.objects.get_for_model(Collaboration) all_comments = ThreadedComment.objects.filter( content_type=coll, object_pk=comment.content_object.pk, site__pk=settings.SITE_ID) all_comments = fill_tree(all_comments) all_comments = list(annotate_tree_properties(all_comments)) rand = ''.join([choice(letters) for i in range(5)]) citations = threaded_comment_citations(all_comments, viewer) asset_resource = AssetResource() sherd_resource = SherdNoteResource() return { 'type': 'discussion', 'form': django_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_comments] }, 'assets': dict([('%s_%s' % (rand, ann.asset.pk), asset_resource.render_one(request, ann.asset)) for ann in citations if (ann.title != "Annotation Deleted" and ann.title != 'Asset Deleted')]), 'annotations': [sherd_resource.render_one(request, ann, rand) for ann in citations], }
def test_pretty_date(self): timestamp = datetime.now() self.assertTrue('seconds ago' in pretty_date(timestamp)) self.assertTrue('a minute ago' in pretty_date(timestamp - timedelta(minutes=1))) self.assertTrue('minutes ago' in pretty_date(timestamp - timedelta(minutes=2))) self.assertTrue('hour(s) ago' in pretty_date(timestamp - timedelta(hours=3))) self.assertTrue('Yesterday' in pretty_date(timestamp - timedelta(days=1))) timestamp = timestamp - timedelta(days=5) self.assertTrue('days ago' in pretty_date(timestamp))
def test_pretty_date(self): timestamp = datetime.now() self.assertTrue('seconds ago' in pretty_date(timestamp)) self.assertTrue('a minute ago' in pretty_date(timestamp - timedelta(minutes=1))) self.assertTrue('minutes ago' in pretty_date(timestamp - timedelta(minutes=2))) self.assertTrue('hour(s) ago' in pretty_date(timestamp - timedelta(hours=3))) self.assertTrue('Yesterday' in pretty_date(timestamp - timedelta(days=1))) timestamp = timestamp - timedelta(days=5) self.assertTrue('days ago' in pretty_date(timestamp))