예제 #1
0
    def _on_ui_save(self):
        """Called when data should be saved
        Calls merge_changes, but only with values that really changed
        """
        effective_changes = self.pending_changes()
        is_valid = False

        self.logger.debug("Request to apply model changes: %s" %
                          effective_changes)

        try:
            is_valid = self._on_ui_change(effective_changes)
        except exceptions.InvalidData as e:
            self.logger.info("Changes to be merged are invalid: %s" %
                             e.message)

        if self.only_merge_on_valid_changes and not is_valid:
            msg = "There are still fields with invalid values."
            self.logger.warning(msg)
            raise exceptions.PreconditionError(msg)

        successfull_merge = self.on_merge(effective_changes)

        if successfull_merge is None:
            self.logger.debug("on_save needs to return True/False or a " +
                              "Page/Dialog")
            successfull_merge = True

        if successfull_merge:
            self.logger.info("Changes were merged successfully")
            self.__changes = Changeset()
        else:
            self.logger.info("Changes were not merged.")

        return self.__handle_merge_result(successfull_merge)
예제 #2
0
 def prepare(self):
     self._prepared_elements = []
     for element in self:
         self.logger.debug("Preparing element '%s'" % element)
         if Transaction.Element not in element.__class__.mro():
             raise exceptions.PreconditionError(
                 ("%s is no Transaction." + "Element") % element)
         self._prepared_elements.append(element)
         element.prepare()
     return True
 def prepare(self):
     self._prepared_elements = []
     for element in self.elements:
         self.logger.debug("Preparing element '%s'" % element)
         if not issubclass(element.__class__, Transaction.Element) and \
                 not issubclass(element.__class__, Transaction):
             raise exceptions.PreconditionError(("%s is no Transaction."
                                                 "Element") % element)
         self._prepared_elements.append(element)
         element.prepare()
     return True