2020-02-24 17:18:44 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
from django.conf import settings
|
2020-03-07 21:28:59 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2020-02-24 17:18:44 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
from django.db import models
|
2020-03-07 21:28:59 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2020-02-24 17:18:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Changelog(models.Model):
|
|
|
|
"""
|
2020-03-08 22:17:55 +00:00
|
|
|
Store each modification in the database (except sessions and logging),
|
2020-02-24 17:18:44 +00:00
|
|
|
including creating, editing and deleting models.
|
|
|
|
"""
|
|
|
|
|
|
|
|
user = models.ForeignKey(
|
|
|
|
settings.AUTH_USER_MODEL,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
null=True,
|
|
|
|
verbose_name=_('user'),
|
|
|
|
)
|
|
|
|
|
2020-02-27 13:47:34 +00:00
|
|
|
ip = models.GenericIPAddressField(
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
verbose_name=_("IP Address")
|
|
|
|
)
|
|
|
|
|
2020-02-26 22:34:27 +00:00
|
|
|
model = models.ForeignKey(
|
|
|
|
ContentType,
|
|
|
|
on_delete=models.PROTECT,
|
2020-02-24 17:18:44 +00:00
|
|
|
null=False,
|
|
|
|
blank=False,
|
|
|
|
verbose_name=_('model'),
|
|
|
|
)
|
|
|
|
|
|
|
|
instance_pk = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
null=False,
|
|
|
|
blank=False,
|
|
|
|
verbose_name=_('identifier'),
|
|
|
|
)
|
|
|
|
|
|
|
|
previous = models.TextField(
|
|
|
|
null=True,
|
|
|
|
verbose_name=_('previous data'),
|
|
|
|
)
|
|
|
|
|
|
|
|
data = models.TextField(
|
|
|
|
null=True,
|
|
|
|
verbose_name=_('new data'),
|
|
|
|
)
|
|
|
|
|
|
|
|
action = models.CharField( # create, edit or delete
|
|
|
|
max_length=16,
|
|
|
|
null=False,
|
|
|
|
blank=False,
|
2020-03-11 09:08:28 +00:00
|
|
|
choices=[
|
|
|
|
('create', _('create')),
|
|
|
|
('edit', _('edit')),
|
|
|
|
('delete', _('delete')),
|
|
|
|
],
|
|
|
|
default='edit',
|
2020-02-24 17:18:44 +00:00
|
|
|
verbose_name=_('action'),
|
|
|
|
)
|
|
|
|
|
|
|
|
timestamp = models.DateTimeField(
|
|
|
|
null=False,
|
|
|
|
blank=False,
|
|
|
|
auto_now_add=True,
|
|
|
|
name='timestamp',
|
|
|
|
verbose_name=_('timestamp'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def delete(self, using=None, keep_parents=False):
|
|
|
|
raise ValidationError(_("Logs cannot be destroyed."))
|
2020-04-06 08:58:16 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("changelog")
|
|
|
|
verbose_name_plural = _("changelogs")
|