o
    ˷e~                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ dd	lmZmZmZmZmZmZ G d
d dZe ZG dd dZejG dd dZG dd dZG dd dZdS )    )OrderedDict)islice)ImproperlyConfigured)reverse)format_html)SafeData)capfirst   )AccessorAttributeDictOrderByOrderByTuplecall_with_appropriatecomputed_valuesc                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	LibraryzA collection of columns.c                 C   s
   g | _ d S N)columnsself r   R/var/www/ideatree/venv/lib/python3.10/site-packages/django_tables2/columns/base.py__init__      
zLibrary.__init__c                 C   s,   t |dstd|jj| j| |S )N
from_fieldz{} is not a subclass of Column)hasattrr   format	__class____name__r   append)r   columnr   r   r   register   s   
zLibrary.registerc                 K   s   |du r| j d di |S t| j D ]+}t|dr | j}nt|d|j}t||d< |j|fi |}|du r;q|  S dS )z{
        Return a column object suitable for model field.

        Returns:
            `.Column` object or `None`
        Nr   get_related_fieldverbose_namer   )	r   reversedr   r!   r"   getattrnamer   r   )r   fieldkwargs	candidater"   r   r   r   r   column_for_field"   s   
zLibrary.column_for_fieldN)r   
__module____qualname____doc__r   r    r)   r   r   r   r   r      s
    r   c                   @   sF   e Zd ZdZdZdZdZdddZdd Zdd Z	d	d
 Z
dd ZdS )LinkTransformzQObject used to generate attributes for the `<a>`-tag to wrap the cell content in.Nc                 C   sT   || _ || _|| _t|ttfr#|\}}d|i}||t|tr!dnd< |p&i | _dS )aU  
        arguments:
            url (callable): If supplied, the result of this callable will be used as ``href`` attribute.
            accessor (Accessor): if supplied, the accessor will be used to decide on which object
                ``get_absolute_url()`` is called.
            attrs (dict): Customize attributes for the ``<a>`` tag.
            reverse_args (dict, tuple): Arguments to ``django.urls.reverse()``. If dict, the arguments
                are assumed to be keyword arguments to ``reverse()``, if tuple, a ``(viewname, args)``
                or ``(viewname, kwargs)``
        viewnamer'   argsN)urlattrsaccessor
isinstancelisttupledictreverse_args)r   r0   r2   r1   r7   r.   r/   r   r   r   r   I   s   zLinkTransform.__init__c                 K   s   | j rt| j rt| j |S |dd }|d }| jdd d ur'| j|dS |d u r5| jd u r5td}nt| jd ur>| jn|j}|	|}t
|ds`t
|drW|}| S tdt|| S )Nbound_columnrecordr.   r9    get_absolute_urlz:for linkify=True, '{}' must have a method get_absolute_url)r0   callabler   getr7   call_reverser2   r
   r%   resolver   	TypeErrorr   strr<   )r   r'   r8   r9   r2   contextr   r   r   compose_url_   s(   



zLinkTransform.compose_urlc                    s    fdd| j  }|d |d< |ddr!|d |d< |ddr4fdd|d D |d< |d	drIfd
d|d	  D |d	< |ddrW|d |d< tdi |S )zY
        Prepares the arguments to reverse() for this record and calls reverse()
        c                    s   t | tr
|  S | S r   )r3   r
   r@   )valr:   r   r   resolve_if_accessor~      z7LinkTransform.call_reverse.<locals>.resolve_if_accessorr.   urlconfNr/   c                    s   g | ]} |qS r   r   ).0arF   r   r   
<listcomp>   s    z.LinkTransform.call_reverse.<locals>.<listcomp>r'   c                    s   i | ]	\}}| |qS r   r   )rI   keyrE   rK   r   r   
<dictcomp>   s    z.LinkTransform.call_reverse.<locals>.<dictcomp>current_appr   )r7   copyr>   itemsr   )r   r9   paramsr   )r9   rF   r   r?   y   s   



zLinkTransform.call_reversec                 K   s&   t | jpi }| jdi ||d< |S )Nhrefr   )r   r1   rD   )r   r'   r1   r   r   r   	get_attrs   s   zLinkTransform.get_attrsc                 K   s0   | j di |}|d d u r|S td| |S )NrS   z<a {}>{}</a>r   )rT   r   as_html)r   contentr'   r1   r   r   r   __call__   s   zLinkTransform.__call__)NNNN)r   r*   r+   r,   r.   r2   r1   r   rD   r?   rT   rW   r   r   r   r   r-   B   s    
r-   c                   @   s   e Zd ZdZdZdZdZdZ													dddZe	d	d
 Z
e	dd Zdd Zdd Zdd Zdd Zedd ZdS )Columnaf  
    Represents a single column of a table.

    `.Column` objects control the way a column (including the cells that fall
    within it) are rendered.

    Arguments:
        attrs (dict): HTML attributes for elements that make up the column.
            This API is extended by subclasses to allow arbitrary HTML
            attributes to be added to the output.

            By default `.Column` supports:

             - ``th`` -- ``table/thead/tr/th`` elements
             - ``td`` -- ``table/tbody/tr/td`` elements
             - ``cell`` -- fallback if ``th`` or ``td`` is not defined
             - ``a`` -- To control the attributes for the ``a`` tag if the cell
               is wrapped in a link.
        accessor (str or `~.Accessor`): An accessor that describes how to
            extract values for this column from the :term:`table data`.
        default (str or callable): The default value for the column. This can be
            a value or a callable object [1]_. If an object in the data provides
            `None` for a column, the default will be used instead.

            The default value may affect ordering, depending on the type of data
            the table is using. The only case where ordering is not affected is
            when a `.QuerySet` is used as the table data (since sorting is
            performed by the database).
        empty_values (iterable): list of values considered as a missing value,
            for which the column will render the default value. Defaults to
            `(None, '')`
        exclude_from_export (bool): If `True`, this column will not be added to
            the data iterator returned from as_values().
        footer (str, callable): Defines the footer of this column. If a callable
            is passed, it can take optional keyword arguments `column`,
            `bound_column` and `table`.
        order_by (str, tuple or `.Accessor`): Allows one or more accessors to be
            used for ordering rather than *accessor*.
        orderable (bool): If `False`, this column will not be allowed to
            influence row ordering/sorting.
        verbose_name (str): A human readable version of the column name.
        visible (bool): If `True`, this column will be rendered.
            Columns with `visible=False` will not be rendered, but will be included
            in ``.Table.as_values()`` and thus also in :ref:`export`.
        localize: If the cells in this column will be localized by the
            `localize` filter:

              - If `True`, force localization
              - If `False`, values are not localized
              - If `None` (default), localization depends on the ``USE_L10N`` setting.
        linkify (bool, str, callable, dict, tuple): Controls if cell content will be wrapped in an
            ``a`` tag. The different ways to define the ``href`` attribute:

             - If `True`, the ``record.get_absolute_url()`` or the related model's
               `get_absolute_url()` is used.
             - If a callable is passed, the returned value is used, if it's not ``None``.
               The callable can optionally accept any argument valid for :ref:`table.render_foo`-methods,
               for example `record` or `value`.
             - If a `dict` is passed, it's passed on to ``~django.urls.reverse``.
             - If a `tuple` is passed, it must be either a (viewname, args) or (viewname, kwargs)
               tuple, which is also passed to ``~django.urls.reverse``.

    Examples, assuming this model::

        class Blog(models.Model):
            title = models.CharField(max_length=100)
            body = model.TextField()
            user = model.ForeignKey(get_user_model(), on_delete=models.CASCADE)

    Using the ``linkify`` argument to control the linkification. These columns will all display
    the value returned from `str(record.user)`::

        # If the column is named 'user', the column will use record.user.get_absolute_url()
        user = tables.Column(linkify=True)

        # We can also do that explicitly:
        user = tables.Column(linkify=lambda record: record.user.get_absolute_url())

        # or, if no get_absolute_url is defined, or a custom link is required, we have a couple
        # of ways to define what is passed to reverse()
        user = tables.Column(linkify={"viewname": "user_detail", "args": [tables.A("user__pk")]})
        user = tables.Column(linkify=("user_detail", [tables.A("user__pk")])) # (viewname, args)
        user = tables.Column(linkify=("user_detail", {"pk": tables.A("user__pk")})) # (viewname, kwargs)

        initial_sort_descending (bool): If `True`, a column will sort in descending order
            on "first click" after table has been rendered. If `False`, column will follow
            default behavior, and sort ascending on "first click". Defaults to `False`.

    .. [1] The provided callable object must not expect to receive any arguments.
    r   )Nr;   NFTc                 C   sn  |d u st |tst|stdt|j t|r"|d ur"td|r(t|nd | _|| _|| _	|| _
|| _|p>t| di | _t |trH|fn|}|d urRt|nd | _|d ur\|| _|	| _|
| _|| _d }t|spt| dr}tt|rw|n| jd}nt |ttfrt|d}n
|du rt| jd}|d urtdd| jd	i i|| _|| _tj| _t jd
7  _d S )Nz-accessor must be a string or callable, not %sz:accessor must be string when default is used, not callabler1   get_url)r0   )r7   T)r2   rJ      r   )r3   rB   r=   rA   typer   r
   r2   _defaultr"   visible	orderabler$   r1   r   order_byempty_valueslocalize_footerexclude_from_exportr   r6   rY   r5   r-   r>   linkinitial_sort_descendingrX   creation_counter)r   r"   r2   defaultr]   r^   r1   r_   r`   ra   footerrc   linkifyre   link_kwargsr   r   r   r     s>   zColumn.__init__c                 C   s   t | jr	|  S | jS r   )r=   r\   r   r   r   r   rg   >  s   zColumn.defaultc                 C   s   | j S )ag  
        The value used for the column heading (e.g. inside the ``<th>`` tag).

        By default this returns `~.Column.verbose_name`.

        :returns: `unicode` or `None`

        .. note::

            This property typically is not accessed directly when a table is
            rendered. Instead, `.BoundColumn.header` is accessed which in turn
            accesses this property. This allows the header to fallback to the
            column name (it is only available on a `.BoundColumn` object hence
            accessing that first) when this property doesn't return something
            useful.
        )r"   r   r   r   r   headerB  s   zColumn.headerc                 C   sL   | ||d}| j durt| j rt| j |S | j S t| dr$t| j|S dS )z/Return the content of the footer, if specified.)r   r8   tableNrender_footerr;   )rb   r=   r   r   rm   )r   r8   rl   footer_kwargsr   r   r   rh   V  s   


zColumn.footerc                 C   s   |S )a  
        Return the content for a specific cell.

        This method can be overridden by :ref:`table.render_FOO` methods on the
        table or by subclassing `.Column`.

        If the value for this cell is in `.empty_values`, this method is
        skipped and an appropriate default value is rendered instead.
        Subclasses should set `.empty_values` to ``()`` if they want to handle
        all values in `.render`.
        r   r   valuer   r   r   rendere  s   zColumn.renderc                 K   s   t | j|}|S )a  
        Return the content for a specific cell for exports.

        Similar to `.render` but without any html content.
        This can be used to get the data in the formatted as it is presented but in a
        form that could be added to a csv file.

        The default implementation just calls the `render` function but any
        subclasses where `render` returns html content should override this
        method.

        See `LinkColumn` for an example.
        )r   rq   )r   r'   rp   r   r   r   rp   s  s   zColumn.valuec                 C   s   |dfS )a+  
        Order the QuerySet of the table.

        This method can be overridden by :ref:`table.order_FOO` methods on the
        table or by subclassing `.Column`; but only overrides if second element
        in return tuple is True.

        returns:
            Tuple (QuerySet, boolean)
        Fr   )r   querysetis_descendingr   r   r   order  s   zColumn.orderc                 K   s   | t u r| di |S dS )a  
        Return a specialized column for the model field or `None`.

        Arguments:
            field (Model Field instance): the field that needs a suitable column
        Returns:
            `.Column` object or `None`

        If the column is not specialized for the given model field, it should
        return `None`. This gives other columns the opportunity to do better.

        If the column is specialized, it should return an instance of itself
        that is configured appropriately for the field.
        Nr   )rX   )clsr&   r'   r   r   r   r     s   zColumn.from_field)NNNTNNNNNNFFF)r   r*   r+   r,   rf   r`   rd   	_explicitr   propertyrg   rk   rh   rq   rp   rt   classmethodr   r   r   r   r   rX      s<    \
7

rX   c                   @   s   e Zd ZdZdd Zdd Zedd Zedd	 Zd
d Z	dd Z
dd Zedd Zedd Zedd Zdd Zedd Zedd Zedd Zedd Zed d! Zed"d# Zed$d% Zd&S )'BoundColumna  
    A run-time version of `.Column`.

    The difference between `.BoundColumn` and `.Column`,
    is that `.BoundColumn` objects include the relationship between a `.Column` and a `.Table`.
    In practice, this means that a `.BoundColumn` knows the *"variable name"* given to the `.Column`
    when it was declared on the `.Table`.

    arguments:
        table (`~.Table`): The table in which this column exists
        column (`~.Column`): The type of column
        name (str): The variable name of the column used when defining the
                    `.Table`. In this example the name is ``age``::

                          class SimpleTable(tables.Table):
                              age = tables.Column()

    c                 C   s$   || _ || _|| _|j| _d | _d S r   )_tabler   r%   rd   current_value)r   rl   r   r%   r   r   r   r     s
   
zBoundColumn.__init__c                 C   s
   t | jS r   )rB   rk   r   r   r   r   __str__  r   zBoundColumn.__str__c                 C   s   | j jpt| jS )zNReturns the string used to access data for this column out of the data source.)r   r2   r
   r%   r   r   r   r   r2     s   zBoundColumn.accessorc                 C   s(  | j | d}t| dddur t| dddur || j| jd t| j j}|t| jj |di }t	|d||d|d< t	|d	||d|d	< t	|d
||d|d
< t
|d |d< t
|d	 |d	< t
|d
 |d
< | |d |d d< | |d	 |d	 d< | |d
 |d
 d< |S )a  
        Proxy to `.Column.attrs` but injects some values of our own.

        A ``th``, ``td`` and ``tf`` are guaranteed to be defined (irrespective
        of what is actually defined in the column attrs. This makes writing
        templates easier. ``tf`` is not actually a HTML tag, but this key name
        will be used for attributes for column's footer, if the column has one.
        )rl   r8   current_recordNr{   )r9   rp   cellth)r'   tdtfclass)rz   r$   updater}   r{   r6   r1   r   r>   r   r   get_th_classget_td_class)r   r'   r1   
cell_attrsr   r   r   r1     s"   zBoundColumn.attrsc                 C   s6   | dd}|du rt nt|d}| j|| S )zN
        Return a set of the classes from the class key in ``attrs``.
        r   N )r>   setsplitrz   get_column_class_names)r   r1   classesr   r   r   _get_cell_class  s   zBoundColumn._get_cell_classc                 C   s(   t | |}t|dkrdS d|S )zQ
        Returns the HTML class attribute for a data cell in this column
        r   Nr   )sortedr   lenjoin)r   td_attrsr   r   r   r   r     s   zBoundColumn.get_td_classc                 C   sx   |  |}|di }| jr||dd | jr-|| jjr&|ddn|dd t|dkr5dS d	t	|S )
zS
        Returns the HTML class attribute for a header cell in this column
        	_orderingr^   
descendingdesc	ascendingascr   Nr   )
r   r>   r^   add
is_orderedorder_by_aliasrs   r   r   r   )r   th_attrsr   ordering_classr   r   r   r     s   

zBoundColumn.get_th_classc                 C   s   | j j}|du r| jj}|S )z*Returns the default value for this column.N)r   rg   rz   ro   r   r   r   rg     s   zBoundColumn.defaultc                 C   s   | j j}|r|S | jS )z0The contents of the header cell for this column.)r   rk   r"   )r   column_headerr   r   r   rk   &  s   zBoundColumn.headerc                 C   s   t | jj| | jdS )z0The contents of the footer cell for this column.)r8   rl   )r   r   rh   rz   r   r   r   r   rh   0  s   zBoundColumn.footerc                 C   s   | j jd upt| j dS )Nrm   )r   rb   r   r   r   r   r   
has_footer7  rG   zBoundColumn.has_footerc                 C   s4   | j jdur| j j}nt| jf}| jjr|jS |S )z
        Return an `.OrderByTuple` of appropriately prefixed data source keys used to sort this column.

        See `.order_by_alias` for details.
        N)r   r_   r   r2   r   rs   oppositer   r_   r   r   r   r_   :  s   
zBoundColumn.order_byc                 C   sH   t | jjpi | j| j}| jr|jn||_| jj	r"| js"|j|_|S )a  
        Return an `OrderBy` describing the current state of ordering for this column.

        The following attempts to explain the difference between `order_by`
        and `.order_by_alias`.

        `.order_by_alias` returns and `.OrderBy` instance that's based on
        the *name* of the column, rather than the keys used to order the table
        data. Understanding the difference is essential.

        Having an alias *and* a keys version is necessary because an N-tuple
        (of data source keys) can be used by the column to order the data, and
        it is ambiguous when mapping from N-tuple to column (since multiple
        columns could use the same N-tuple).

        The solution is to use order by *aliases* (which are really just
        prefixed column names) that describe the ordering *state* of the
        column, rather than the specific keys in the data source should be
        ordered.

        e.g.::

            >>> class SimpleTable(tables.Table):
            ...     name = tables.Column(order_by=("firstname", "last_name"))
            ...
            >>> table = SimpleTable([], order_by=('-name', ))
            >>> table.columns["name"].order_by_alias
            "-name"
            >>> table.columns["name"].order_by
            ("-first_name", "-last_name")

        The `OrderBy` returned has been patched to include an extra attribute
        ``next``, which returns a version of the alias that would be
        transitioned to if the user toggles sorting on this column, for example::

            not sorted -> ascending
            ascending  -> descending
            descending -> ascending

        This is useful otherwise in templates you'd need something like::

            {% if column.is_ordered %}
                {% querystring table.prefixed_order_by_field=column.order_by_alias.opposite %}
            {% else %}
                {% querystring table.prefixed_order_by_field=column.order_by_alias %}
            {% endif %}

        )
r   rz   r_   r>   r%   r   r   nextr   re   r   r   r   r   r   H  s
   2zBoundColumn.order_by_aliasc                 C   s   | j | jjpdv S )Nr   )r%   rz   r_   r   r   r   r   r     s   zBoundColumn.is_orderedc                 C   s   | j jdur
| j jS | jjS )z-Return whether this column supports ordering.N)r   r^   rz   r   r   r   r   r^     s   zBoundColumn.orderablec                 C   s|   | j jdur
| j jS | jdd}| jjj}|r:t| j	|}|r3t
|dr,|jj}nt|d|j}t|tr:|S t|S )a  
        Return the verbose name for this column.

        In order of preference, this will return:
          1) The column's explicitly defined `verbose_name`
          2) The model's `verbose_name` with the first letter capitalized (if applicable)
          3) Fall back to the column name, with first letter capitalized.

        Any `verbose_name` that was not passed explicitly in the column
        definition is returned with the first character capitalized in keeping
        with the Django convention of `verbose_name` being defined in lowercase and
        uppercased as needed by the application.

        If the table is using `QuerySet` data, then use the corresponding model
        field's `~.db.Field.verbose_name`. If it is traversing a relationship,
        then get the last field in the accessor (i.e. stop when the
        relationship turns from ORM relationships to object attributes [e.g.
        person.upper should stop at person]).
        N_r   r&   r"   )r   r"   r%   replacerz   datamodelr
   r2   	get_fieldr   r&   r$   r3   r   r   )r   r%   r   r&   r   r   r   r"     s   



zBoundColumn.verbose_namec                 C      | j jS )z&Return whether this column is visible.)r   r]   r   r   r   r   r]        zBoundColumn.visiblec                 C   r   )zDReturn `True`, `False` or `None` as described in ``Column.localize``)r   ra   r   r   r   r   ra     r   zBoundColumn.localizeN)r   r*   r+   r,   r   r|   rw   r2   r1   r   r   r   rg   rk   rh   r   r_   r   r   r^   r"   r]   ra   r   r   r   r   ry     s@    

.	

	


7


