[Python-Dev] Enum Eccentricities

Guido van Rossum guido at python.org
Mon Sep 23 19:53:34 CEST 2013


I am quickly losing interest in this -- I was only jumping in because I
feared there was support for making Color.red.blue "work". I don't think I
hve to worry about that any more -- what's best for Django templates is up
to the template author.


On Mon, Sep 23, 2013 at 10:46 AM, Stephen J. Turnbull <stephen at xemacs.org>wrote:

> Guido van Rossum writes:
>  > On Mon, Sep 23, 2013 at 8:17 AM, Zero Piraeus <z at etiol.net> wrote:
>  >> On Mon, Sep 23, 2013 at 09:45:46AM -0400, Chris Lambacher wrote:
>
>  >>> [...] An example of how this will be used in practice is:>
>  >>>     {% if object.state == object.state.completed %}
>  >>>       some html
>  >>>     {% endif %}
>
> [Zero Piraeus suggests instead:]
>
>  >>     {% if object.state == State.completed %}
>  >>       some html
>  >>     {% endif %}
>  >>
>  >> That's quite intelligible, and doesn't require anyone to know that
>  >> an Enum member's siblings can, in your proposal, be accessed directly
>  >> via dot notation (an unintuitive state of affairs, to me at least).
>
>  > Right. The OP is just concerned that (because these are Django
>  > templates) he will have to pass in the 'State' class as a separate
>  > template parameter for this to work.
>
> Given your earlier description of what makes sense for class
> attributes, an alternative solution might be to put State-valued class
> attributes (constants) on DjangoObject (the object's class), like
> DjangoObject.completed_state = State.completed, and so on.  Then you
> write "{% if object.state == object.completed_state %}".
>
> IIUC, you wouldn't have a problem with that?  It still doesn't feel
> quite right, but given the limitations of a template language, it
> might grow on me.
>
> Another alternative would be to have attributes like 'completed' be
> *boolean* properties computed from a State-valued attribute, and write
> just "{% if object.completed %}".  This actually feels good to me
> given it's a templating language.
>
> But I don't know if either of those is reasonable in the context.
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130923/d855f562/attachment.html>


More information about the Python-Dev mailing list