1+ from typing import TYPE_CHECKING , Union
2+
13from django .core .exceptions import ImproperlyConfigured
24from django .http import HttpResponse
35
6+ if TYPE_CHECKING :
7+ from ..tables import Table
8+
49try :
510 from tablib import Dataset
611except ImportError : # pragma: no cover
@@ -51,7 +56,9 @@ def __init__(self, export_format, table, exclude_columns=None, dataset_kwargs=No
5156 self .format = export_format
5257 self .dataset = self .table_to_dataset (table , exclude_columns , dataset_kwargs )
5358
54- def table_to_dataset (self , table , exclude_columns , dataset_kwargs = None ):
59+ def table_to_dataset (
60+ self , table : "Table" , exclude_columns : list [str ], dataset_kwargs : "Union[dict, None]" = None
61+ ) -> Dataset :
5562 """Transform a table to a tablib dataset."""
5663
5764 def default_dataset_title ():
@@ -71,25 +78,21 @@ def default_dataset_title():
7178 return dataset
7279
7380 @classmethod
74- def is_valid_format (self , export_format ) :
81+ def is_valid_format (self , export_format : str ) -> bool :
7582 """
7683 Returns true if `export_format` is one of the supported export formats
7784 """
7885 return export_format is not None and export_format in TableExport .FORMATS .keys ()
7986
80- def content_type (self ):
81- """
82- Returns the content type for the current export format
83- """
87+ def content_type (self ) -> str :
88+ """Return the content type for the current export format."""
8489 return self .FORMATS [self .format ]
8590
8691 def export (self ):
87- """
88- Returns the string/bytes for the current export format
89- """
92+ """Return the string/bytes for the current export format."""
9093 return self .dataset .export (self .format )
9194
92- def response (self , filename = None ):
95+ def response (self , filename : Union [ str , None ] = None ) -> HttpResponse :
9396 """
9497 Builds and returns a `HttpResponse` containing the exported data
9598
0 commit comments