Created
February 6, 2010 00:07
-
-
Save mrts/296411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see http://groups.google.com/group/django-users/browse_thread/thread/259c1679ddaaceb8 | |
# for the problem and http://code.djangoproject.com/ticket/12780 for the admin/options.py patch | |
# required to get this working | |
from django.forms.util import ErrorList | |
class ClipAdmin(admin.ModelAdmin): | |
def formsets_are_valid(self, formsets, form, form_is_valid, instance, | |
request): | |
valid = super(ClipAdmin, self).formsets_are_valid(formsets, | |
form, form_is_valid, instance, request) | |
if not valid: | |
return False | |
is_approved = form.cleaned_data.get('is_approved') | |
base_language = form.cleaned_data.get('language') | |
valid = True | |
if base_language and is_approved: | |
# find the right formset | |
clipdescription_formset = filter( | |
lambda fset: fset.__class__.__name__ == 'ClipDescriptionFormFormSet', | |
formsets)[0] | |
valid = False | |
for form_cleaned_data in clipdescription_formset.cleaned_data: | |
# check for language matches in the formset | |
language = form_cleaned_data.get('language') | |
if language and language == base_language: | |
valid = True | |
break | |
if not valid: | |
msg = _("Cannot approve this clip without " | |
"having a description in English.") | |
clipdescription_formset._non_form_errors = ErrorList([msg]) | |
return valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment