django-cms/djangocms-link

Exception is raised when copying internal links between languages

sephii opened this issue · 6 comments

If you create a link to a page in a language (eg. de) and your user has a different defined user language (by going to /admin/cms/usersettings/ and setting it eg. to en), you then get the following exception, because apparently get_language() then returns the user language instead of the current page language.

The same happens if a page in a given language contains a link plugin pointing to an internal page and a translation of this page is created and all plugins from the other language are copied.

Traceback (most recent call last):
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 177, in __call__
    response = self.get_response(request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 230, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 289, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/six.py", line 686, in reraise
    raise value
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 174, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/handlers/base.py", line 172, in get_response
    response = response.render()
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/response.py", line 160, in render
    self.content = self.rendered_content
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/response.py", line 137, in rendered_content
    content = template.render(context, self._request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 206, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader_tags.py", line 173, in render
    return compiled_parent._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/classytags/core.py", line 153, in render
    return self.render_tag(context, **kwargs)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/sekizai/templatetags/sekizai_tags.py", line 93, in render_tag
    rendered_contents = nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/classytags/core.py", line 153, in render
    return self.render_tag(context, **kwargs)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/cms/templatetags/cms_tags.py", line 499, in render_tag
    toolbar = render_to_string('cms/toolbar/toolbar.html', flatten_context(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader.py", line 97, in render_to_string
    return template.render(context, request)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 206, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/templatetags/i18n.py", line 190, in render
    output = self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 220, in render
    nodelist.append(node.render_annotated(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 220, in render
    nodelist.append(node.render_annotated(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader_tags.py", line 209, in render
    return template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 208, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 584, in render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 326, in render
    return nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 220, in render
    nodelist.append(node.render_annotated(context))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/loader_tags.py", line 209, in render
    return template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 208, in render
    return self._render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/test/utils.py", line 92, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/defaulttags.py", line 584, in render
    return self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/templatetags/i18n.py", line 190, in render
    output = self.nodelist.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 992, in render
    bit = node.render_annotated(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 959, in render_annotated
    return self.render(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 1043, in render
    output = self.filter_expression.resolve(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 709, in resolve
    obj = self.var.resolve(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 850, in resolve
    value = self._resolve_lookup(context)
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/template/base.py", line 913, in _resolve_lookup
    current = current()
  File "/home/vagrant/ENV/lib/python3.4/site-packages/djangocms_link/models.py", line 129, in get_short_description
    return '{} ({})'.format(self.name, self.get_link())
  File "/home/vagrant/ENV/lib/python3.4/site-packages/djangocms_link/models.py", line 140, in get_link
    link = self.internal_link.get_absolute_url()
  File "/home/vagrant/ENV/lib/python3.4/site-packages/cms/models/pagemodel.py", line 177, in get_absolute_url
    return reverse('pages-details-by-slug', kwargs={"slug": path})
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/urlresolvers.py", line 600, in reverse
    return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))
  File "/home/vagrant/ENV/lib/python3.4/site-packages/django/core/urlresolvers.py", line 508, in _reverse_with_prefix
    (lookup_view_s, args, kwargs, len(patterns), patterns))
django.core.urlresolvers.NoReverseMatch: Reverse for 'pages-details-by-slug' with arguments '()' and keyword arguments '{'slug': ''}' not found. 1 pattern(s) tried: ['en/(?P<slug>[0-9A-Za-z-_.//]+)/$']

@sephii would you be able to fix it and open up a pull request?

This is not related to django-cms/django-cms#5801. The issue I described here doesn't happen in the admin but on the frontend editing, because in the Structure mode the plugins are rendered using the user language (which can then use an untranslated version of the page).

sorry for the confusion here @sephii :)

Closing as it will be implemented directly into django CMS

Why are you rejecting a bugfix when it is not implemented in django CMS yet? It seems that this plugin is still actively maintained, or is it already deprecated?

@SteinRobert I'm closing it here as it should be tracked on the django CMS issues itself.