summaryrefslogtreecommitdiff
path: root/django/contrib/comments
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/comments')
-rw-r--r--django/contrib/comments/admin.py30
-rw-r--r--django/contrib/comments/models.py26
-rw-r--r--django/contrib/comments/views/comments.py52
3 files changed, 82 insertions, 26 deletions
diff --git a/django/contrib/comments/admin.py b/django/contrib/comments/admin.py
new file mode 100644
index 0000000000..81ecc699c7
--- /dev/null
+++ b/django/contrib/comments/admin.py
@@ -0,0 +1,30 @@
+from django.contrib import admin
+from django.contrib.comments.models import Comment, FreeComment
+
+
+class CommentAdmin(admin.ModelAdmin):
+ fieldsets = (
+ (None, {'fields': ('content_type', 'object_id', 'site')}),
+ ('Content', {'fields': ('user', 'headline', 'comment')}),
+ ('Ratings', {'fields': ('rating1', 'rating2', 'rating3', 'rating4', 'rating5', 'rating6', 'rating7', 'rating8', 'valid_rating')}),
+ ('Meta', {'fields': ('is_public', 'is_removed', 'ip_address')}),
+ )
+ list_display = ('user', 'submit_date', 'content_type', 'get_content_object')
+ list_filter = ('submit_date',)
+ date_hierarchy = 'submit_date'
+ search_fields = ('comment', 'user__username')
+ raw_id_fields = ('user',)
+
+class FreeCommentAdmin(admin.ModelAdmin):
+ fieldsets = (
+ (None, {'fields': ('content_type', 'object_id', 'site')}),
+ ('Content', {'fields': ('person_name', 'comment')}),
+ ('Meta', {'fields': ('is_public', 'ip_address', 'approved')}),
+ )
+ list_display = ('person_name', 'submit_date', 'content_type', 'get_content_object')
+ list_filter = ('submit_date',)
+ date_hierarchy = 'submit_date'
+ search_fields = ('comment', 'person_name')
+
+admin.site.register(Comment, CommentAdmin)
+admin.site.register(FreeComment, FreeCommentAdmin) \ No newline at end of file
diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py
index d0c54b85cb..a13fec9e6e 100644
--- a/django/contrib/comments/models.py
+++ b/django/contrib/comments/models.py
@@ -66,7 +66,7 @@ class CommentManager(models.Manager):
class Comment(models.Model):
"""A comment by a registered user."""
- user = models.ForeignKey(User, raw_id_admin=True)
+ user = models.ForeignKey(User)
content_type = models.ForeignKey(ContentType)
object_id = models.IntegerField(_('object ID'))
headline = models.CharField(_('headline'), max_length=255, blank=True)
@@ -96,18 +96,6 @@ class Comment(models.Model):
verbose_name_plural = _('comments')
ordering = ('-submit_date',)
- class Admin:
- fields = (
- (None, {'fields': ('content_type', 'object_id', 'site')}),
- ('Content', {'fields': ('user', 'headline', 'comment')}),
- ('Ratings', {'fields': ('rating1', 'rating2', 'rating3', 'rating4', 'rating5', 'rating6', 'rating7', 'rating8', 'valid_rating')}),
- ('Meta', {'fields': ('is_public', 'is_removed', 'ip_address')}),
- )
- list_display = ('user', 'submit_date', 'content_type', 'get_content_object')
- list_filter = ('submit_date',)
- date_hierarchy = 'submit_date'
- search_fields = ('comment', 'user__username')
-
def __unicode__(self):
return "%s: %s..." % (self.user.username, self.comment[:100])
@@ -188,17 +176,6 @@ class FreeComment(models.Model):
verbose_name_plural = _('free comments')
ordering = ('-submit_date',)
- class Admin:
- fields = (
- (None, {'fields': ('content_type', 'object_id', 'site')}),
- ('Content', {'fields': ('person_name', 'comment')}),
- ('Meta', {'fields': ('submit_date', 'is_public', 'ip_address', 'approved')}),
- )
- list_display = ('person_name', 'submit_date', 'content_type', 'get_content_object')
- list_filter = ('submit_date',)
- date_hierarchy = 'submit_date'
- search_fields = ('comment', 'person_name')
-
def __unicode__(self):
return "%s: %s..." % (self.person_name, self.comment[:100])
@@ -306,3 +283,4 @@ class ModeratorDeletion(models.Model):
def __unicode__(self):
return _("Moderator deletion by %r") % self.user
+ \ No newline at end of file
diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py
index 67da5759ac..ba59cbafc9 100644
--- a/django/contrib/comments/views/comments.py
+++ b/django/contrib/comments/views/comments.py
@@ -1,3 +1,6 @@
+import base64
+import datetime
+
from django.core import validators
from django import oldforms
from django.core.mail import mail_admins, mail_managers
@@ -7,16 +10,61 @@ from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.comments.models import Comment, FreeComment, RATINGS_REQUIRED, RATINGS_OPTIONAL, IS_PUBLIC
from django.contrib.contenttypes.models import ContentType
-from django.contrib.auth.forms import AuthenticationForm
+from django.contrib.auth import authenticate
from django.http import HttpResponseRedirect
from django.utils.text import normalize_newlines
from django.conf import settings
from django.utils.translation import ungettext, ugettext as _
from django.utils.encoding import smart_unicode
-import base64, datetime
COMMENTS_PER_PAGE = 20
+# TODO: This is a copy of the manipulator-based form that used to live in
+# contrib.auth.forms. It should be replaced with the newforms version that
+# has now been added to contrib.auth.forms when the comments app gets updated
+# for newforms.
+
+class AuthenticationForm(oldforms.Manipulator):
+ """
+ Base class for authenticating users. Extend this to get a form that accepts
+ username/password logins.
+ """
+ def __init__(self, request=None):
+ """
+ If request is passed in, the manipulator will validate that cookies are
+ enabled. Note that the request (a HttpRequest object) must have set a
+ cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before
+ running this validator.
+ """
+ self.request = request
+ self.fields = [
+ oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True,
+ validator_list=[self.isValidUser, self.hasCookiesEnabled]),
+ oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True),
+ ]
+ self.user_cache = None
+
+ def hasCookiesEnabled(self, field_data, all_data):
+ if self.request and not self.request.session.test_cookie_worked():
+ raise validators.ValidationError, _("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in.")
+
+ def isValidUser(self, field_data, all_data):
+ username = field_data
+ password = all_data.get('password', None)
+ self.user_cache = authenticate(username=username, password=password)
+ if self.user_cache is None:
+ raise validators.ValidationError, _("Please enter a correct username and password. Note that both fields are case-sensitive.")
+ elif not self.user_cache.is_active:
+ raise validators.ValidationError, _("This account is inactive.")
+
+ def get_user_id(self):
+ if self.user_cache:
+ return self.user_cache.id
+ return None
+
+ def get_user(self):
+ return self.user_cache
+
class PublicCommentManipulator(AuthenticationForm):
"Manipulator that handles public registered comments"
def __init__(self, user, ratings_required, ratings_range, num_rating_choices):