Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't convert app labels in config model IDs to lowercase #162

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions wagtail_transfer/field_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from .files import File, FileTransferError, get_file_hash, get_file_size
from .locators import get_locator_for_model
from .models import get_base_model, get_base_model_for_path
from .models import get_base_model, get_base_model_for_path, normalize_model_label
from .richtext import get_reference_handler
from .streamfield import get_object_references, update_object_ids

Expand All @@ -29,10 +29,10 @@

WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS = getattr(settings, "WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS", [('wagtailimages.image', 'tagged_items', True)])
FOLLOWED_REVERSE_RELATIONS = {
(model_label.lower(), relation.lower()) for model_label, relation, _ in WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS
(normalize_model_label(model_label), relation.lower()) for model_label, relation, _ in WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS
}
DELETED_REVERSE_RELATIONS = {
(model_label.lower(), relation.lower()) for model_label, relation, track_deletions in WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS if track_deletions
(normalize_model_label(model_label), relation.lower()) for model_label, relation, track_deletions in WAGTAILTRANSFER_FOLLOWED_REVERSE_RELATIONS if track_deletions
}
ADMIN_BASE_URL = getattr(
settings, "WAGTAILADMIN_BASE_URL",
Expand Down
4 changes: 2 additions & 2 deletions wagtail_transfer/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from django.core.exceptions import ImproperlyConfigured
from django.db import IntegrityError

from .models import IDMapping, get_base_model
from .models import IDMapping, get_base_model, normalize_model_label


logger = logging.getLogger(__name__)
Expand All @@ -27,7 +27,7 @@
'contenttypes.contenttype': ['app_label', 'model'],
}
for model_label, fields in getattr(settings, 'WAGTAILTRANSFER_LOOKUP_FIELDS', {}).items():
LOOKUP_FIELDS[model_label.lower()] = fields
LOOKUP_FIELDS[normalize_model_label(model_label)] = fields


class IDMappingLocator:
Expand Down
6 changes: 6 additions & 0 deletions wagtail_transfer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ def get_base_model_for_path(model_path):
(e.g. for 'blog.blog_page', return Page)
"""
return get_base_model(get_model_for_path(model_path))


def normalize_model_label(label):
app_label, model_name = label.rsplit('.', 1)
return "{}.{}".format(app_label, model_name.lower())

6 changes: 3 additions & 3 deletions wagtail_transfer/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from .field_adapters import adapter_registry
from .locators import get_locator_for_model
from .models import get_base_model, get_base_model_for_path, get_model_for_path
from .models import get_base_model, get_base_model_for_path, get_model_for_path, normalize_model_label


logger = logging.getLogger(__name__)
Expand All @@ -22,7 +22,7 @@
default_update_related_models = ['wagtailimages.image']

UPDATE_RELATED_MODELS = [
model_label.lower()
normalize_model_label(model_label)
for model_label in getattr(settings, 'WAGTAILTRANSFER_UPDATE_RELATED_MODELS', default_update_related_models)
]

Expand All @@ -31,7 +31,7 @@
default_no_follow_models = ['wagtailcore.page', 'contenttypes.contenttype']

NO_FOLLOW_MODELS = [
model_label.lower()
normalize_model_label(model_label)
for model_label in getattr(settings, 'WAGTAILTRANSFER_NO_FOLLOW_MODELS', default_no_follow_models)
]

Expand Down