Django

Code

Ticket #2228: better_comments2.diff

File better_comments2.diff, 3.9 kB (added by Tyson Tate <tyson@fallingbullets.com>, 3 years ago)

Changed from TextField? to proper fields and, by consequence, adds proper error checking

  • django/contrib/comments/models.py

    old new  
    166166    object_id = models.IntegerField(_('object ID')) 
    167167    comment = models.TextField(_('comment'), maxlength=3000) 
    168168    person_name = models.CharField(_("person's name"), maxlength=50) 
     169    person_email = models.EmailField(_("person's e-mail address"), blank=True) 
     170    person_url = models.URLField(_("person's url"), blank=True) 
    169171    submit_date = models.DateTimeField(_('date/time submitted'), auto_now_add=True) 
    170172    is_public = models.BooleanField(_('is public')) 
    171173    ip_address = models.IPAddressField(_('ip address')) 
     
    179181    class Admin: 
    180182        fields = ( 
    181183            (None, {'fields': ('content_type', 'object_id', 'site')}), 
    182             ('Content', {'fields': ('person_name', 'comment')}), 
     184            ('Content', {'fields': ('person_name', 'person_email', 'person_url', 'comment')}), 
    183185            ('Meta', {'fields': ('submit_date', 'is_public', 'ip_address', 'approved')}), 
    184186        ) 
    185187        list_display = ('person_name', 'submit_date', 'content_type', 'get_content_object') 
  • django/contrib/comments/views/comments.py

    old new  
    124124        self.fields = ( 
    125125            forms.TextField(field_name="person_name", maxlength=50, is_required=True, 
    126126                validator_list=[self.hasNoProfanities]), 
     127            forms.EmailField(field_name="person_email", maxlength=70), 
     128            forms.URLField(field_name="person_url", maxlength=100), 
    127129            forms.LargeTextField(field_name="comment", maxlength=3000, is_required=True, 
    128130                validator_list=[self.hasNoProfanities]), 
    129131        ) 
     
    137139        "Helper function" 
    138140        return FreeComment(None, new_data["content_type_id"], 
    139141            new_data["object_id"], new_data["comment"].strip(), 
    140             new_data["person_name"].strip(), datetime.datetime.now(), new_data["is_public"], 
     142            new_data["person_name"].strip(), 
     143            new_data["person_email"].strip(), 
     144            new_data["person_url"].strip(), 
     145            datetime.datetime.now(), 
     146            new_data["is_public"], 
    141147            new_data["ip_address"], False, settings.SITE_ID) 
    142148 
    143149    def save(self, new_data): 
     
    148154        # the comment was posted successfully. 
    149155        for old_comment in FreeComment.objects.filter(content_type__id__exact=new_data["content_type_id"], 
    150156            object_id__exact=new_data["object_id"], person_name__exact=new_data["person_name"], 
     157            person_email__exact=new_data["person_email"], person_url__exact=new_data["person_url"], 
    151158            submit_date__year=today.year, submit_date__month=today.month, 
    152159            submit_date__day=today.day): 
    153160            if old_comment.comment == c.comment: 
  • django/contrib/comments/templates/comments/freeform.html

    old new  
    22{% if display_form %} 
    33<form action="/comments/postfree/" method="post"> 
    44<p>{% trans "Your name:" %} <input type="text" id="id_person_name" name="person_name" /></p> 
     5<p>{% trans "E-mail Address (optional):" %} <input type="text" id="id_person_email" name="person_email" /></p> 
     6<p>{% trans "URL (optional):" %} <input type="text" id="id_person_url" name="person_url" /></p> 
    57<p>{% trans "Comment:" %}<br /><textarea name="comment" id="id_comment" rows="10" cols="60"></textarea></p> 
    68<input type="hidden" name="options" value="{{ options }}" /> 
    79<input type="hidden" name="target" value="{{ target }}" />