Closed florianRepenn closed 3 weeks ago
@florianRepenn Thanks for reporting and submitting the fix!
Have you tested this? I believe the problem lies elsewhere. Maybe you can check?
Here container types are imported from the settings https://github.com/django-cms/djangocms-bootstrap4/blob/148ec5d851b9610d94a2afd1ec9fc64302a34f89/djangocms_bootstrap4/contrib/bootstrap4_grid/models.py#L53
This might need to be run through force_str
to make sure the lazy translations from the settings are resolved.
I might be wrong, of course. Can you share the traceback?
@fsbraun Thanks for replying so fast. I tested my fix by changing the file in my running application container and I got rid of the exception.
I just tested to wrap the line you provided in the force_str
function but that didn't has any effect. (Also not sure if I understood correct)
Here is the traceback:
Template error:
In template /usr/local/lib/python3.9/dist-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 26
__str__ returned non-string (type __proxy__)
16 : {{ field.label_tag }}
17 : {% if field.is_readonly %}
18 : <div class="readonly">{{ field.contents }}</div>
19 : {% else %}
20 : {{ field.field }}
21 : {% endif %}
22 : {% endif %}
23 : </div>
24 : {% if field.field.help_text %}
25 : <div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
26 : <div> {{ field.field.help_text|safe }} </div>
27 : </div>
28 : {% endif %}
29 : </div>
30 : {% endfor %}
31 : {% if not line.fields|length == 1 %}</div>{% endif %}
32 : </div>
33 : {% endfor %}
34 : </fieldset>
35 :
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.9/dist-packages/django/core/handlers/base.py", line 220, in _get_response
response = response.render()
File "/usr/local/lib/python3.9/dist-packages/django/template/response.py", line 111, in render
self.content = self.rendered_content
File "/usr/local/lib/python3.9/dist-packages/django/template/response.py", line 89, in rendered_content
return template.render(context, self._request)
File "/usr/local/lib/python3.9/dist-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 175, in render
return self._render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/loader_tags.py", line 157, in render
return compiled_parent._render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/loader_tags.py", line 157, in render
return compiled_parent._render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/loader_tags.py", line 157, in render
return compiled_parent._render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/loader_tags.py", line 63, in render
result = block.nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/loader_tags.py", line 63, in render
result = block.nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/defaulttags.py", line 238, in render
nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/loader_tags.py", line 208, in render
return template.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 177, in render
return self._render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 167, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/defaulttags.py", line 238, in render
nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/defaulttags.py", line 238, in render
nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/defaulttags.py", line 321, in render
return nodelist.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in render
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1005, in <listcomp>
return SafeString("".join([node.render_annotated(context) for node in self]))
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 966, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 1064, in render
output = self.filter_expression.resolve(context)
File "/usr/local/lib/python3.9/dist-packages/django/template/base.py", line 742, in resolve
new_obj = func(obj, *arg_vals)
File "/usr/local/lib/python3.9/dist-packages/django/template/defaultfilters.py", line 47, in _dec
first = str(first)
Exception Type: TypeError at /de/admin/cms/page/add-plugin/
Exception Value: __str__ returned non-string (type __proxy__)
Ok, I seem to have been wrong here.
It is not good practice to use gettext
for model declarations, since anyone with a non-English setup will create migrations.
The next thing I noticed is that the container's help text was doubly lazy: mark_safe_lazy
on the outside and gettext_lazy
on the inside. I created a patch for your patch to fix this. Would you like to give it a try?
Yes of cause. I can test it in my setup. Where can I find it?
It should be a pr in your fork.
This works for me. I approved the PR and merged it.
@florianRepenn Welcome as a new django CMS contributor 🚀!! I'd be delighted if you joined our Discord group: https://discord-contributors-channel.django-cms.org/
Thanks a lot @fsbraun!
Description
Replacing gettext_lazy with gettext in djangocms_bootstrap4/contrib/bootstrap4_grid/models.py