Repository: translate/pootle

Issue:
Check 'delete' checkbox for a new entry renders error
_Version: 2.5.1_

_Originally posted by Mike Massonnet:_

_Imported from attachment 976:_

``` pytb
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 109, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python2.7/dist-packages/pootle/core/decorators.py", line 87, in wrapped
    return func(request, path_obj, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pootle/core/decorators.py", line 180, in _wrapped
    return func(request, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pootle/apps/pootle_project/views.py", line 427, in project_admin
    exclude=('description',))
  File "/usr/lib/python2.7/dist-packages/pootle/apps/pootle_app/views/admin/util.py", line 191, in edit
    queryset=queryset, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pootle/apps/pootle_app/views/admin/util.py", line 172, in process_modelformset
    if formset.is_valid():
  File "/usr/lib/python2.7/dist-packages/django/forms/formsets.py", line 272, in is_valid
    err = self.errors
  File "/usr/lib/python2.7/dist-packages/django/forms/formsets.py", line 250, in _get_errors
    self.full_clean()
  File "/usr/lib/python2.7/dist-packages/django/forms/formsets.py", line 293, in full_clean
    self._errors.append(form.errors)
  File "/usr/lib/python2.7/dist-packages/django/forms/forms.py", line 115, in _get_errors
    self.full_clean()
  File "/usr/lib/python2.7/dist-packages/django/forms/forms.py", line 272, in full_clean
    self._post_clean()
  File "/usr/lib/python2.7/dist-packages/django/forms/models.py", line 309, in _post_clean
    self.instance = construct_instance(self, self.instance, opts.fields, opts.exclude)
  File "/usr/lib/python2.7/dist-packages/django/forms/models.py", line 51, in construct_instance
    f.save_form_data(instance, cleaned_data[f.name])
  File "/usr/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 454, in save_form_data
    setattr(instance, self.name, data)
  File "/usr/lib/python2.7/dist-packages/django/db/models/fields/related.py", line 362, in __set__
    (instance._meta.object_name, self.field.name))
ValueError: Cannot assign None: "TranslationProject.language" does not allow null values.
```

_Created [attachment 976](http://bugs.locamotion.org/attachment.cgi?id=976)_

pootle-check-all-traceback.txt

Hello,

In the adminstration page of a project, checking the Delete checkbox for a new entry renders an error. This checkbox is also automatically selected when checking the Delete checkbox at the top of the form, to check all checkboxes.

The following error is rendered:
"Cannot assign None: "TranslationProject.language" does not allow null values."

See attached screenshots and traceback.

Regards,
Mike



Discussion:
_Originally posted by Mike Massonnet:_

_Created [attachment 977](http://bugs.locamotion.org/attachment.cgi?id=977)_

pootle-check-all-1.png

_Originally posted by Mike Massonnet:_

_Created [attachment 978](http://bugs.locamotion.org/attachment.cgi?id=978)_

pootle-check-all-2.png

This was fixed probably

Reopening since this is still not fixed.


Resolving patch:
diff --git a/pootle/apps/pootle_app/views/admin/util.py b/pootle/apps/pootle_app/views/admin/util.py
--- a/pootle/apps/pootle_app/views/admin/util.py
+++ b/pootle/apps/pootle_app/views/admin/util.py
@@ -7,6 +7,7 @@
 # or later license. See the LICENSE file for a copy of the license and the
 # AUTHORS file for copyright and authorship information.
 
+from django import forms
 from django.forms.models import modelformset_factory
 from django.forms.utils import ErrorList
 from django.shortcuts import render
@@ -110,6 +111,10 @@ def add_widgets(result, fields, form, link):
         result.append('</tfoot>\n')
 
         result.append('<tbody>\n')
+
+        # Do not display the delete checkbox for the 'add a new entry' form.
+        formset.forms[-1].fields['DELETE'].widget = forms.HiddenInput()
+
         for i, form in enumerate(formset.forms):
             add_errors(result, fields, form)
             add_widgets(result, fields, form, link)


Test patch: