Changeset f7aa709 in rattail


Ignore:
Timestamp:
07/29/2020 01:38:43 AM (3 years ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
637b9a3
Parents:
d0deae5
Message:

Add BatchHandler.do_delete() method

Location:
rattail
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rattail/batch/filemon.py

    rd0deae5 rf7aa709  
    1 # -*- coding: utf-8 -*-
     1# -*- coding: utf-8; -*-
    22################################################################################
    33#
    44#  Rattail -- Retail Software Framework
    5 #  Copyright © 2010-2017 Lance Edgar
     5#  Copyright © 2010-2020 Lance Edgar
    66#
    77#  This file is part of Rattail.
     
    8787            if not batch.data_rows:
    8888                log.debug("auto-deleting empty '{}' batch: {}".format(handler.batch_key, batch))
    89                 batch.delete_data(self.config)
    90                 session.delete(batch)
     89                handler.do_delete(batch)
    9190                batch = None
    9291
  • rattail/batch/handlers.py

    rd0deae5 rf7aa709  
    234234
    235235        def purge(batch, i):
    236             self.delete(batch, delete_all_data=delete_all_data)
    237             session.delete(batch)
     236            self.do_delete(batch, dry_run=dry_run)
    238237            result.purged += 1
    239238            if i % 5 == 0:
     
    733732        return True
    734733
     734    def do_delete(self, batch, dry_run=False, progress=None, **kwargs):
     735        """
     736        Totally delete the given batch.  This includes deleting the batch
     737        itself, any rows and "extra" data such as files.
     738
     739        Note that callers *should* use this method, but custom batch handlers
     740        should *not* override this method.  Conversely, custom handlers
     741        *should* override the :meth:`~delete()` method, but callers should
     742        *not* use that one directly.
     743        """
     744        session = orm.object_session(batch)
     745
     746        if 'delete_all_data' in kwargs:
     747            warnings.warn("The 'delete_all_data' kwarg is not supported for "
     748                          "this method; please use 'dry_run' instead",
     749                          DeprecationWarning)
     750        kwargs['delete_all_data'] = not dry_run
     751
     752        self.delete(batch, progress=progress, **kwargs)
     753        session.delete(batch)
     754
    735755    def delete(self, batch, delete_all_data=True, progress=None, **kwargs):
    736756        """
     
    738758        records, as well as files on disk etc.  This method should *not* delete
    739759        the batch itself however.
     760
     761        Note that callers should *not* use this method, but custom batch
     762        handlers *should* override this method.  Conversely, custom handlers
     763        should *not* override the :meth:`~do_delete()` method, but callers
     764        *should* use that one directly.
    740765
    741766        :param delete_all_data: Flag indicating whether *all* data should be
  • rattail/commands/batch.py

    rd0deae5 rf7aa709  
    120120            if not batch.data_rows:
    121121                log.debug("auto-deleting empty '%s' batch: %s", handler.batch_key, batch)
    122                 batch.delete_data(self.config)
    123                 session.delete(batch)
     122                handler.do_delete(batch, dry_run=args.dry_run,
     123                                  progress=self.progress)
    124124                batch = None
    125125
Note: See TracChangeset for help on using the changeset viewer.