-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6553c4
commit e7d1b7d
Showing
63 changed files
with
641 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .serializers_.change_logging import * | ||
from .serializers_.data import * | ||
from .serializers_.jobs import * | ||
from .nested_serializers import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Annotated, List | ||
|
||
import strawberry | ||
import strawberry_django | ||
from django.contrib.contenttypes.models import ContentType | ||
|
||
from core.models import ObjectChange | ||
|
||
__all__ = ( | ||
'ChangelogMixin', | ||
) | ||
|
||
|
||
@strawberry.type | ||
class ChangelogMixin: | ||
|
||
@strawberry_django.field | ||
def changelog(self, info) -> List[Annotated["ObjectChangeType", strawberry.lazy('.types')]]: | ||
content_type = ContentType.objects.get_for_model(self) | ||
object_changes = ObjectChange.objects.filter( | ||
changed_object_type=content_type, | ||
changed_object_id=self.pk | ||
) | ||
return object_changes.restrict(info.context.request.user, 'view') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('core', '0010_gfk_indexes'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.SeparateDatabaseAndState( | ||
state_operations=[ | ||
migrations.CreateModel( | ||
name='ObjectChange', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)), | ||
('time', models.DateTimeField(auto_now_add=True, db_index=True)), | ||
('user_name', models.CharField(editable=False, max_length=150)), | ||
('request_id', models.UUIDField(db_index=True, editable=False)), | ||
('action', models.CharField(max_length=50)), | ||
('changed_object_id', models.PositiveBigIntegerField()), | ||
('related_object_id', models.PositiveBigIntegerField(blank=True, null=True)), | ||
('object_repr', models.CharField(editable=False, max_length=200)), | ||
('prechange_data', models.JSONField(blank=True, editable=False, null=True)), | ||
('postchange_data', models.JSONField(blank=True, editable=False, null=True)), | ||
('changed_object_type', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.contenttype')), | ||
('related_object_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='+', to='contenttypes.contenttype')), | ||
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='changes', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'verbose_name': 'object change', | ||
'verbose_name_plural': 'object changes', | ||
'ordering': ['-time'], | ||
'indexes': [models.Index(fields=['changed_object_type', 'changed_object_id'], name='core_object_changed_c227ce_idx'), models.Index(fields=['related_object_type', 'related_object_id'], name='core_object_related_3375d6_idx')], | ||
}, | ||
), | ||
], | ||
# Table has been renamed from 'extras' app | ||
database_operations=[], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .config import * | ||
from .contenttypes import * | ||
from .change_logging import * | ||
from .config import * | ||
from .data import * | ||
from .files import * | ||
from .jobs import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.apps import apps | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.db.utils import ProgrammingError | ||
|
||
from utilities.querysets import RestrictedQuerySet | ||
|
||
__all__ = ( | ||
'ObjectChangeQuerySet', | ||
) | ||
|
||
|
||
class ObjectChangeQuerySet(RestrictedQuerySet): | ||
|
||
def valid_models(self): | ||
# Exclude any change records which refer to an instance of a model that's no longer installed. This | ||
# can happen when a plugin is removed but its data remains in the database, for example. | ||
try: | ||
content_types = ContentType.objects.get_for_models(*apps.get_models()).values() | ||
except ProgrammingError: | ||
# Handle the case where the database schema has not yet been initialized | ||
content_types = ContentType.objects.none() | ||
|
||
content_type_ids = set( | ||
ct.pk for ct in content_types | ||
) | ||
return self.filter(changed_object_type_id__in=content_type_ids) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .change_logging import * | ||
from .config import * | ||
from .data import * | ||
from .jobs import * | ||
|
Oops, something went wrong.