Example #1
0
def comment_create(request):
    """Create a comment for a Post, or a Comment reply."""
    form = forms.CommentForm(request.POST)
    if not form.is_valid():
        return JsonResponse({'error': form.errors.as_json()}, status=422)

    entity_type = ContentType.objects.get_for_id(
        form.cleaned_data['entity_content_type_id'])
    entity = entity_type.get_object_for_this_type(
        id=form.cleaned_data['entity_object_id'])

    comment = Comment.objects.create(
        user=request.user,
        content=form.cleaned_data['content'],
        entity=entity,
        parent_comment_id=form.cleaned_data['parent_comment_id'],
    )

    return JsonResponse({
        'status':
        'success',
        'content':
        render_to_string('dillo/components/_comment_view.pug',
                         {'comment': comment}),
    })
Example #2
0
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['form_comment'] = forms.CommentForm({
         'entity_object_id':
         self.object.id,
         'entity_content_type_id':
         self.object.content_type_id,
     })
     context['og_data'] = self.populate_og_data(kwargs['object'])
     context['related_posts'] = self.get_related_posts(self.object)
     return context
 def get_context_data(self, **kwargs):
     context = super().get_context_data(**kwargs)
     context['form_comment'] = forms.CommentForm(
         {'post_id': self.object.id})
     context['og_data'] = self.populate_og_data(kwargs['object'])
     return context