Beispiel #1
0
 def log_change(self, request, object, message):
     if is_active():
         if isinstance(message, list):
             set_comment(LogEntry(change_message=json.dumps(message)).get_change_message())
         else:
             set_comment(message)
     super(VersionAdmin, self).log_change(request, object, message)
Beispiel #2
0
 def remove_trainees(self, trainees):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Removed trainees')
         for trainee in trainees:
             self.trainees.remove(trainee)
         self.save()
Beispiel #3
0
 def log_change(self, request, object, message):
     if is_active():
         if isinstance(message, list):
             set_comment(json.dumps(message))
         else:
             set_comment(message)
     super(VersionAdmin, self).log_change(request, object, message)
Beispiel #4
0
 def remove_trainees(self, trainees):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Removed trainees')
         for trainee in trainees:
             self.trainees.remove(trainee)
         self.save()
Beispiel #5
0
 def log_addition(self, request, object, change_message=None):
     change_message = change_message or _("Initial version.")
     if is_active():
         set_comment(change_message)
     try:
         super(VersionAdmin, self).log_addition(request, object, change_message)
     except TypeError:  # Django < 1.9 pragma: no cover
         super(VersionAdmin, self).log_addition(request, object)
Beispiel #6
0
 def add_trainees(self, trainees):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Added trainees')
         existing_trainees = self.trainees.all()
         for trainee in trainees:
             if trainee not in existing_trainees:
                 self.trainees.add(trainee)
         self.save()
Beispiel #7
0
 def add_trainees(self, trainees):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Added trainees')
         existing_trainees = self.trainees.all()
         for trainee in trainees:
             if trainee not in existing_trainees:
                 self.trainees.add(trainee)
         self.save()
Beispiel #8
0
 def log_addition(self, request, object, change_message=None):
     change_message = change_message or _("Initial version.")
     if is_active():
         # If https://code.djangoproject.com/ticket/27218 is implemented, we
         # could first call super() and get the change_message from the returned
         # LogEntry.
         if isinstance(change_message, list):
             set_comment(json.dumps(change_message))
         else:
             set_comment(change_message)
     super(VersionAdmin, self).log_addition(request, object, change_message)
Beispiel #9
0
 def log_addition(self, request, object, change_message=None):
     change_message = change_message or _("Initial version.")
     if is_active():
         # If https://code.djangoproject.com/ticket/27218 is implemented, we
         # could first call super() and get the change_message from the returned
         # LogEntry.
         if isinstance(change_message, list):
             set_comment(json.dumps(change_message))
         else:
             set_comment(change_message)
     super(VersionAdmin, self).log_addition(request, object, change_message)
Beispiel #10
0
def post_revision_commit(sender, instance, **kwargs):
    if reversion.is_active() and (instance.status == 2 or instance.status == 4) and not instance.imported:

        authorized_user = instance.user
        authorizer = reversion.get_user()

        authorization = Authorization()

        if instance.specific_stream:
            authorization.stream = instance.specific_stream

        authorization.authorized_user = authorized_user
        authorization.authorizer = authorizer
        authorization.partner = instance.partner
        authorization.save()
Beispiel #11
0
    def save(self, *args, skip_last_updated=False, **kwargs):
        if self.is_dirty(check_relationship=True):
            dirty_fields = self.get_dirty_fields(check_relationship=True)

            # If only the signature changed, skip the rest of the updates here,
            # to avoid invalidating that signature. If the signature changed
            # along with something else, raise an error, since the signature
            # will probably be invalid. Otherwise, try and generate a new
            # signature for the object. If that fails, remove the signature,
            # because it is invalid now.

            dirty_field_names = list(dirty_fields.keys())
            should_sign = False

            if dirty_field_names == ['signature']:
                super().save(*args, **kwargs)
                return
            elif 'signature' in dirty_field_names and self.signature is not None:
                # Setting the signature while also changing something else is probably
                # going to make the signature immediately invalid. Don't allow it.
                raise ValidationError('Signatures must change alone')
            else:
                should_sign = True

            # Increment the revision ID, unless someone else tried to change it.
            if 'revision_id' not in dirty_field_names:
                self.revision_id += 1

            if reversion.is_active():
                reversion.add_to_revision(self)

            if not skip_last_updated:
                self.last_updated = timezone.now()

            if should_sign:
                try:
                    if self.id is None:
                        # Save now, to get an ID for the signature.
                        super().save(*args, **kwargs)
                        # Change from insert to update, so the save() call at the end doesn't fail
                        kwargs['force_insert'] = False
                    self.update_signature()
                except ImproperlyConfigured:
                    self.signature = None

        super().save(*args, **kwargs)
Beispiel #12
0
    def save(self, *args, skip_last_updated=False, **kwargs):
        if self.is_dirty(check_relationship=True):
            dirty_fields = self.get_dirty_fields(check_relationship=True)

            # If only the signature changed, skip the rest of the updates here, to avoid
            # invalidating that signature. If anything else changed, remove the signature,
            # since it is now invalid.
            dirty_field_names = list(dirty_fields.keys())
            should_sign = False

            if dirty_field_names == ['signature']:
                super().save(*args, **kwargs)
                return
            elif 'signature' in dirty_field_names and self.signature is not None:
                # Setting the signature while also changing something else is probably
                # going to make the signature immediately invalid. Don't allow it.
                raise ValidationError('Signatures must change alone')
            else:
                should_sign = True

            # Increment the revision ID, unless someone else tried to change it.
            if 'revision_id' not in dirty_field_names:
                self.revision_id += 1

            if reversion.is_active():
                reversion.add_to_revision(self)

            if not skip_last_updated:
                self.last_updated = timezone.now()

            if should_sign:
                try:
                    self.update_signature()
                except ImproperlyConfigured:
                    self.signature = None

        super().save(*args, **kwargs)
Beispiel #13
0
 def add_trainees(self, trainees):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Added trainees')
         self._add_pls(trainees)
Beispiel #14
0
 def add_trainee_group(self, tg):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Added group {}'.format(tg.name))
         self._add_pls(tg.trainees.all())
Beispiel #15
0
 def log_change(self, request, object, message):
     if is_active():
         set_comment(message)
     super(VersionAdmin, self).log_change(request, object, message)
Beispiel #16
0
 def log_change(self, request, object, message):
     entry = super().log_change(request, object, message)
     if is_active():
         set_comment(entry.get_change_message())
     return entry
Beispiel #17
0
 def log_addition(self, request, object, message):
     change_message = message or _("Initial version.")
     entry = super().log_addition(request, object, change_message)
     if is_active():
         set_comment(entry.get_change_message())
     return entry
Beispiel #18
0
 def save_with_reversion(*args, **kwargs):
     if not reversion.is_active():
         with reversion.create_revision():
             original_save(*args, **kwargs)
     else:
         original_save(*args, **kwargs)
Beispiel #19
0
 def add_trainees(self, trainees):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Added trainees')
         self._add_pls(trainees)
Beispiel #20
0
 def add_trainee_group(self, tg):
     with reversion.create_revision() and transaction.atomic():
         if reversion.is_active():
             reversion.set_comment('Added group {}'.format(tg.name))
         self._add_pls(tg.trainees.all())