Re: Tutorial missing import: Http404

2015-04-10 Thread John Matthew Ian Davis

On Friday, April 10, 2015 at 3:33:36 PM UTC-7, Ramiro Morales wrote:
>
> On Fri, Apr 10, 2015 at 6:31 PM, John Matthew Ian Davis <
> johnmatth...@gmail.com > wrote:
>
>> obviously one needs to change:
>>
>> from django.http import HttpResponse, 
>>
>> to
>>
>> from django.http import HttpResponse, Http404
>>
>
> If you are talking about part 3 of the tutorial then it in fact contains 
> an import of Http404 and it's intrdroduced together with the first piece of 
> code that uses it.
>
> It's right in the views.py snippet located under the "Raising a 404 error" 
> section title: 
> https://docs.djangoproject.com/en/1.8/intro/tutorial03/#raising-a-404-error
>
> Regards,
>
> -- 
> Ramiro Morales
> @ramiromorales
>

 You (and the page) are completely correct, and I missed the relevant line, 
reading through, a half dozen times in a row. Apologies. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c18b8de4-0895-49e4-86a0-a44dc3be7ee1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom password validation

2015-04-10 Thread Helton Alves
hey man, how are you ?

I don't know if I understand very well, but you can try make a custom user
and in forms file you can do the validation that you need. :D

if that's right, you can follow this example:
http://www.lasolution.be/blog/creating-custom-user-model-django-16-part-1.html

I hope to have helped you!

Em sex, 10 de abr de 2015 às 19:39, Larry Martell 
escreveu:

