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

Fix non uid lookup for pages #138

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

easherma
Copy link
Contributor

@easherma easherma commented Jan 12, 2023

Fixes #133 and adds some test coverage, as well as some tweaks to the way some settings are initialized so that those tests can work

@easherma
Copy link
Contributor Author

See #132 for original discussion

Copy link
Member

@jacobtoppm jacobtoppm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this! Added a few questions (and a couple of obligatory nitpicks)

@@ -383,6 +394,7 @@ def _test_view(self, method, url, data=None, success_url=None):
with self.subTest(user=user):
self.client.login(username=user.username, password="password")
request = getattr(self.client, method)
breakpoint()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an accidental addition?

elif type(uid) == str:
# if lookup fields are configured for wagtailcore.page, then in the admin view those
# fields get passed along as a string
filters = dict(zip(self.fields, uid.split(",")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the lookup field value contains a ","?

@@ -150,6 +151,15 @@
'tests.category': ['name']
}

# some settings are modified in tests, in which case this caching interfers with the ability to test
# effectivley. Since settings are unlikely to change in the middle of usage in the real world,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: "interferes" and "effectively" typos

filters = dict(zip(self.fields, uid))
if type(uid) == tuple:
filters = dict(zip(self.fields, uid))
elif type(uid) == str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the last PR, I'm not sure whether this is the right approach - it feels like this method should accept a single type, and the caller (or another method, like we use when we get it from JSON with uid_from_json) should take care of conversion into a tuple. My thought is that currently, it looks like we put the uid into a single GET parameter here:

`${localCheckUIDUrl}?uid=${sourcePage.meta.uid}`
. That's why my previous request.GET.getlist() suggestion failed - we're not using the typical param=a&param=b GET syntax for passing a list. We could fix that and use getlist in the view, or else we could do the conversion to tuple in the view/in another method like uid_from_json. But just like the JSON case isn't in the main function, I don't think the list case should be either.

for model_label, fields in getattr(settings, 'WAGTAILTRANSFER_LOOKUP_FIELDS', {}).items():
LOOKUP_FIELDS[model_label.lower()] = fields

def get_lookup_fields():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth caching this as well? We'll work it out once per locator we look up, which feels a little redundant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding `'wagtailcore.page' to WAGTAILTRANSFER_LOOKUP_FIELDS causes error trying to match in admin
2 participants