Re: form fields slicing

2009-11-23 Thread gentlestone
"it's cheap enough to make such a list (preferably in your
view function)"

thx, it's easy and simple - good idea

On 23. Nov, 16:44 h., Bill Freeman  wrote:
> Possibly the form class is not written to support slicing.  Supporting
> itteration only
> requires methods for __iter__() and next().  Slicing, like indexing
> requires implementation
> of __getitem__(), and for slicing to work, this method must check for
> receiving a 'slice'
> object as an index.  Since most folks probably can't think of a good
> use for slicing here,
> the maintainers probably just haven't implemented slicing.
>
> Since a list of fields is just a list of references, and doesn't
> involve actually copying
> the fields, it's cheap enough to make such a list (preferably in your
> view function),
> pass that, and slice it.  (lists do, of course, implement slicing.)
> Something at least
> that complicated would need to be going on inside the code that would 
> implement
> slicing on the form anyway, so this shouldn't have a negative
> performance impact.
>
> Bill
>
> On Mon, Nov 23, 2009 at 10:16 AM, gentlestone  wrote:
> > the same result :(
>
> > On 23. Nov, 13:47 h., Doug Blank  wrote:
> >> On Mon, Nov 23, 2009 at 7:16 AM, gentlestone  
> >> wrote:
> >> > why this piece of code doesn't work?
>
> >> > {% for field in form|slice:":2" %}
>
> >> > the result is iterating over all fields, not just the first two fields
>
> >> Perhaps break this up into two parts?
>
> >> {% with form|slice:":2" as formslice %}
> >>     (% for field in formslice %}
>
> >> -Doug
>
> >> > --
>
> >> > You received this message because you are subscribed to the Google 
> >> > Groups "Django users" group.
> >> > To post to this group, send email to django-us...@googlegroups.com.
> >> > To unsubscribe from this group, send email to 
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group 
> >> > athttp://groups.google.com/group/django-users?hl=.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: form fields slicing

2009-11-23 Thread Bill Freeman
Possibly the form class is not written to support slicing.  Supporting
itteration only
requires methods for __iter__() and next().  Slicing, like indexing
requires implementation
of __getitem__(), and for slicing to work, this method must check for
receiving a 'slice'
object as an index.  Since most folks probably can't think of a good
use for slicing here,
the maintainers probably just haven't implemented slicing.

Since a list of fields is just a list of references, and doesn't
involve actually copying
the fields, it's cheap enough to make such a list (preferably in your
view function),
pass that, and slice it.  (lists do, of course, implement slicing.)
Something at least
that complicated would need to be going on inside the code that would implement
slicing on the form anyway, so this shouldn't have a negative
performance impact.

Bill

On Mon, Nov 23, 2009 at 10:16 AM, gentlestone  wrote:
> the same result :(
>
> On 23. Nov, 13:47 h., Doug Blank  wrote:
>> On Mon, Nov 23, 2009 at 7:16 AM, gentlestone  wrote:
>> > why this piece of code doesn't work?
>>
>> > {% for field in form|slice:":2" %}
>>
>> > the result is iterating over all fields, not just the first two fields
>>
>> Perhaps break this up into two parts?
>>
>> {% with form|slice:":2" as formslice %}
>>     (% for field in formslice %}
>>
>> -Doug
>>
>> > --
>>
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: form fields slicing

2009-11-23 Thread gentlestone
the same result :(

On 23. Nov, 13:47 h., Doug Blank  wrote:
> On Mon, Nov 23, 2009 at 7:16 AM, gentlestone  wrote:
> > why this piece of code doesn't work?
>
> > {% for field in form|slice:":2" %}
>
> > the result is iterating over all fields, not just the first two fields
>
> Perhaps break this up into two parts?
>
> {% with form|slice:":2" as formslice %}
>     (% for field in formslice %}
>
> -Doug
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




Re: form fields slicing

2009-11-23 Thread Doug Blank
On Mon, Nov 23, 2009 at 7:16 AM, gentlestone  wrote:
> why this piece of code doesn't work?
>
> {% for field in form|slice:":2" %}
>
> the result is iterating over all fields, not just the first two fields

Perhaps break this up into two parts?

{% with form|slice:":2" as formslice %}
(% for field in formslice %}

-Doug

> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.




form fields slicing

2009-11-23 Thread gentlestone
why this piece of code doesn't work?

{% for field in form|slice:":2" %}

the result is iterating over all fields, not just the first two fields

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=.