def __init__(self, *args, **kwargs): super(CommentsRelation, self).__init__( to=get_comments_model(), content_type_field='content_type', object_id_field='object_pk', **kwargs )
def comment(post): comment_model = get_comments_model() instance = comment_model(content_object=post, site_id=settings.SITE_ID, title="foobar", comment="bar baz") instance.save() return instance
def get_comments_for_model(content_object, include_moderated=False): """ Return the QuerySet with all comments for a given model. """ qs = get_comments_model().objects.for_model(content_object) if not include_moderated: qs = qs.filter(is_public=True, is_removed=False) return qs
def test_add_new_comment(self, client, post, comments_enabled): ajax_url = reverse("comments-post-comment-ajax") slugs = {"blog_slug": post.blog.slug, "slug": post.slug} detail_url = reverse("cast:post_detail", kwargs=slugs) r = client.get(detail_url) content = r.content.decode("utf-8") for line in content.split("\n"): if "security_hash" in line: for part in line.split("input"): if "security_hash" in part: for attr in part.split(" "): if "value" in attr: security_hash = attr.split('"')[1] if "timestamp" in part: for attr in part.split(): if "value" in attr: timestamp = attr.split('"')[1] data = { "content_type": "cast.post", "object_pk": str(post.pk), "comment": "new content", "name": "Name", "email": "*****@*****.**", "title": "buzz", "security_hash": security_hash, "timestamp": timestamp, } r = client.post(ajax_url, data, HTTP_X_REQUESTED_WITH="XMLHttpRequest") assert r.status_code == 200 rdata = r.json() assert rdata["success"] comment = get_comments_model().objects.get(pk=rdata["object_id"]) assert comment.comment == data["comment"]
return force_text(comment.user) else: return None user_name_col.short_description = _("user's name") def has_add_permission(self, request): return False def has_change_permission(self, request, obj=None): return request.user.has_perm('comments.change_fluentcomment') def has_delete_permission(self, request, obj=None): return request.user.has_perm('comments.delete_fluentcomment') def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == 'title': kwargs['widget'] = AdminTextInputWidget return super(FluentCommentsAdmin, self).formfield_for_dbfield(db_field, **kwargs) # Replace the old admin screen. if appsettings.FLUENT_COMMENTS_REPLACE_ADMIN: CommentModel = get_comments_model() try: admin.site.unregister(CommentModel) except admin.sites.NotRegistered as e: pass admin.site.register(CommentModel, FluentCommentsAdmin)
object_link.allow_tags = True def user_name_col(self, comment): if comment.user_name: return comment.user_name elif comment.user_id: return force_text(comment.user) else: return None user_name_col.short_description = _("user's name") def has_add_permission(self, request): return False def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == 'title': kwargs['widget'] = AdminTextInputWidget return super(FluentCommentsAdmin, self).formfield_for_dbfield(db_field, **kwargs) # Replace the old admin screen. if appsettings.FLUENT_COMMENTS_REPLACE_ADMIN: CommentModel = get_comments_model() try: admin.site.unregister(CommentModel) except admin.sites.NotRegistered as e: pass admin.site.register(CommentModel, FluentCommentsAdmin)
def __init__(self, *args, **kwargs): super().__init__(to=get_comments_model(), content_type_field="content_type", object_id_field="object_pk", **kwargs)