Пример #1
0
    def create_historical_record(self, instance, type):
        manager = getattr(instance, self.manager_name)
        attrs = {}
        for field in instance._meta.fields:
            attrs[field.attname] = getattr(instance, field.attname)

        manager.create(history_type=type, **attrs)
Пример #2
0
    def create_historical_record(self, instance, editor, type):
        manager = getattr(instance, self.manager_name)
        attrs = {}
        for field in self.get_important_fields(instance):
            '''
            Detect a condition where a cascading delete causes an integrity
            error because the post_delete trigger tries to create a
            reference to a now-deleted instance in its history record.  This
            should only be an issue on PRESERVEd foreign keys, since CONVERTed
            ones won't have an explicit reference.

            Raise a specific exception when the condition is detected, allowing
            post_delete to ignore historical record creation in this case.
            '''
            if isinstance(field, models.ForeignKey):
                conversion = self.key_conversions.get(field.name, CONVERT)
                if conversion == PRESERVE:
                    try:
                        # dereference key to make sure it exists
                        getattr(instance, field.name)
                    except field.rel.to.DoesNotExist as e:
                        raise HistoricalIntegrityError(e)

            # copy field values normally
            attrs[field.attname] = getattr(instance, field.attname)
        manager.create(history_type=type, history_editor=editor, **attrs)
Пример #3
0
 def create_historical_record(self, instance, type):
     manager = getattr(instance, self.manager_name)
     attrs = {}
     for field in instance._meta.fields:
         attrs[field.attname] = getattr(instance, field.attname)
     manager.create(history_type=type, **attrs)
Пример #4
0
 def create_historical_record(self, instance, editor, type):
     manager = getattr(instance, self.manager_name)
     attrs = {}
     for field in self.get_important_field_names(instance):
         attrs[field] = getattr(instance, field)
     manager.create(history_type=type, history_editor=editor, **attrs)