[web2py] Re: Proposal to add 'extend' to DIV

2016-10-11 Thread Massimo Di Pierro
I see the value in this. It calls _fixup after concatenating. Can you 
submit a PR?

On Wednesday, 5 October 2016 14:51:59 UTC-5, Joe Barnhart wrote:
>
> One Python helper I find enormously useful is "extend()" as applied to 
> list objects.  Extend differs from append in that it adds the items of the 
> list provided at the same level as the current list items, thereby 
> "extending" the list. 
>
> An example:
>
> body = DIV("this","is","the","body")
>
> Result: a DIV with four elements in it.
>
> body.append(["and","additional","elements"])
>
> Result:  Not what you wanted!  It appends a list to the original DIV 
> making a mess.
>
> body.extend(["and","additional","elements"])
>
> This is what you wanted:
>
> DIV("this","is","the","body","and","additional","elements")
>
> I've been monkey-patching "extend" into DIV quite awhile now and thought 
> you may want to consider adding it to the DIV helper.  Here is my 
> monkey-patch:
>
> def extend(self,coll):
> self._setnode(coll)
> ret = self.components.extend(coll)
> self._fixup()
> return ret
> DIV.extend = extend
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Proposal to add 'extend' to DIV

2016-10-06 Thread Anthony
To clarify, web2py HTML helpers act like lists with respect to their 
components (in fact, div.components *is* a list). The helpers already have 
a .append method to match the list.append method, so I suppose it makes 
sense for it to have a matching .extend method as well.

Note, you can do something like:

body = DIV("this", "is", "the", "body")
body.components.extend(["and", "additional", "elements"])

The above will work fine in many cases, though it won't call the ._setnode 
or ._fixup methods (which may not matter, depending on which helper you are 
using, what you are adding to it, and what you plan to do with it).

Anthony


On Wednesday, October 5, 2016 at 8:54:15 PM UTC-4, Joe Barnhart wrote:
>
> Yep.  That is essentially what "extend" does.  It's a standard method in 
> the Python list class.  Since DIV has a lot of "list" behavior I think it 
> would be nice to "extend" it to have extend() as well!
>
> -- Joe
>
>
> On Wednesday, October 5, 2016 at 3:19:52 PM UTC-7, Dave S wrote:
>>
>>
>>
>> On Wednesday, October 5, 2016 at 12:51:59 PM UTC-7, Joe Barnhart wrote:
>>>
>>> One Python helper I find enormously useful is "extend()" as applied to 
>>> list objects.  Extend differs from append in that it adds the items of the 
>>> list provided at the same level as the current list items, thereby 
>>> "extending" the list. 
>>>
>>
>>
>> I'll try paraphrasing to see if I understand you and the examples:  given 
>> 2 lists, [a0, a1, .., an] and [b0, b1, ..., bn], you want the elements of b 
>> to be concantenated to the a list, rather than putting a single item 
>> consistenting of the b list at the end of the a list.
>>
>> Roughly
>>
>> for item in b:
>>   a.append(item)
>>
>> Did I get it?
>>  
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Proposal to add 'extend' to DIV

2016-10-05 Thread Joe Barnhart
Yep.  That is essentially what "extend" does.  It's a standard method in 
the Python list class.  Since DIV has a lot of "list" behavior I think it 
would be nice to "extend" it to have extend() as well!

-- Joe


On Wednesday, October 5, 2016 at 3:19:52 PM UTC-7, Dave S wrote:
>
>
>
> On Wednesday, October 5, 2016 at 12:51:59 PM UTC-7, Joe Barnhart wrote:
>>
>> One Python helper I find enormously useful is "extend()" as applied to 
>> list objects.  Extend differs from append in that it adds the items of the 
>> list provided at the same level as the current list items, thereby 
>> "extending" the list. 
>>
>
>
> I'll try paraphrasing to see if I understand you and the examples:  given 
> 2 lists, [a0, a1, .., an] and [b0, b1, ..., bn], you want the elements of b 
> to be concantenated to the a list, rather than putting a single item 
> consistenting of the b list at the end of the a list.
>
> Roughly
>
> for item in b:
>   a.append(item)
>
> Did I get it?
>  
>
>>
>> An example:
>>
>> body = DIV("this","is","the","body")
>>
>> Result: a DIV with four elements in it.
>>
>> body.append(["and","additional","elements"])
>>
>> Result:  Not what you wanted!  It appends a list to the original DIV 
>> making a mess.
>>
>> body.extend(["and","additional","elements"])
>>
>> This is what you wanted:
>>
>> DIV("this","is","the","body","and","additional","elements")
>>
>> I've been monkey-patching "extend" into DIV quite awhile now and thought 
>> you may want to consider adding it to the DIV helper.  Here is my 
>> monkey-patch:
>>
>> def extend(self,coll):
>> self._setnode(coll)
>> ret = self.components.extend(coll)
>> self._fixup()
>> return ret
>> DIV.extend = extend
>>
>>
>
> /dps
>  
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: Proposal to add 'extend' to DIV

2016-10-05 Thread Dave S


On Wednesday, October 5, 2016 at 12:51:59 PM UTC-7, Joe Barnhart wrote:
>
> One Python helper I find enormously useful is "extend()" as applied to 
> list objects.  Extend differs from append in that it adds the items of the 
> list provided at the same level as the current list items, thereby 
> "extending" the list. 
>


I'll try paraphrasing to see if I understand you and the examples:  given 2 
lists, [a0, a1, .., an] and [b0, b1, ..., bn], you want the elements of b 
to be concantenated to the a list, rather than putting a single item 
consistenting of the b list at the end of the a list.

Roughly

for item in b:
  a.append(item)

Did I get it?
 

>
> An example:
>
> body = DIV("this","is","the","body")
>
> Result: a DIV with four elements in it.
>
> body.append(["and","additional","elements"])
>
> Result:  Not what you wanted!  It appends a list to the original DIV 
> making a mess.
>
> body.extend(["and","additional","elements"])
>
> This is what you wanted:
>
> DIV("this","is","the","body","and","additional","elements")
>
> I've been monkey-patching "extend" into DIV quite awhile now and thought 
> you may want to consider adding it to the DIV helper.  Here is my 
> monkey-patch:
>
> def extend(self,coll):
> self._setnode(coll)
> ret = self.components.extend(coll)
> self._fixup()
> return ret
> DIV.extend = extend
>
>

/dps
 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.