Changeset 7979 for django/branches/gis/django/contrib/comments
- Timestamp:
- 07/19/08 08:30:47 (6 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/contrib/comments/admin.py (copied) (copied from django/trunk/django/contrib/comments/admin.py)
- django/branches/gis/django/contrib/comments/models.py (modified) (4 diffs)
- django/branches/gis/django/contrib/comments/views/comments.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7917 to /django/trunk:1-7978
django/branches/gis/django/contrib/comments/models.py
r7044 r7979 67 67 class Comment(models.Model): 68 68 """A comment by a registered user.""" 69 user = models.ForeignKey(User , raw_id_admin=True)69 user = models.ForeignKey(User) 70 70 content_type = models.ForeignKey(ContentType) 71 71 object_id = models.IntegerField(_('object ID')) … … 97 97 ordering = ('-submit_date',) 98 98 99 class Admin:100 fields = (101 (None, {'fields': ('content_type', 'object_id', 'site')}),102 ('Content', {'fields': ('user', 'headline', 'comment')}),103 ('Ratings', {'fields': ('rating1', 'rating2', 'rating3', 'rating4', 'rating5', 'rating6', 'rating7', 'rating8', 'valid_rating')}),104 ('Meta', {'fields': ('is_public', 'is_removed', 'ip_address')}),105 )106 list_display = ('user', 'submit_date', 'content_type', 'get_content_object')107 list_filter = ('submit_date',)108 date_hierarchy = 'submit_date'109 search_fields = ('comment', 'user__username')110 111 99 def __unicode__(self): 112 100 return "%s: %s..." % (self.user.username, self.comment[:100]) … … 189 177 ordering = ('-submit_date',) 190 178 191 class Admin:192 fields = (193 (None, {'fields': ('content_type', 'object_id', 'site')}),194 ('Content', {'fields': ('person_name', 'comment')}),195 ('Meta', {'fields': ('submit_date', 'is_public', 'ip_address', 'approved')}),196 )197 list_display = ('person_name', 'submit_date', 'content_type', 'get_content_object')198 list_filter = ('submit_date',)199 date_hierarchy = 'submit_date'200 search_fields = ('comment', 'person_name')201 202 179 def __unicode__(self): 203 180 return "%s: %s..." % (self.person_name, self.comment[:100]) … … 307 284 def __unicode__(self): 308 285 return _("Moderator deletion by %r") % self.user 286 django/branches/gis/django/contrib/comments/views/comments.py
r6394 r7979 1 import base64 2 import datetime 3 1 4 from django.core import validators 2 5 from django import oldforms … … 8 11 from django.contrib.comments.models import Comment, FreeComment, RATINGS_REQUIRED, RATINGS_OPTIONAL, IS_PUBLIC 9 12 from django.contrib.contenttypes.models import ContentType 10 from django.contrib.auth .forms import AuthenticationForm13 from django.contrib.auth import authenticate 11 14 from django.http import HttpResponseRedirect 12 15 from django.utils.text import normalize_newlines … … 14 17 from django.utils.translation import ungettext, ugettext as _ 15 18 from django.utils.encoding import smart_unicode 16 import base64, datetime17 19 18 20 COMMENTS_PER_PAGE = 20 21 22 # TODO: This is a copy of the manipulator-based form that used to live in 23 # contrib.auth.forms. It should be replaced with the newforms version that 24 # has now been added to contrib.auth.forms when the comments app gets updated 25 # for newforms. 26 27 class AuthenticationForm(oldforms.Manipulator): 28 """ 29 Base class for authenticating users. Extend this to get a form that accepts 30 username/password logins. 31 """ 32 def __init__(self, request=None): 33 """ 34 If request is passed in, the manipulator will validate that cookies are 35 enabled. Note that the request (a HttpRequest object) must have set a 36 cookie with the key TEST_COOKIE_NAME and value TEST_COOKIE_VALUE before 37 running this validator. 38 """ 39 self.request = request 40 self.fields = [ 41 oldforms.TextField(field_name="username", length=15, max_length=30, is_required=True, 42 validator_list=[self.isValidUser, self.hasCookiesEnabled]), 43 oldforms.PasswordField(field_name="password", length=15, max_length=30, is_required=True), 44 ] 45 self.user_cache = None 46 47 def hasCookiesEnabled(self, field_data, all_data): 48 if self.request and not self.request.session.test_cookie_worked(): 49 raise validators.ValidationError, _("Your Web browser doesn't appear to have cookies enabled. Cookies are required for logging in.") 50 51 def isValidUser(self, field_data, all_data): 52 username = field_data 53 password = all_data.get('password', None) 54 self.user_cache = authenticate(username=username, password=password) 55 if self.user_cache is None: 56 raise validators.ValidationError, _("Please enter a correct username and password. Note that both fields are case-sensitive.") 57 elif not self.user_cache.is_active: 58 raise validators.ValidationError, _("This account is inactive.") 59 60 def get_user_id(self): 61 if self.user_cache: 62 return self.user_cache.id 63 return None 64 65 def get_user(self): 66 return self.user_cache 19 67 20 68 class PublicCommentManipulator(AuthenticationForm):
