Changeset f9bf01b in rattail


Ignore:
Timestamp:
02/14/19 10:34:29 (13 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
0bf04a7
Parents:
8ae12ca
Message:

Add include_fields() and exclude_fields() importer methods

for convenience, to tweak field list at runtime

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail/importing/importers.py

    r8ae12ca rf9bf01b  
    106106        self.fields = fields or self.supported_fields
    107107        if exclude_fields:
    108             for field in exclude_fields:
    109                 if field in self.fields:
    110                     self.fields.remove(field)
     108            self.exclude_fields(*exclude_fields)
    111109        if isinstance(self.key, six.string_types):
    112110            self.key = (self.key,)
     
    120118            self.model_name = self.model_class.__name__
    121119        self._setup(**kwargs)
     120
     121    def include_fields(self, *args):
     122        """
     123        Add the given fields to the supported field list for the importer.  May
     124        be used at runtime to customize behavior.
     125        """
     126        for field in args:
     127            if field not in self.fields:
     128                self.fields.append(field)
     129
     130    def exclude_fields(self, *args):
     131        """
     132        Remove the given fields from the supported field list for the importer.
     133        May be used at runtime to customize behavior.
     134        """
     135        for field in args:
     136            if field in self.fields:
     137                self.fields.remove(field)
    122138
    123139    def get_model_class(self):
Note: See TracChangeset for help on using the changeset viewer.