コード例 #1
0
ファイル: comments.py プロジェクト: lvboqi/vlevit.org
 def import_comments_list(comments, obj, parent=None):
     # import comments to a database
     count = 0
     for c in comments:
         # consider comments with equal date to be the same
         # this makes possible to update all other comment fields
         try:
             comment = ThreadedComment.objects.get(
                 submit_date=c['published'])
         except ThreadedComment.DoesNotExist:
             comment_pk = None
         except ThreadedComment.MultipleObjectsReturned:
             logger.error(
                 "more then one comment with the same "
                 "publish date: %s", c['published'])
             continue
         else:
             comment_pk = comment.pk
         comment = ThreadedComment(
             pk=comment_pk,
             content_type=ContentType.objects.get_for_model(obj.__class__),
             object_pk=unicode(obj.pk),
             user_name=c['author'],
             user_url=c.get('website', ''),
             comment=c['content'],
             submit_date=c['published'],
             site_id=settings.SITE_ID,
             is_public=True,
             is_removed=False,
             parent=parent,
             comment_html=safe_markdown(c['content']))
         comment.save()
         count += 1
         if 'replies' in c:
             count += import_comments_list(c['replies'], obj, comment)
     return count
コード例 #2
0
ファイル: comments.py プロジェクト: vlevit/vlevit.org
 def import_comments_list(comments, obj, parent=None):
     # import comments to a database
     count = 0
     for c in comments:
         # consider comments with equal date to be the same
         # this makes possible to update all other comment fields
         try:
             comment = ThreadedComment.objects.get(
                 submit_date=c['published'])
         except ThreadedComment.DoesNotExist:
             comment_pk = None
         except ThreadedComment.MultipleObjectsReturned:
             logger.error("more then one comment with the same "
                          "publish date: %s", c['published'])
             continue
         else:
             comment_pk = comment.pk
         comment = ThreadedComment(
             pk=comment_pk,
             content_type=ContentType.objects.get_for_model(
                 obj.__class__),
             object_pk=unicode(obj.pk),
             user_name=c['author'],
             user_url=c.get('website', ''),
             comment=c['content'],
             submit_date=c['published'],
             site_id=settings.SITE_ID,
             is_public=True,
             is_removed=False,
             parent=parent,
             comment_html=safe_markdown(c['content']))
         comment.save()
         count += 1
         if 'replies' in c:
             count += import_comments_list(c['replies'], obj, comment)
     return count
コード例 #3
0
ファイル: views.py プロジェクト: vlevit/vlevit.org
def preview_comment(request):
    comment = request.GET.get('comment', '')
    return HttpResponse(safe_markdown(comment))
コード例 #4
0
 def get_comment_create_data(self):
     d = super(ThreadedCommentForm, self).get_comment_create_data()
     d['parent_id'] = self.cleaned_data['parent']
     d['comment_html'] = safe_markdown(self.cleaned_data['comment'])
     return d
コード例 #5
0
ファイル: forms.py プロジェクト: vlevit/vlevit.org
 def get_comment_create_data(self):
     d = super(ThreadedCommentForm, self).get_comment_create_data()
     d['parent_id'] = self.cleaned_data['parent']
     d['comment_html'] = safe_markdown(self.cleaned_data['comment'])
     return d
コード例 #6
0
def preview_comment(request):
    comment = request.GET.get('comment', '')
    return HttpResponse(safe_markdown(comment))