Skip to content

Commit

Permalink
Merge pull request #186 from apache/AIRAVATA-3698-fix-page-revision-c…
Browse files Browse the repository at this point in the history
…ontent-type

AIRAVATA-3698 management command to fix up the content type id in page revision json
  • Loading branch information
machristie authored Sep 25, 2023
2 parents 18cd1ab + dd41406 commit 75ff283
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 304 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import json

from django.core.management.base import BaseCommand
from wagtail.core.models import PageRevision


class Command(BaseCommand):
help = "Fix the content_type id in the page revisions content_type which may be correct due to being imported from a different Django instance"

def handle(self, **options):
fixed_count = 0
for pr in PageRevision.objects.all():
content_json = json.loads(pr.content_json)
if content_json['content_type'] != pr.page.content_type.id:
content_json['content_type'] = pr.page.content_type.id
pr.content_json = json.dumps(content_json)
pr.save()
fixed_count = fixed_count + 1
if fixed_count > 0:
self.stdout.write(
self.style.SUCCESS(f"Successfully fixed the content type of {fixed_count} page revisions")
)
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ def handle(self, **options):

call_command('loaddata', fixture_file, verbosity=0)
call_command('set_wagtail_site')
call_command('fix_page_revision_content_type')

print(f"{options['filename']} is loaded successfully....!")
self.stdout.write(
self.style.SUCCESS(f"{options['filename']} is loaded successfully....!")
)

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ def handle(self, **options):
if site_root is None:
raise Exception("Could not find site root page!")
else:
print(f"Setting root page to {site_root.title}")
self.stdout.write(f"Setting root page to {site_root.title}")
Site.objects.create(
hostname=hostname,
is_default_site=True,
site_name=settings.PORTAL_TITLE,
root_page=site_root
)
print(f"Created Site object for domain {hostname}")
self.stdout.write(f"Created Site object for domain {hostname}")
else:
print(f"Site object for domain {hostname} already exists")
self.stdout.write(f"Site object for domain {hostname} already exists")

def find_root_airavata_page(self, pages):
for page in pages:
Expand Down

0 comments on commit 75ff283

Please sign in to comment.