Django

Code

Show
Ignore:
Timestamp:
07/19/08 08:30:47 (6 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7921,7926-7928,7938-7941,7945-7947,7949-7950,7952,7955-7956,7961,7964-7968,7970-7978 via svnmerge from trunk.

This includes the newforms-admin branch, and thus is backwards-incompatible. The geographic admin is _not_ in this changeset, and is forthcoming.

Files:

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  
    6767class Comment(models.Model): 
    6868    """A comment by a registered user.""" 
    69     user = models.ForeignKey(User, raw_id_admin=True
     69    user = models.ForeignKey(User
    7070    content_type = models.ForeignKey(ContentType) 
    7171    object_id = models.IntegerField(_('object ID')) 
     
    9797        ordering = ('-submit_date',) 
    9898 
    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  
    11199    def __unicode__(self): 
    112100        return "%s: %s..." % (self.user.username, self.comment[:100]) 
     
    189177        ordering = ('-submit_date',) 
    190178 
    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  
    202179    def __unicode__(self): 
    203180        return "%s: %s..." % (self.person_name, self.comment[:100]) 
     
    307284    def __unicode__(self): 
    308285        return _("Moderator deletion by %r") % self.user 
     286         
  • django/branches/gis/django/contrib/comments/views/comments.py

    r6394 r7979  
     1import base64 
     2import datetime 
     3 
    14from django.core import validators 
    25from django import oldforms 
     
    811from django.contrib.comments.models import Comment, FreeComment, RATINGS_REQUIRED, RATINGS_OPTIONAL, IS_PUBLIC 
    912from django.contrib.contenttypes.models import ContentType 
    10 from django.contrib.auth.forms import AuthenticationForm 
     13from django.contrib.auth import authenticate 
    1114from django.http import HttpResponseRedirect 
    1215from django.utils.text import normalize_newlines 
     
    1417from django.utils.translation import ungettext, ugettext as _ 
    1518from django.utils.encoding import smart_unicode 
    16 import base64, datetime 
    1719 
    1820COMMENTS_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 
     27class 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 
    1967 
    2068class PublicCommentManipulator(AuthenticationForm):