Re: Can please someone explain this code from the docs?

2014-03-15 Thread Camilo Torres
On Friday, March 14, 2014 5:33:37 PM UTC-4:30, Voyager wrote:
>
> On 03/14/2014 11:49 PM, Shawn Milochik wrote: 
> > That's just the syntax for calling a method on the base class. 
> > 
> > 1. MultiEmailField is a subclass of forms.Field. 
> > 2. forms.Field has a method named validate. 
> > 3. MultiEmailField also has a method named validate, so it overrides the 
> > one on forms.Field. 
> > 
>
> Thank you. It seemed odd that the calling class name is used to call the 
> parent but the more I think about it the more it makes sense. super in 
> it self is a function that returns the parent of a given class. So it is 
> logical to include class in arguments list. 
>
Hello,

This has nothing to do with Django; *super() is a Python built-in* to 
manage calling/accessing attributes of the super class taking in account 
that Python supports multiple inheritance.

Regards,
Camilo

-- 
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/8b1ff3d5-f805-4c13-81a1-1ff80f8f7ba0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can please someone explain this code from the docs?

2014-03-14 Thread voger

On 03/14/2014 11:49 PM, Shawn Milochik wrote:

That's just the syntax for calling a method on the base class.

1. MultiEmailField is a subclass of forms.Field.
2. forms.Field has a method named validate.
3. MultiEmailField also has a method named validate, so it overrides the
one on forms.Field.



Thank you. It seemed odd that the calling class name is used to call the 
parent but the more I think about it the more it makes sense. super in 
it self is a function that returns the parent of a given class. So it is 
logical to include class in arguments list.


--
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/53237CB9.4080105%40yahoo.gr.
For more options, visit https://groups.google.com/d/optout.


Re: Can please someone explain this code from the docs?

2014-03-14 Thread Shawn Milochik
That's just the syntax for calling a method on the base class.

1. MultiEmailField is a subclass of forms.Field.
2. forms.Field has a method named validate.
3. MultiEmailField also has a method named validate, so it overrides the
one on forms.Field.

So, for MultiEmailField to call its parent's validate() method, it has to
use super. That's how the subclass can use the parent's code, and add some
of its own.

-- 
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/CAOzwKwGWsc5%2B1BdpZK%3DJCyu88a%3DLk9gZFQg7yLR-6A6n0_k5SA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Can please someone explain this code from the docs?

2014-03-14 Thread voger
Hi, I was reading the form validation section here 
https://docs.djangoproject.com/en/dev/ref/forms/validation/ and the very 
first example is this code


from django import forms
from django.core.validators import validate_email

class MultiEmailField(forms.Field):
def to_python(self, value):
"Normalize data to a list of strings."

# Return an empty list if no input was given.
if not value:
return []
return value.split(',')

def validate(self, value):
"Check if value consists only of valid emails."

# Use the parent's handling of required fields, etc.
super(MultiEmailField, self).validate(value)  #<---What is this?

for email in value:
validate_email(email)

so the validate function calls super(MultiEmailField, 
self).validate(value) so essentially calls itself? Why? And how is this 
not ending in infinite recursion?


--
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/53237879.8090604%40yahoo.gr.
For more options, visit https://groups.google.com/d/optout.