Make it possible to fully delete unlisted/unrated extensions #81
@ -59,19 +59,23 @@ class TrackChangesMixin(models.Model):
|
||||
|
||||
track_changes_to_fields: Set[str]
|
||||
|
||||
def _compare(self, old_instance: object) -> bool:
|
||||
"""Returns True if model fields have changed.
|
||||
def _was_modified(self, old_instance: object, update_fields=None) -> bool:
|
||||
"""Returns True if the record is modified.
|
||||
|
||||
Only checks fields listed in self.track_changes_to_fields.
|
||||
"""
|
||||
for field in self.track_changes_to_fields:
|
||||
# If update_fields was given and this field was NOT in it,
|
||||
# its value definitely won't be changed:
|
||||
if update_fields is not None and field not in update_fields:
|
||||
continue
|
||||
old_val = getattr(old_instance, field, ...)
|
||||
new_val = getattr(self, field, ...)
|
||||
if old_val != new_val:
|
||||
return True
|
||||
return False
|
||||
|
||||
def pre_save_record(self) -> Tuple[bool, OldStateType]:
|
||||
def pre_save_record(self, *args, **kwargs) -> Tuple[bool, OldStateType]:
|
||||
"""Tracks the previous state of this object.
|
||||
|
||||
Only records fields listed in self.track_changes_to_fields.
|
||||
@ -86,7 +90,8 @@ class TrackChangesMixin(models.Model):
|
||||
except type(self).DoesNotExist:
|
||||
return True, {}
|
||||
|
||||
was_modified = self._compare(db_instance)
|
||||
update_fields = kwargs.get('update_fields')
|
||||
was_modified = self._was_modified(db_instance, update_fields=update_fields)
|
||||
old_instance_data = {
|
||||
attr: copy.deepcopy(getattr(db_instance, attr)) for attr in self.track_changes_to_fields
|
||||
}
|
||||
|
@ -44,9 +44,10 @@ def _delete_file(sender: object, instance: object, **kwargs: object) -> None:
|
||||
def _record_changes(
|
||||
sender: object,
|
||||
instance: Union[extensions.models.Extension, extensions.models.Version],
|
||||
update_fields: object,
|
||||
**kwargs: object,
|
||||
) -> None:
|
||||
was_changed, old_state = instance.pre_save_record()
|
||||
was_changed, old_state = instance.pre_save_record(update_fields=update_fields)
|
||||
|
||||
if hasattr(instance, 'name'):
|
||||
instance.sanitize('name', was_changed, old_state, **kwargs)
|
||||
|
@ -10,8 +10,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@receiver(pre_save, sender=files.models.File)
|
||||
def _record_changes(sender: object, instance: files.models.File, **kwargs: object) -> None:
|
||||
was_changed, old_state = instance.pre_save_record()
|
||||
def _record_changes(
|
||||
sender: object, instance: files.models.File, update_fields: object, **kwargs: object
|
||||
) -> None:
|
||||
was_changed, old_state = instance.pre_save_record(update_fields=update_fields)
|
||||
|
||||
instance.record_status_change(was_changed, old_state, **kwargs)
|
||||
|
||||
|
@ -0,0 +1,20 @@
|
||||
[Unit]
|
||||
Description=Send notification emails for {{ project_name }} {{ env|capitalize }}
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User={{ user }}
|
||||
Group={{ group }}
|
||||
EnvironmentFile={{ env_file }}
|
||||
ExecStart={{ dir.source }}/.venv/bin/python {{ dir.source }}/manage.py send_notification_emails
|
||||
SyslogIdentifier={{ service_name }}
|
||||
NotifyAccess=all
|
||||
WorkingDirectory={{ dir.source }}
|
||||
|
||||
PrivateTmp=true
|
||||
ProtectHome=true
|
||||
ProtectSystem=full
|
||||
CapabilityBoundingSet=~CAP_SYS_ADMIN
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -0,0 +1,8 @@
|
||||
[Timer]
|
||||
OnCalendar=*-*-* *:*:00
|
||||
RandomizedDelaySec=3
|
||||
AccuracySec=1us
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timer.target
|
@ -19,8 +19,10 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@receiver(pre_save, sender=User)
|
||||
def _record_changes(sender: object, instance: User, **kwargs: object) -> None:
|
||||
was_changed, old_state = instance.pre_save_record()
|
||||
def _record_changes(
|
||||
sender: object, instance: User, update_fields: object, **kwargs: object
|
||||
) -> None:
|
||||
was_changed, old_state = instance.pre_save_record(update_fields=update_fields)
|
||||
|
||||
instance.record_status_change(was_changed, old_state, **kwargs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user