﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9360	Admin interface method get_form does not call get_fieldsets to get fieldsets	David Christiansen	nobody	"I'm presently limiting the fields that some users can edit in our admin interface by defining two fieldsets variables and then overriding get_fieldsets on the admin object to check for a user permission and return the right fieldsets.  It looks like this:

{{{
def get_fieldsets(self, request, obj=None):
    if request.user.has_perm('page.can_change_structure'):
        return self.fieldsets
    else:
        return self.fieldsets_content_only
}}}

However, the exluded fields were being set to blank whenever the form was submitted by a user with fewer privileges.  I tracked it down to the get_form method of ModelAdmin.  It gets the fieldsets as such: (starting on line 777)
{{{
if self.declared_fieldsets:
    fields = flatten_fieldsets(self.declared_fieldsets)
else:
    fields = None
}}}

This ignores the get_fieldsets method.  I'm not quite sure where the right place to fix this is, so I haven't written a patch.  For our use case, it worked to simply override the get_form method and replace the four lines above with:

{{{
fields = flatten_fieldsets(self.get_fieldsets(request, obj=obj))
}}}

Perhaps something similar would be the right solution overall?

We're running Django 1.0."		closed	contrib.admin	1.1		invalid	fieldsets form modelform permissions	domen@…	Unreviewed	0	0	0	0	0	0
