• Members 2 posts
    April 26, 2019, 9:59 a.m.

    Hello i got this error. When i try in django console receive get_language() i get None

    File "/srv/misago/misago/threads/participants.py", line 151, in build_noticiation_email
    context={"settings": request.settings, "thread": thread},
    File "/srv/misago/misago/core/mail.py", line 15, in build_mail
    "LANGUAGE_CODE": get_language()[:2],
    TypeError: 'NoneType' object is not subscriptable

  • April 28, 2019, 8:19 p.m.

    Hi!

    How are you getting this error? Can you give detailed description of what you are entering in your console?

  • Members 2 posts
    April 30, 2019, 8:39 a.m.

    I want to create convertor from other forum engine to misago.
    When i create private message in script

    data variable contains json

    {"to":["admin"],"title":"title text","post":"message text","attachments":[]}
    

    script:

    request = RequestFactory().get(reverse("misago:private-threads"))
        request.cache_versions = get_cache_versions()
        request.settings = DynamicSettings(request.cache_versions)
        request.user = user
        request.user_acl = get_user_acl(request.user, request.cache_versions)
        request.method = "POST"
        request.POST = data
        request.data = request.POST
        request.user_ip = '127.0.0.1'
        thread = Thread()
        post = Post(thread=thread)
        user.lock()
        posting = PostingEndpoint(
            request,
            PostingEndpoint.START,
            tree_name=PRIVATE_THREADS_ROOT_NAME,
            thread=thread,
            post=post,
            datetime=timen,
        )
        posting.is_valid()
        posting.save()
    

    System create email and try to apply language (as i understand). But django function return None (instead 'en') so [:2] from none is error.
    in misago/core/mail.py

    I apply fix without changing in misago engine.

    from django.utils.translation import _trans
    _trans.get_language = lambda: 'en'
    

    But i think this is not norm practice.

  • April 30, 2019, 5:24 p.m.

    This is super weird way to do data migration. Any reason you can't create management command that reads data from other forum's database and then uses it to create Misago models? Here's example of such data migration that moves data from Misago 0.5 to Misago 0.6.


    As for your issue, Django requires that there's active language before any features using translations are used:

    from django.utils.translation import activate
    
    activate('en')