Login

Tag "comments"

Snippet List

comments_allowed function for your model/...

Use this if you want to check if commenting is allowed for a certain object/model/... in a template. Like this; `{% if not object.comments_allowed %} <p>Comments are now closed.</p> {% else %} {% render_comment_form for object %} {% endif %}` You can replace the CommentModerator class with your own custom moderation class ofcourse.

  • comments
  • moderation
Read More

Prevent Django newcomments spam with Akismet (reloaded)

This is a rewrite of [snippet #1006](http://www.djangosnippets.org/snippets/1006/) to use the moderation features available in Django's comments framework. This is more customizable than the signals approach and works well if other moderation features are being used. If you want to make comments that are flagged as spam become hidden instead of deleted, change the allow() method to moderate(). [See the blog post here](http://sciyoshi.com/blog/2009/jul/17/prevent-django-newcomments-spam-akismet-reloaded/)

  • akismet
  • spam
  • comments
  • antispam
  • newcomments
Read More

Signal to notify new saved comments

Signal to notify new saved comments. **Example:** from django.contrib.comment import models, signals signals.comment_was_posted.connect(new_comment_notifier, sender=models.Comment)

  • django
  • python
  • comments
  • signals
Read More

Unobtrusive comment moderation, updated for Django 1.0

This is the "unobtrusive comments moderation" code from http://www.djangosnippets.org/snippets/112/ , but updated so it works properly with Django 1.0. There are only a few small changes reflecting changes in the comments, contenttypes, and signals APIs. For full background, see the original snippet: http://www.djangosnippets.org/snippets/112/

  • akismet
  • comments
  • moderation
Read More

Gravatar support for Django comments

A templatetag to add [Gravatar](http://www.gravatar.com/) support for [Django comments](http://docs.djangoproject.com/en/dev/ref/contrib/comments/ "Django Comments"). Based on [this snippet](http://www.djangosnippets.org/snippets/772/) but works for everyone who comments even if they are not a registered user.

  • comments
  • gravatar
Read More

Recaptcha with Django Comments

Working off b23's [recaptcha support](http://www.djangosnippets.org/snippets/433/), I have hacked a way to add recaptcha support using existing comments. I am sure there is a better way, and ultimately I will suggest a patch to add captcha support as an option, but for now I hope this helps. For a more detailed rundown (as well as a working sample), check out my [blog entry](http://nikolajbaer.us/blog/recaptcha-django-free-comments/).

  • comments
  • recaptcha
Read More

Email on new comments

In response to [#366](/snippets/366/), this is a subclass of the `CommentModerator` class from `comment_utils` which does nothing except email the "owner" of an object whenever a new comment is posted on it; all other moderation options remain inactive.

  • email
  • comments
Read More

Email on new comments

I know ubernostrum has the nice comment_utils, but I need something that would notify the owner of the comment's content object (where the model has a foreignkey field to django.contrib.auth.models.User), but I didn't need all the moderation stuff. I stuck this in my models.py, where YOURMODEL is the name of the model object with comments attached, and a user field.

  • email
  • comments
Read More

Cheetah-style comments

For those who find the Django comments syntax tedious, this snippet enables the use of (almost) Cheetah-style comments.

  • template
  • comments
  • cheetah
Read More

Strip html comments middleware

Middleware for stripping all html comments from the response content before returning it to the client. This will also strip inline javascript with htmlcomments put around it!

  • middleware
  • comments
Read More

Unobtrusive comment moderation

**Before using this snippet**, please note that it's largely been superseded by [comment_utils](http://code.google.com/p/django-comment-utils/), which includes a more featureful and extensible version of this system, particularly with respect to additional moderation options and useful things like email notifications of comments. Once upon a time I hacked the copy of `django.contrib.comments` I'm using on my blog, so that I could have comments get set to `is_public=False` if posted more than 30 days after the entry's publication, and to add Akismet spam filtering. I've regretted it ever since, because it's made upgrading my copy of Django a pain. So here's an improved version which doesn't require hacking directly on Django. To use it, you'll need to do a few things: 1. Grab the [Python Akismet module](http://www.voidspace.org.uk/python/modules.shtml#akismet) and install it somewhere on your server. 2. In your settings file, add `AKISMET_API_KEY`, and make sure its value is a valid Akismet key. If you don't have an Akismet key, you can [get one at wordpress.com](http://wordpress.com/api-keys/). 3. Put this code -- both the function and the dispatcher calls -- somewhere in your project that's _guaranteed_ to be imported early (until this code is executed, the moderation function won't be set up to listen for comments posting). To have comments on a certain type of object (say, weblog entries) automatically go into moderation when the object reaches a certain age, define a method on that object's model called `comments_open`, and have it return `False` when comments should be auto-moderated.

  • akismet
  • comments
  • moderation
Read More

Get most-commented objects

This is a pretty straightforward bit of code for getting the most-commented objects of a particular model; just drop it into a custom manager for that model, and you should be good to go. Check the docstring for how to make it look at `Comment` instead of `FreeComment`.

  • managers
  • comments
  • popularity
Read More

15 snippets posted so far.