Use attrgetter if all other ways did not worked (in getitem) #9

Closed
wants to merge 1 commit into
from

Conversation

2 participants
@almet

almet commented Dec 20, 2010

This allow to support dotted attributes. You can ask for "obj.attribute", and this will work.
It is then possible to groupby on the sub attributes of the items, for instance.

Hope this helps.

Use attrgetter if all other ways did not worked. This allows to speci…
…fy dot

separated attributes while using the groupby builtin filter.
@mitsuhiko

This comment has been minimized.

Show comment Hide comment
@mitsuhiko

mitsuhiko Dec 20, 2010

Member

What exactly is this supposed to fix? Attributes are already looked up and for chaining attribute lookups you must call this function for each dot. Otherwise sub attributes could not be items.

Member

mitsuhiko commented Dec 20, 2010

What exactly is this supposed to fix? Attributes are already looked up and for chaining attribute lookups you must call this function for each dot. Otherwise sub attributes could not be items.

@almet

This comment has been minimized.

Show comment Hide comment
@almet

almet Dec 20, 2010

This is supposed to allow the groupby to group by more precisely.
For instance, if I have articles that I want to group by year, I need to access item.date.year in the groupby filter.

Maybe that's not the way to go, and if not, please tell me what's the right way :)

When you're saying this function should be called for each dot, maybe can I split on . then and call this function recursively ?

Please let me know, this is a bit obscure by now.

almet commented Dec 20, 2010

This is supposed to allow the groupby to group by more precisely.
For instance, if I have articles that I want to group by year, I need to access item.date.year in the groupby filter.

Maybe that's not the way to go, and if not, please tell me what's the right way :)

When you're saying this function should be called for each dot, maybe can I split on . then and call this function recursively ?

Please let me know, this is a bit obscure by now.

@mitsuhiko

This comment has been minimized.

Show comment Hide comment
@mitsuhiko

mitsuhiko Dec 20, 2010

Member

Can you open an issue for groupby not supporting more than one dot? That should be fixed there, not in the getattr function on the environment. Reasoning: this has specific requirements and must not change in a backwards incompatible way because people subclass this. Jinja2 already has the sandbox which also subclasses this.

Member

mitsuhiko commented Dec 20, 2010

Can you open an issue for groupby not supporting more than one dot? That should be fixed there, not in the getattr function on the environment. Reasoning: this has specific requirements and must not change in a backwards incompatible way because people subclass this. Jinja2 already has the sandbox which also subclasses this.

@almet

This comment has been minimized.

Show comment Hide comment
@almet

almet Dec 20, 2010

okay, sure, thanks.

almet commented Dec 20, 2010

okay, sure, thanks.

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment