o
    ˷e~	                     @   s   d dl mZ G dd dZdS )   )TableExportc                       sT   e Zd ZdZeZdZdZdZdZ	ej
fZdd Zdd	 Zd
d Z fddZ  ZS )ExportMixina  
    Support various export formats for the table data.

    `ExportMixin` looks for some attributes on the class to change it's behavior:

    Attributes:
        export_class (TableExport): Allows using a custom implementation of `TableExport`.
        export_name (str): is the name of file that will be exported, without extension.
        export_trigger_param (str): is the name of the GET attribute used to trigger
            the export. It's value decides the export format, refer to
            `TableExport` for a list of available formats.
        exclude_columns (iterable): column names excluded from the export.
            For example, one might want to exclude columns containing buttons from
            the export. Excluding columns from the export is also possible using the
            `exclude_from_export` argument to the `.Column` constructor::

                class Table(tables.Table):
                    name = tables.Column()
                    buttons = tables.TemplateColumn(exclude_from_export=True, template_name=...)
        export_formats (iterable): export formats to render a set of buttons in the template.
        dataset_kwargs (dictionary): passed as `**kwargs` to `tablib.Dataset` constructor::

            dataset_kwargs = {"tite": "My custom tab title"}
    table_export Nc                 C   s   d | j|S )Nz{}.{})formatexport_name)selfexport_formatr   r   R/var/www/ideatree/venv/lib/python3.10/site-packages/django_tables2/export/views.pyget_export_filename&   s   zExportMixin.get_export_filenamec                 C   s   | j S N)dataset_kwargs)r	   r   r   r   get_dataset_kwargs)   s   zExportMixin.get_dataset_kwargsc                 C   s:   | j || jdi |  | j|  d}|j| |dS )N)r
   r   exclude_columnsr   )filenamer   )export_class	get_tableget_table_kwargsr   r   responser   )r	   r
   exporterr   r   r   create_export,   s   zExportMixin.create_exportc                    s<   | j j| jd }| j|r| |S t j|fi |S r   )	requestGETgetexport_trigger_paramr   is_valid_formatr   superrender_to_response)r	   contextkwargsr
   	__class__r   r   r   6   s   
zExportMixin.render_to_response)__name__
__module____qualname____doc__r   r   r   r   r   r   CSVexport_formatsr   r   r   r   __classcell__r   r   r!   r   r      s    
r   N)exportr   r   r   r   r   r   <module>   s    