Zine

open source content publishing system


Changeset 827:0f14ee78dc4e


Ignore:
Timestamp:
12/30/08 22:59:24 (3 years ago)
Author:
dennda
Branch:
default
Children:
830:556536f6f8b1, 840:4be83bf64ddc
Message:

Fix #135 by making empty strings invalid as value for entry titles and group, user and category names.

Location:
zine
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • zine/forms.py

    r810 r827  
    2323from zine.utils.http import redirect_to 
    2424from zine.utils.validators import ValidationError, is_valid_email, \ 
    25      is_valid_url, is_valid_slug, is_netaddr 
     25     is_valid_url, is_valid_slug, is_netaddr, is_not_whitespace_only 
    2626from zine.utils.redirects import register_redirect, change_url_prefix 
    2727 
     
    221221    """ 
    222222    title = forms.TextField(lazy_gettext(u'Title'), max_length=150, 
    223                             required=True) 
     223                            validators=[is_not_whitespace_only()], required=True) 
    224224    text = forms.TextField(lazy_gettext(u'Text'), max_length=65000, 
    225225                           widget=forms.Textarea) 
     
    291291        existing = query.first() 
    292292        if existing is not None: 
    293             raise ValidationError(_('This slug is already in use')) 
     293            raise ValidationError(_('This slug is already in use.')) 
    294294 
    295295    def validate_parser(self, value): 
     
    505505 
    506506    slug = forms.TextField(lazy_gettext(u'Slug'), validators=[is_valid_slug()]) 
    507     name = forms.TextField(lazy_gettext(u'Name'), max_length=50, required=True) 
     507    name = forms.TextField(lazy_gettext(u'Name'), max_length=50, required=True, 
     508                           validators=[is_not_whitespace_only()]) 
    508509    description = forms.TextField(lazy_gettext(u'Description'), 
    509510                                  max_length=5000, widget=forms.Textarea) 
     
    609610 
    610611    groupname = forms.TextField(lazy_gettext(u'Groupname'), max_length=30, 
    611                            required=True) 
     612                                validators=[is_not_whitespace_only()], 
     613                                required=True) 
    612614    privileges = forms.MultiChoiceField(lazy_gettext(u'Privileges'), 
    613615                                        widget=forms.CheckboxGroup) 
     
    706708 
    707709    username = forms.TextField(lazy_gettext(u'Username'), max_length=30, 
     710                               validators=[is_not_whitespace_only()], 
    708711                               required=True) 
    709712    real_name = forms.TextField(lazy_gettext(u'Realname'), max_length=180) 
  • zine/utils/forms.py

    r744 r827  
    974974        validation if the field is empty and not required. 
    975975 
    976         For example a validator like `is_valid_ip` is never alled if the 
     976        For example a validator like `is_valid_ip` is never called if the 
    977977        value is an empty string and the field hasn't raised a validation 
    978978        error when checking if the field is required. 
  • zine/utils/validators.py

    r754 r827  
    156156                raise ValidationError(_(u'URL prefix must not end with a slash.')) 
    157157    return validator 
     158 
     159def is_not_whitespace_only(): 
     160    """Make sure the value does consist of at least one 
     161    non-whitespace character""" 
     162    def validator(form, value): 
     163        if not value.strip(): 
     164            raise ValidationError(_('At least one non-whitespace character ' 
     165                                    'is required.')) 
     166    return validator 
Note: See TracChangeset for help on using the changeset viewer.