Changeset View
Changeset View
Standalone View
Standalone View
looper/admin_log.py
| from typing import Optional | from typing import Optional | ||||
| import django.db.models | |||||
| import django.conf | |||||
| # noinspection PyUnresolvedReferences | # noinspection PyUnresolvedReferences | ||||
| from django.contrib.admin.models import ADDITION, CHANGE, DELETION | from django.contrib.admin.models import ADDITION, CHANGE, DELETION, LogEntry | ||||
| import django.conf | |||||
| import django.db.models | |||||
| def attach_log_entry( | def attach_log_entry( | ||||
| instance: django.db.models.Model, | instance: django.db.models.Model, | ||||
| message: str, | message: str, | ||||
| action_flag: int = CHANGE, | action_flag: int = CHANGE, | ||||
| user_id: Optional[int] = None, | user_id: Optional[int] = None, | ||||
| ) -> None: | ) -> None: | ||||
| Show All 16 Lines | LogEntry.objects.log_action( | ||||
| content_type_id=ContentType.objects.get_for_model(type(instance)).pk, | content_type_id=ContentType.objects.get_for_model(type(instance)).pk, | ||||
| object_id=instance.id, | object_id=instance.id, | ||||
| object_repr=str(instance), | object_repr=str(instance), | ||||
| action_flag=action_flag, | action_flag=action_flag, | ||||
| change_message=message, | change_message=message, | ||||
| ) | ) | ||||
| def entries_for(instance: django.db.models.Model) -> django.db.models.QuerySet: | def entries_for(instance: django.db.models.Model) -> 'django.db.models.QuerySet[LogEntry]': | ||||
| """Build a query for all log entries attached to an instance.""" | """Build a query for all log entries attached to an instance.""" | ||||
| from django.contrib.admin.models import LogEntry | from django.contrib.admin.models import LogEntry | ||||
| from django.contrib.contenttypes.models import ContentType | from django.contrib.contenttypes.models import ContentType | ||||
| return LogEntry.objects.filter( | return LogEntry.objects.filter( | ||||
| content_type_id=ContentType.objects.get_for_model(type(instance)).pk, object_id=instance.id | content_type_id=ContentType.objects.get_for_model(type(instance)).pk, object_id=instance.id | ||||
| ) | ) | ||||