> On Fri, Apr 10, 2015 at 3:14 PM, Larry Martell 
> wrote:
> > I am trying to add custom password validation to the create user and
> > change password admin forms. I did not see anything in the django docs
> > about how to do this. From what I read on stackoverflow and other
> > sites it seems I have to write a validator and then someone hook it
> > into the add and change forms.
> >
> > Here's what I have now in my apps admin.py:
> >
> > def validate_password_strength(value):
> > """Validates that a password is as least 10 characters long and has
> at least
> > 2 digits and 1 Upper case letter.
> > """
> > min_length = 10
> >
> > if len(value) < min_length:
> > raise ValidationError(_('Password must be at least {0}
> characters '
> > 'long.').format(min_length))
> >
> > # check for 2 digits
> > if sum(c.isdigit() for c in value) < 2:
> > raise ValidationError(_('Password must container at least 2
> digits.'))
> >
> > # check for uppercase letter
> > if not any(c.isupper() for c in value):
> > raise ValidationError(_('Password must container at least 1
> > uppercase letter.'))
> >
> > class MySetPasswordForm(SetPasswordForm):
> > def __init__(self, *args, **kwargs):
> > super(MySetPasswordForm, self).__init__(*args, **kwargs)
> >
>  self.fields['password1'].validators.append(validate_password_strength)
> >
> > But what I can't figure out is how do I get MySetPasswordForm to be
> > used. Can anyone help me with this. If i am way off base, can someone
> > point me in the right direction. Thanks!
>
> I've tried a few different things. First I did this:
>
> class UserAdmin(UserAdmin):
> form = MySetPasswordForm
>
> # Re-register UserAdmin
> admin.site.unregister(User)
> admin.site.register(User, UserAdmin)
>
> And I got this error:
>
> : (admin.E016)
> The value of 'form' must inherit from 'BaseModelForm'.
>
> So then I changed MySetPasswordForm to inherit from BaseModelForm and
> then I got this error:
>
> __init__() missing 1 required positional argument: 'user'
>
> So then I added the user param so now MySetPasswordForm looked like this:
>
> class MySetPasswordForm(BaseModelForm):
> def __init__(self, user, *args, **kwargs):
> super(MySetPasswordForm, self).__init__(user, *args, **kwargs)
>
> self.fields['password1'].validators.append(validate_password_strength)
>
> But I still got the same error as before.
>
> I can't believe it's this hard to add a password validator. It must be
> a very common need, so clearly I must be missing something simple. Can
> anyone please provide some assistance here.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACwCsY7e%3DkTtvs71PdDG66h1X%3DisWGCgjs7LdpXFtG-n3hRjDQ%40mail.gmail.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABcoSmCTX8oOKJ5wsJXaS3b%3DfgfTPwKo6n1e68cVFfdiL-Zi6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Custom password validation

2015-04-10 Thread Larry Martell
On Fri, Apr 10, 2015 at 3:14 PM, Larry Martell  wrote:
> I am trying to add custom password validation to the create user and
> change password admin forms. I did not see anything in the django docs
> about how to do this. From what I read on stackoverflow and other
> sites it seems I have to write a validator and then someone hook it
> into the add and change forms.
>
> Here's what I have now in my apps admin.py:
>
> def validate_password_strength(value):
> """Validates that a password is as least 10 characters long and has at 
> least
> 2 digits and 1 Upper case letter.
> """
> min_length = 10
>
> if len(value) < min_length:
> raise ValidationError(_('Password must be at least {0} characters '
> 'long.').format(min_length))
>
> # check for 2 digits
> if sum(c.isdigit() for c in value) < 2:
> raise ValidationError(_('Password must container at least 2 digits.'))
>
> # check for uppercase letter
> if not any(c.isupper() for c in value):
> raise ValidationError(_('Password must container at least 1
> uppercase letter.'))
>
> class MySetPasswordForm(SetPasswordForm):
> def __init__(self, *args, **kwargs):
> super(MySetPasswordForm, self).__init__(*args, **kwargs)
> self.fields['password1'].validators.append(validate_password_strength)
>
> But what I can't figure out is how do I get MySetPasswordForm to be
> used. Can anyone help me with this. If i am way off base, can someone
> point me in the right direction. Thanks!

I've tried a few different things. First I did this:

class UserAdmin(UserAdmin):
form = MySetPasswordForm

# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

And I got this error:

: (admin.E016)
The value of 'form' must inherit from 'BaseModelForm'.

So then I changed MySetPasswordForm to inherit from BaseModelForm and
then I got this error:

__init__() missing 1 required positional argument: 'user'

So then I added the user param so now MySetPasswordForm looked like this:

class MySetPasswordForm(BaseModelForm):
def __init__(self, user, *args, **kwargs):
super(MySetPasswordForm, self).__init__(user, *args, **kwargs)
self.fields['password1'].validators.append(validate_password_strength)

But I still got the same error as before.

I can't believe it's this hard to add a password validator. It must be
a very common need, so clearly I must be missing something simple. Can
anyone please provide some assistance here.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY7e%3DkTtvs71PdDG66h1X%3DisWGCgjs7LdpXFtG-n3hRjDQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Tutorial missing import: Http404

2015-04-10 Thread Ramiro Morales
On Fri, Apr 10, 2015 at 6:31 PM, John Matthew Ian Davis <
johnmatthewianda...@gmail.com> wrote:

> obviously one needs to change:
>
> from django.http import HttpResponse,
>
> to
>
> from django.http import HttpResponse, Http404
>

If you are talking about part 3 of the tutorial then it in fact contains an
import of Http404 and it's intrdroduced together with the first piece of
code that uses it.

It's right in the views.py snippet located under the "Raising a 404 error"
section title:
https://docs.djangoproject.com/en/1.8/intro/tutorial03/#raising-a-404-error

Regards,

-- 
Ramiro Morales
@ramiromorales

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAO7PdF-p6F_6reyXKni0kuBeAyWDFia-%2BwZkG9HzLYLQfGYq5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Tutorial missing import: Http404

2015-04-10 Thread John Matthew Ian Davis
obviously one needs to change:

from django.http import HttpResponse, 

to

from django.http import HttpResponse, Http404

but that's a speed-bump that should not be in the tutorial.

NameError at /polls/34/ 

global name 'Http404' is not defined

 Request Method: GET  Request URL: http://localhost:8000/polls/34/  Django 
Version: 1.8  Exception Type: NameError  Exception Value: 

global name 'Http404' is not defined

 Exception Location: 
/home/john/Documents/code/python/django/djangostart/polls/views.py 
in detail, line 19  Python Executable: /usr/bin/python  Python Version: 
2.7.6  Python Path: 

['/home/john/Documents/code/python/django/djangostart',
 '/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

 Server time: Fri, 10 Apr 2015 21:30:24 +

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f8405d8-8099-4182-8010-0701abbe44f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.