Example #1
0
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(u"Usernames can only contain letters, numbers and underscores.")
     try:
         user = User.objects.get(username__exact=self.cleaned_data["username"])
     except User.DoesNotExist:
         return self.cleaned_data["username"]
     raise forms.ValidationError(u"This username is already taken. Please choose another.")
Example #2
0
 def clean_username(self):
     if not alnum_re.search(self.cleaned_data["username"]):
         raise forms.ValidationError(
             u"Usernames can only contain letters, numbers and underscores."
         )
     try:
         user = User.objects.get(
             username__exact=self.cleaned_data["username"])
     except User.DoesNotExist:
         return self.cleaned_data["username"]
     raise forms.ValidationError(
         u"This username is already taken. Please choose another.")
Example #3
0
 def clean_username(self):
     """
     Validates that the username is alphanumeric and is not already
     in use.
     
     """
     if not alnum_re.search(self.cleaned_data['username']):
         raise forms.ValidationError(_(u'Usernames can only contain letters, numbers and underscores'))
     try:
         user = User.objects.get(username__exact=self.cleaned_data['username'])
     except User.DoesNotExist:
         return self.cleaned_data['username']
     raise forms.ValidationError(_(u'This username is already taken. Please choose another.'))
Example #4
0
 def clean_username(self):
     """ Validate that the username is alphanumeric and is not already in use """
     if len(self.clean_data['username']) < 5:
         raise forms.ValidationError(str(_('The user name must be at least 5 characters long.')))
     if len(self.clean_data['username']) > 30:
         raise forms.ValidationError(str(_('The user name must be at most 30 characters long.')))
     if not alnum_re.search(self.clean_data['username']):
         raise forms.ValidationError(str(_('The user name can only contain letters, numbers and underscores.')))
     try:
         user = User.objects.get(username__exact = self.clean_data['username'])
     except User.DoesNotExist:
         return self.clean_data['username']
     raise forms.ValidationError(str(_('This user name is already taken. Please choose another.')))
Example #5
0
def list(request, contact='', manager='inbox'):
    "Lists messages for inbox, outbox and drafts"
    
    mgr = getattr(request.user, manager)
    mgr.filter_username(contact)
    qs = mgr.all().select_related()
    
    if request.POST:
        # Handle message deletion
        if request.POST.has_key('delete'):
            delete_time = datetime.now()
            messages = mgr.in_bulk(request.POST.getlist('checkbox')).values()
            for message in messages:
                message.set_delete_flag(request.user, delete_time)
                
            count_deleted = len(messages)
            if count_deleted:
                view = '%s/list%s%s/' % ( manager, contact and '/' or '', contact )
                timestamp = mktime(delete_time.timetuple()) + delete_time.microsecond / 1e6
                notification(request,
                       ungettext('Message deleted.',
                                   '%(count)d messages deleted.', count_deleted) % {'count': count_deleted},
                       template = 'notice_link',
                       link_url = reverse('pm_restore', args=['%f' % timestamp, view]),
                       link_text = _('undo'),
                       )
                return HttpResponseRedirect(mgr.get_redirect_list(message.id, contact))
            else:
                notification(request,_('No messages deleted.'))
        
        # Handle contact filter
        if alnum_re.search(request.POST.get('contact', '')):
            return HttpResponseRedirect(reverse('pm_%s_contact' % manager, args=[request.POST['contact']]))
    
    return object_list(request=request,
                       queryset=qs,
                       template_name='pm/list_%s.html' % manager,
                       allow_empty=True,
                       paginate_by=PAGINATE_BY,
                       extra_context={'contact': contact}
                       )