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

Post installation issue with manage.py #16

Open
webforge opened this issue Apr 5, 2017 · 2 comments
Open

Post installation issue with manage.py #16

webforge opened this issue Apr 5, 2017 · 2 comments

Comments

@webforge
Copy link

webforge commented Apr 5, 2017

Environment:

Django==1.10.6
wagtail==1.9

After setting up wagtailtinymce as per the instructions in README.md the following happens after trying to run ./manage.py makemigrations (or indeed any other subcommand, I reckon - haven't tested all subcommands).

Here are the last few lines of the stack trace:

  File "./venv/local/lib/python2.7/site-packages/wagtailtinymce/rich_text.py", line 66, in __init__
    self.kwargs = self.getDefaultArgs()
  File "./venv/local/lib/python2.7/site-packages/wagtailtinymce/rich_text.py", line 59, in getDefaultArgs
    'language': translation.to_locale(translation.get_language()),
  File "./venv/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 202, in to_locale
    return _trans.to_locale(language)
  File "./venv/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 71, in to_locale
    p = language.find('-')
AttributeError: 'NoneType' object has no attribute 'find'

After a little investigation, it appears that the language is not set properly in the getDefaultArgs method in class TinyMCERichTextArea in wagtailtinymce/rich_text.py.

To fix, I added an import statement for the project settings before the class is defined:

from django.conf import settings

and then in the definition for getDefaultArgs, I added the following before the return statement:

translation.trans_real.activate(settings.LANGUAGE_CODE)

All seems to work now, but I thought I should share the above and also ask is there a better way to resolve the issue than modifying the source code as above?

@ranihorev
Copy link

ranihorev commented May 20, 2017

Based on your solution, I found a better way to fix it (I think).

creating a new class based on TinyMCERichTextArea:

from django.utils import translation
from wagtailtinymce.rich_text import TinyMCERichTextArea
from django.conf import settings

class MyTinyMCE(TinyMCERichTextArea):
    def __init__(self, *args, **kwargs):
        translation.trans_real.activate(settings.LANGUAGE_CODE)
        super(MyTinyMCE, self).__init__(*args, **kwargs)

Referring the rich_text_editors to that class:

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'path_to_class.MyTinyMCE'
    },
}

Hope it'll help

@Krzypis
Copy link

Krzypis commented Aug 2, 2017

This is not solving this issue but not using tinyMCE as a default (in settings) also seemed to help to get rid of this error when migrating. So this works:

WAGTAILADMIN_RICH_TEXT_EDITORS = {
    'default': {
        'WIDGET': 'wagtail.wagtailadmin.rich_text.HalloRichTextArea'
    },
    'tinymce': {
        'WIDGET': 'wagtailtinymce.rich_text.TinyMCERichTextArea'
    },
}

edit: Although the above solution (from ranihorev) is better works as well.

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

No branches or pull requests

3 participants