,
ry   c                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd S )!BoundColumnsa  
    Container for spawning `.BoundColumn` objects.

    This is bound to a table and provides its `.Table.columns` property.
    It provides access to those columns in different ways (iterator,
    item-based, filtered and unfiltered etc), stuff that would not be possible
    with a simple iterator in the table class.

    A `BoundColumns` object is a container for holding `BoundColumn` objects.
    It provides methods that make accessing columns easier than if they were
    stored in a `list` or `dict`. `Columns` has a similar API to a `dict` (it
    actually uses a `~collections.OrderedDict` internally).

    At the moment you'll only come across this class when you access a
    `.Table.columns` property.

    Arguments:
        table (`.Table`): the table containing the columns
    c                 C   s   || _ t | _| D ]3\}}t||| | j|< }t|d| |j|_t|d| t|d| |j|_t|d| |j|_qd S )Nrender_value_order_)	rz   r   r   rQ   ry   r$   rq   rp   rt   )r   rl   base_columnsr%   r   r8   r   r   r   r     s   zBoundColumns.__init__c                 C      dd |   D S )Nc                 s   s    | ]\}}|V  qd S r   r   rI   r%   r   r   r   r   	<genexpr>      z)BoundColumns.iternames.<locals>.<genexpr>	iteritemsr   r   r   r   	iternames  s   zBoundColumns.iternamesc                 C      t |  S r   )r4   r   r   r   r   r   names     zBoundColumns.namesc                 C   r   )z~
        Return an iterator that exposes all `.BoundColumn` objects,
        regardless of visibility or sortability.
        c                 s   s    | ]\}}|V  qd S r   r   r   r   r   r   r     r   z'BoundColumns.iterall.<locals>.<genexpr>r   r   r   r   r   iterall  s   zBoundColumns.iterallc                 C   r   r   )r4   r   r   r   r   r   all  r   zBoundColumns.allc                 c   s0    | j jD ]}|| j jvr|| j| fV  qdS )aM  
        Return an iterator of ``(name, column)`` pairs (where ``column`` is a `BoundColumn`).

        This method is the mechanism for retrieving columns that takes into
        consideration all of the ordering and filtering modifiers that a table
        supports (e.g. `~Table.Meta.exclude` and `~Table.Meta.sequence`).
        N)rz   sequenceexcluder   r   r%   r   r   r   r     s   	zBoundColumns.iteritemsc                 C   r   r   )r4   r   r   r   r   r   rQ     r   zBoundColumns.itemsc                 C   r   )a_  
        Same as `BoundColumns.all` but only returns orderable columns.

        This is useful in templates, where iterating over the full
        set and checking ``{% if column.ordarable %}`` can be problematic in
        conjunction with e.g. ``{{ forloop.last }}`` (the last column might not
        be the actual last that is rendered).
        c                 s       | ]}|j r|V  qd S r   )r^   rI   xr   r   r   r         z-BoundColumns.iterorderable.<locals>.<genexpr>r   r   r   r   r   iterorderable  s   	zBoundColumns.iterorderablec                 C   r   )z
        Same as `.iterorderable` but only returns visible `.BoundColumn` objects.

        This is geared towards table rendering.
        c                 s   r   r   )r]   r   r   r   r   r     r   z+BoundColumns.itervisible.<locals>.<genexpr>r   r   r   r   r   itervisible  s   zBoundColumns.itervisiblec                 C      d| j | j_dS )z^
        Hide a column.

        Arguments:
            name(str): name of the column
        FNr   r   r]   r   r   r   r   hide     zBoundColumns.hidec                 C   r   )zo
        Show a column otherwise hidden.

        Arguments:
            name(str): name of the column
        TNr   r   r   r   r   show   r   zBoundColumns.showc                 C   s   |   S )z)Convenience API, alias of `.itervisible`.)r   r   r   r   r   __iter__)  s   zBoundColumns.__iter__c                 C   s"   t |tr||  v S ||  v S )z
        Check if a column is contained within a `BoundColumns` object.

        *item* can either be a `~.BoundColumn` object, or the name of a column.
        )r3   rB   r   r   )r   itemr   r   r   __contains__-  s   
zBoundColumns.__contains__c                 C   s   t t|  S )zDReturn how many `~.BoundColumn` objects are contained (and visible).)r   r4   r   r   r   r   r   __len__9  s   zBoundColumns.__len__c                 C   s   t |trztt|  ||d W S  ty   tw t |tr;|  D ]}|j|kr0|  S q%t	d
||  td
t|j)a!  
        Retrieve a specific `~.BoundColumn` object.

        *index* can either be 0-indexed or the name of a column

        .. code-block:: python

            columns['speed']  # returns a bound column with name 'speed'
            columns[0]        # returns the first column
        rZ   z5Column with name '{}' does not exist; choices are: {}z.Column indices must be integers or str, not {})r3   intr   r   r   StopIteration
IndexErrorrB   r%   KeyErrorr   r   rA   r[   r   )r   indexr   r   r   r   __getitem__=  s"   


zBoundColumns.__getitem__N)r   r*   r+   r,   r   r   r   r   r   r   rQ   r   r   r   r   r   r   r   r   r   r   r   r   r     s"    		r   N)collectionsr   	itertoolsr   django.core.exceptionsr   django.urlsr   django.utils.htmlr   django.utils.safestringr   django.utils.textr   utilsr
   r   r   r   r   r   r   libraryr-   r    rX   ry   r   r   r   r   r   <module>   s&     
+]  
  