Ignore:
Timestamp:
24 Feb 2020, 21:26:35 (5 years ago)
Author:
Henrik Bettermann
Message:

Implement BatchProcessor.checkCreateRequirements and
BatchProcessor.checkUpdateRequirements methods mainly
to protect course result lists of graduated student.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r15065 r16012  
    196196        raise NotImplementedError('method not implemented')
    197197
     198    def checkCreateRequirements(self, parent, row, site):
     199        """Checks requirements the parent object must fulfill when
     200        a new subobject is being created.
     201
     202        This method is not used in case of updating or removing objects.
     203
     204        Returns error messages as strings in case of requirement
     205        problems.
     206        """
     207        return None
     208
    198209    def checkUpdateRequirements(self, obj, row, site):
    199210        """Checks requirements the object must fulfill when being updated.
    200211
    201212        This method is not used in case of deleting or adding objects.
     213
     214        Returns error messages as strings in case of requirement
     215        problems.
     216        """
     217        return None
     218
     219
     220    def checkRemoveRequirements(self, obj, row, site):
     221        """Checks requirements the object must fulfill when being removed.
     222
     223        This method is not used in case of updating or adding objects.
    202224
    203225        Returns error messages as strings in case of requirement
     
    329351           record is stored in the pending data file.
    330352
     353           The `BatchProcessor.checkCreateRequirements` method checks additional
     354           requirements the parent object must fulfill before a new sububject
     355           is being added. These requirements are not imposed by the data
     356           type but the context of the object. For example, the course results
     357           of graduated students must not changed by import, neither by
     358           creating nor updating or removing course tickets.
     359
    331360           Now `doImport` tries to add the new object with the data
    332361           from the conversion dictionary. In some cases this
     
    359388           a ``no such entry`` warning message is raised and a record is
    360389           stored in the pending data file.
     390
     391           The `BatchProcessor.checkRemoveRequirements` method checks additional
     392           requirements the object must fulfill before being removed.
     393           These requirements are not imposed by the data type but the context
     394           of the object. For example, the course results of graduated students
     395           must not changed by import, neither by creating nor updating or
     396           removing course tickets.
    361397
    362398           Finally, `doImport` removes the existing object.
     
    425461                        "This object already exists.")
    426462                    continue
     463                parent = self.getParent(row, site)
     464                create_errors = self.checkCreateRequirements(parent, row, site)
     465                if create_errors is not None:
     466                    num_warns += 1
     467                    self.writeFailedRow(
     468                        failed_writer, string_row, create_errors)
     469                    continue
    427470                obj = self.callFactory()
    428471                # Override all values in row, also
     
    453496                        failed_writer, string_row,
    454497                        "Cannot remove: no such entry")
     498                    continue
     499                obj = self.getEntry(row, site)
     500                remove_errors = self.checkRemoveRequirements(obj, row, site)
     501                if remove_errors is not None:
     502                    num_warns += 1
     503                    self.writeFailedRow(
     504                        failed_writer, string_row, remove_errors)
    455505                    continue
    456506                self.delEntry(row, site)
Note: See TracChangeset for help on using the changeset viewer.