google-code-export / django-modeltranslation

Automatically exported from code.google.com/p/django-modeltranslation
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Admin: group translated fields in a fieldset #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I found it useful to group the translated fields together in a fieldset to keep 
clutter down on models with a fair number of non-translated fields.

Here's the commit in my fork: 
http://github.com/acdha/django-modeltranslation/commit/18d9341986b796588340ec00f
38f320c26d0bda5

It won't touch a ModelAdmin which already has a fieldset, allowing the user to 
override if this is not desirable.

Original issue reported on code.google.com by adamsc@gmail.com on 29 Jun 2010 at 6:25

GoogleCodeExporter commented 9 years ago
(btw: fully aware this is not a defect; I don't have permission to change the 
issue type)

Original comment by adamsc@gmail.com on 29 Jun 2010 at 6:28

GoogleCodeExporter commented 9 years ago

Original comment by eschler on 30 Jun 2010 at 8:25

GoogleCodeExporter commented 9 years ago
Doesn't seem to work for me (see error and traceback below).

Besides that, in general i would prefer to have features like this disabled by 
default and a setting in TranslationOptions to enable them, something like 
group_fields=True for this feature.

{{{
Template error:
In template 
/path/to/django/contrib/admin/templates/admin/includes/fieldset.html, error at 
line 6
   Caught AttributeError while rendering: 'NoneType' object has no attribute 'label'
   1 : <fieldset class="module aligned {{ fieldset.classes }}">

   2 :     {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}

   3 :     {% if fieldset.description %}

   4 :         <div class="description">{{ fieldset.description|safe }}</div>

   5 :     {% endif %}

   6 :      {% for line in fieldset %}

   7 :         <div class="form-row{% if line.errors %} errors{% endif %}{% for field in line %} {{ field.field.name }}{% endfor %}">

   8 :             {{ line.errors }}

   9 :             {% for field in line %}

   10 :                 <div{% if not line.fields|length_is:"1" %} class="field-box"{% endif %}>

   11 :                     {% if field.is_checkbox %}

   12 :                         {{ field.field }}{{ field.label_tag }}

   13 :                     {% else %}

   14 :                         {{ field.label_tag }}

   15 :                         {% if field.is_readonly %}

   16 :                             <p>{{ field.contents }}</p>

Traceback:
File "/path/to/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/path/to/django/contrib/admin/options.py" in wrapper
  239.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/path/to/django/utils/decorators.py" in _wrapped_view
  76.                     response = view_func(request, *args, **kwargs)
File "/path/to/django/views/decorators/cache.py" in _wrapped_view_func
  69.         response = view_func(request, *args, **kwargs)
File "/path/to/django/contrib/admin/sites.py" in inner
  190.             return view(request, *args, **kwargs)
File "/path/to/django/utils/decorators.py" in _wrapper
  21.             return decorator(bound_func)(*args, **kwargs)
File "/path/to/django/utils/decorators.py" in _wrapped_view
  76.                     response = view_func(request, *args, **kwargs)
File "/path/to/django/utils/decorators.py" in bound_func
  17.                 return func(self, *args2, **kwargs2)
File "/path/to/django/db/transaction.py" in _commit_on_success
  299.                     res = func(*args, **kw)
File "/path/to/django/contrib/admin/options.py" in change_view
  943.         return self.render_change_form(request, context, change=True, obj=obj)
File "/path/to/django/contrib/admin/options.py" in render_change_form
  634.         ], context, context_instance=context_instance)
File "/path/to/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/path/to/django/template/loader.py" in render_to_string
  186.     return t.render(context_instance)
File "/path/to/django/template/__init__.py" in render
  173.             return self._render(context)
File "/path/to/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/path/to/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/path/to/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/path/to/django/template/loader_tags.py" in render
  125.         return compiled_parent._render(context)
File "/path/to/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/path/to/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/path/to/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/path/to/django/template/loader_tags.py" in render
  125.         return compiled_parent._render(context)
File "/path/to/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/path/to/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/path/to/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/path/to/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "/path/to/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/path/to/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/path/to/django/template/defaulttags.py" in render
  167.                 nodelist.append(node.render(context))
File "/path/to/django/template/loader_tags.py" in render
  139.             return self.template.render(context)
File "/path/to/django/template/__init__.py" in render
  173.             return self._render(context)
File "/path/to/django/template/__init__.py" in _render
  167.         return self.nodelist.render(context)
File "/path/to/django/template/__init__.py" in render
  796.                 bits.append(self.render_node(node, context))
File "/path/to/django/template/debug.py" in render_node
  72.             result = node.render(context)
File "/path/to/django/template/defaulttags.py" in render
  167.                 nodelist.append(node.render(context))
File "/path/to/django/template/defaulttags.py" in render
  137.             values = list(values)
File "/path/to/django/contrib/admin/helpers.py" in __iter__
  106.                 yield AdminField(self.form, field, is_first=(i == 0))
File "/path/to/django/contrib/admin/helpers.py" in __init__
  113.         self.field = form[field] # A django.forms.BoundField instance
File "/path/to/django/forms/forms.py" in __getitem__
  107.         return BoundField(self, field, name)
File "/path/to/django/forms/forms.py" in __init__
  398.         if self.field.label is None:

Exception Type: TemplateSyntaxError at /admin/news/article/3/
Exception Value: Caught AttributeError while rendering: 'NoneType' object has 
no attribute 'label'
}}}

Original comment by eschler on 30 Jun 2010 at 9:09

GoogleCodeExporter commented 9 years ago
Which version of Django are you using? It's possible that a work-around might 
be needed for Django 1.1, which I no longer use.

I have an updated patch which turns the fieldset grouping off by default; 
setting TranslationOptions.group_fields = True will enable it.

http://github.com/acdha/django-modeltranslation/commit/cd91ff05b340ed0db6031095f
7a08114c474ae4d

Original comment by adamsc@gmail.com on 8 Jul 2010 at 1:02

GoogleCodeExporter commented 9 years ago
http://github.com/acdha/django-modeltranslation/commit/3ef3abe7a480ec45d7b302781
32eba2b92f62b95 has a documentation update describing the group_fields flag.

Original comment by adamsc@gmail.com on 9 Jul 2010 at 2:44

GoogleCodeExporter commented 9 years ago
The updated patch against the current SVN trunk is available here:

http://github.com/acdha/django-modeltranslation/commit/3179200423e7246ba528805a4
31dae3e5a046944

(all of my unmerged changes can be seen 
http://github.com/acdha/django-modeltranslation/compare/trunk...master)

Original comment by adamsc@gmail.com on 27 Aug 2010 at 2:48

GoogleCodeExporter commented 9 years ago
Hi,
The issue comes because the field is not editable.
Here's a pacth : 
https://github.com/hyperweek/django-modeltranslation/commit/91efab947f0c71fa5946
195254cae2e5217bd46d.
BTW, my fork is synced with official django-modeltranslation and acdha's fork.
Chhers,

Original comment by sebast...@hyperweek.com on 27 Jun 2011 at 3:05

GoogleCodeExporter commented 9 years ago
Project moved to Github. All issues have been migrated preserving their id. All 
remaining open issues on GoogleCode are closed. New project url: 
https://github.com/deschler/django-modeltranslation

Original comment by eschler on 22 Oct 2012 at 8:22