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

Error when loading in wagtailtrans own hooks #153

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

Conversation

OktayAltay
Copy link
Contributor

Thanks for contributing!

Hi, when using wagtailtrans in combination with a Wagtail Page model in a specific way will generate
the following error 'model object has no attribute 'get_translations'.

To reproduce this you only need to use wagtail trans and also having a page model for example called Article that uses Wagtails own Page model and not the TranslatablePage. That Article model must have a foreignkey field named language that is linked to wagtailtrans Language model.
To trigger the error you just have to go to the admin page and visit the Article page. Wagtail will then try loading wagtailtrans own hooks edit_in_language_button or page_translations_menu this is based on your settings. this will than generate that error.

@OktayAltay OktayAltay changed the title expand the if statement and add tests Error when loading in wagtailtrans own hooks Feb 10, 2019
@mikedingjan
Copy link
Member

In what case would you want a page to have a language object in your translated tree and not inherit from translatable page.. seems a bit weird too me when having a dutch tree to create an article in french right?

Can you elaborate a bit more on this issue?

@mikedingjan
Copy link
Member

Hi @OktayAltay ,

In PR #155 there is some work done to have a TranslatableMixin in the future, this would also make it possible to have other content translated via wagtailtrans, which would be really nice to have. However this change also allows you to not have the TranslatablePage so checking with issubclass() doesn't seem right to me.. Maybe you can explain why you would want to have pages with a relation to language while using wagtailtrans for the others?

@kaedroho
Copy link
Contributor

kaedroho commented Mar 1, 2019

We could change those lines to reference TranslatablePageMixin, which should work exactly the same.

Personally, I prefer the issubclass check as this won't be fooled if the class happens to have a "language" attribute, which could be added to a model for another reason (and doesn't have to be a relation to language).

@OktayAltay
Copy link
Contributor Author

I have swapped the isinstance with the issubclass check. @mikedingjan it is so that the check correctly handles non-wagtailtrans pages that happen to have a "language" field anyway. I realize that this is a pretty rare edge case, but that doesn't change the fact that it should work with models that have a 'language' field outside the wagtailtrans tree

@mikedingjan mikedingjan self-requested a review March 8, 2019 07:06
mikedingjan
mikedingjan previously approved these changes Mar 8, 2019
@mikedingjan mikedingjan self-requested a review March 8, 2019 07:11
@mikedingjan mikedingjan dismissed their stale review March 8, 2019 07:11

should update the tests

self.article = ArticleFactory()
self.transpage = TranslatablePage()

@hooks.register('register_page_listing_buttons')
Copy link
Member

Choose a reason for hiding this comment

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

Why are you defining this here? I think we can just import it right, just like the edit_in_language_button, now you're testing code which is defined in the test, seems a bit weird..


@pytest.mark.django_db
class TestWagtailHooks:
def setup(self):
Copy link
Member

Choose a reason for hiding this comment

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

We don't need the 2 pages created in the setup for each test, so lets just create the page we need in the test itself

@pytest.mark.django_db
class TestWagtailHooks:
def setup(self):
self.article = ArticleFactory()
Copy link
Member

Choose a reason for hiding this comment

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

The purpose of this ArticlePage is to have a page with a relation to language which doesn't extend from TranslatablePage right? so lets call it: NormalPageWithLanguage or something like that so we have a more clear view for what purpose this page is created

@@ -74,3 +77,35 @@ class WagtailPageFactory(factory.DjangoModelFactory):

class Meta:
model = Page

@classmethod
def _create(cls, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Don't think we need this since we're mostly using a pytest fixture when creating a site tree. Or is there any particular reason why you implemented this?

import factory
from factory.fuzzy import FuzzyDate
Copy link
Member

Choose a reason for hiding this comment

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

factory.fuzzy is deprecated according to the docs: https://factoryboy.readthedocs.io/en/latest/fuzzy.html

@@ -116,7 +115,7 @@ def edit_in_language_button(page, page_perms, is_parent=False):
clear interface to work in.

"""
if not hasattr(page, 'language'):
if not issubclass(page.__class__, TranslatablePage):
Copy link
Contributor

@kaedroho kaedroho Mar 8, 2019

Choose a reason for hiding this comment

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

I'm sorry, my last comment was misleading. I meant isinstance, as you had changed it just before, not sure why I said issubclass!

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

Successfully merging this pull request may close these issues.

None yet

4 participants