kopia lustrzana https://github.com/wagtail/wagtail
Replace `data_json` `TextField` with `data` `JSONField` in `BaseLogEntry`
rodzic
3bf9b65c06
commit
bf8d5b3f94
docs
reference/pages
releases
wagtail
admin/tests
core
management/commands
models
|
@ -563,6 +563,7 @@ Contributors
|
|||
* Dennis McGregor
|
||||
* Joshua Munn
|
||||
* Gianluca De Cola
|
||||
* Sage Abdullah
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -983,13 +983,18 @@ Database fields
|
|||
|
||||
A foreign key to the user that triggered the action.
|
||||
|
||||
.. attribute:: data_json
|
||||
.. attribute:: data
|
||||
|
||||
(text)
|
||||
(dict)
|
||||
|
||||
The JSON representation of any additional details for each action.
|
||||
e.g. source page id and title when copying from a page. Or workflow id/name and next step id/name on a workflow transition
|
||||
|
||||
.. versionchanged:: 2.17
|
||||
|
||||
The field has been renamed from ``data_json`` to ``data`` and it now uses :class:`~django.db.models.JSONField` instead of
|
||||
:class:`~django.db.models.TextField`.
|
||||
|
||||
.. attribute:: timestamp
|
||||
|
||||
(date/time)
|
||||
|
@ -1016,8 +1021,6 @@ Methods and properties
|
|||
|
||||
.. autoattribute:: user_display_name
|
||||
|
||||
.. autoattribute:: data
|
||||
|
||||
.. autoattribute:: comment
|
||||
|
||||
.. autoattribute:: object_verbose_name
|
||||
|
|
|
@ -26,6 +26,7 @@ Here are other changes related to the redesign:
|
|||
* Remove IE11 warnings (Gianluca De Cola)
|
||||
* Replace `content_json` `TextField` with `content` `JSONField` in `PageRevision` (Sage Abdullah)
|
||||
* Remove `replace_text` management command (Sage Abdullah)
|
||||
* Replace `data_json` `TextField` with `data` `JSONField` in `BaseLogEntry` (Sage Abdullah)
|
||||
|
||||
|
||||
### Bug fixes
|
||||
|
@ -48,3 +49,11 @@ Here are other changes related to the redesign:
|
|||
* The `content_json` field in the `PageRevision` model has been renamed to `content`.
|
||||
* The field now internally uses `JSONField` instead of `TextField`.
|
||||
* If you have a large number of `PageRevision` objects, running the migrations might take a while.
|
||||
|
||||
## Replaced `data_json` `TextField` with `data` `JSONField` in `BaseLogEntry`
|
||||
|
||||
* The `data_json` field in the `BaseLogEntry` model has been renamed to `data`.
|
||||
* The field now internally uses `JSONField` instead of `TextField`.
|
||||
* The default empty value for the field has been changed from `""` to `{}`.
|
||||
* This change also affects `BaseLogEntry` subclasses, i.e. `PageLogEntry` and `ModelLogEntry`.
|
||||
* If you have a large number of objects for these models, running the migrations might take a while.
|
||||
|
|
|
@ -1327,7 +1327,7 @@ class TestConvertAliasPageAction(AdminAPITestCase):
|
|||
log = PageLogEntry.objects.get(action="wagtail.convert_alias")
|
||||
self.assertFalse(log.content_changed)
|
||||
self.assertEqual(
|
||||
json.loads(log.data_json),
|
||||
log.data,
|
||||
{
|
||||
"page": {
|
||||
"id": self.alias_page.id,
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import json
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
@ -78,7 +76,7 @@ class TestConvertAlias(TestCase, WagtailTestUtils):
|
|||
log = PageLogEntry.objects.get(action="wagtail.convert_alias")
|
||||
self.assertFalse(log.content_changed)
|
||||
self.assertEqual(
|
||||
json.loads(log.data_json),
|
||||
log.data,
|
||||
{
|
||||
"page": {
|
||||
"id": self.alias_page.id,
|
||||
|
|
|
@ -104,7 +104,7 @@ class Command(BaseCommand):
|
|||
PageLogEntry.objects.log_action(
|
||||
instance=revision.page.specific,
|
||||
action=action,
|
||||
data="",
|
||||
data={},
|
||||
revision=None if action == "wagtail.create" else revision,
|
||||
user=revision.user,
|
||||
timestamp=revision.created_at,
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# Generated by Django 4.0.2 on 2022-02-22 04:27
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def replace_empty_string_with_empty_object(apps, schema_editor):
|
||||
ModelLogEntry = apps.get_model("wagtailcore.ModelLogEntry")
|
||||
PageLogEntry = apps.get_model("wagtailcore.PageLogEntry")
|
||||
ModelLogEntry.objects.filter(data_json='""').update(data_json="{}")
|
||||
PageLogEntry.objects.filter(data_json='""').update(data_json="{}")
|
||||
|
||||
|
||||
def revert_empty_object_to_empty_string(apps, schema_editor):
|
||||
ModelLogEntry = apps.get_model("wagtailcore.ModelLogEntry")
|
||||
PageLogEntry = apps.get_model("wagtailcore.PageLogEntry")
|
||||
ModelLogEntry.objects.filter(data_json="{}").update(data_json='""')
|
||||
PageLogEntry.objects.filter(data_json="{}").update(data_json='""')
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("wagtailcore", "0067_alter_pagerevision_content_json"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
replace_empty_string_with_empty_object, revert_empty_object_to_empty_string
|
||||
),
|
||||
]
|
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 4.0.2 on 2022-02-24 04:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("wagtailcore", "0068_log_entry_empty_object"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="modellogentry",
|
||||
name="data_json",
|
||||
field=models.JSONField(blank=True, default=dict),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="pagelogentry",
|
||||
name="data_json",
|
||||
field=models.JSONField(blank=True, default=dict),
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name="modellogentry",
|
||||
old_name="data_json",
|
||||
new_name="data",
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name="pagelogentry",
|
||||
old_name="data_json",
|
||||
new_name="data",
|
||||
),
|
||||
]
|
|
@ -4,7 +4,6 @@ such as Page, but the definitions here should remain generic and not depend on t
|
|||
wagtail.core.models module or specific models such as Page.
|
||||
"""
|
||||
|
||||
import json
|
||||
from collections import defaultdict
|
||||
|
||||
from django.conf import settings
|
||||
|
@ -100,7 +99,7 @@ class BaseLogEntryManager(models.Manager):
|
|||
% (instance,)
|
||||
)
|
||||
|
||||
data = kwargs.pop("data", "")
|
||||
data = kwargs.pop("data", None) or {}
|
||||
title = kwargs.pop("title", None)
|
||||
if not title:
|
||||
title = self.get_instance_title(instance)
|
||||
|
@ -113,7 +112,7 @@ class BaseLogEntryManager(models.Manager):
|
|||
label=title,
|
||||
action=action,
|
||||
timestamp=timestamp,
|
||||
data_json=json.dumps(data),
|
||||
data=data,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
@ -151,7 +150,7 @@ class BaseLogEntry(models.Model):
|
|||
label = models.TextField()
|
||||
|
||||
action = models.CharField(max_length=255, blank=True, db_index=True)
|
||||
data_json = models.TextField(blank=True)
|
||||
data = models.JSONField(blank=True, default=dict)
|
||||
timestamp = models.DateTimeField(verbose_name=_("timestamp (UTC)"), db_index=True)
|
||||
uuid = models.UUIDField(
|
||||
blank=True,
|
||||
|
@ -224,16 +223,6 @@ class BaseLogEntry(models.Model):
|
|||
else:
|
||||
return _("system")
|
||||
|
||||
@cached_property
|
||||
def data(self):
|
||||
"""
|
||||
Provides deserialized data
|
||||
"""
|
||||
if self.data_json:
|
||||
return json.loads(self.data_json)
|
||||
else:
|
||||
return {}
|
||||
|
||||
@cached_property
|
||||
def object_verbose_name(self):
|
||||
model_class = self.content_type.model_class()
|
||||
|
|
Ładowanie…
Reference in New Issue