Skip to content

Conversation

qris
Copy link
Contributor

@qris qris commented Aug 14, 2014

We have a custom user model that has a full_name field instead of first_name and last_name.

When we set CMS_PERMISSION = True, the CMS breaks with this error:

File "/home/chris/dev/dfidbeamexchange/django/website/.ve/local/lib/python2.7/site-packages/django/contrib/admin/validation.py", line 251, in validate_list_display
% (cls.__name__, idx, field, cls.__name__, model._meta.object_name))

ImproperlyConfigured: PageUserAdmin.list_display[1], 'first_name' is not a callable or an attribute of 'PageUserAdmin' or found in the model 'PageUser'.

PageUserAdmin hard-codes the field list, which breaks it for us:

class PageUserAdmin(UserAdmin, GenericCmsPermissionAdmin):
    form = PageUserForm
    add_form = PageUserForm
    model = PageUser

    list_display = ('email', 'first_name', 'last_name', 'created_by')

What should we do here? Unregister PageUserAdmin and replace it with a custom one?

@mmarzantowicz
Copy link

@qris
Copy link
Contributor Author

qris commented Aug 13, 2014

Unfortunately that's not enough. It crashes during validating the models, which happens on import of cms.admin.useradmin (during autodiscover), not when the page is accessed. So we can't subclass the PageUserAdmin because we can't import it, or allow it to be imported.

@mmarzantowicz
Copy link

@qris
Copy link
Contributor Author

qris commented Aug 13, 2014

@mmarzantowicz so is your advice that we should submit a pull request to Django-CMS to change the list_display to include the REQUIRED_FIELDS instead of hard-coding the list of fields? Or did I misunderstand?

@mmarzantowicz
Copy link

This might be the best you can do. Quick fix might be not to use first_name and last_name but full_name instead. Can you play with it and see if it works before making PR? I do not currently have any installation with custom User model to play with.

@qris
Copy link
Contributor Author

qris commented Aug 14, 2014

OK, here's a pull request. I wasn't able yet to make a single test use a custom user model. The only way I could trigger a failure was to run the tests like this:

AUTH_USER_MODEL=customuserapp.User bin/python django-cms/develop.py test cms.AdminTestCase

I added such a test to the Travis configuration in 2eb9e84.

There are still problems with PageUserAdmin if your user model lacks some fields. Users will have to subclass it and change the fieldsets to include the fields that actually work, but at least they can import it now, so they can actually subclass it.

@digi604
Copy link
Contributor

digi604 commented Aug 14, 2014

mmmh strange test failures....

@qris
Copy link
Contributor Author

qris commented Aug 14, 2014

Test failures only on the custom user model build? I get test failures on trunk when I run tests locally even without my changes. Have you thought about using tox?

@digi604
Copy link
Contributor

digi604 commented Aug 14, 2014

no all tests fail.... locally we run it with python develop.py test

@digi604
Copy link
Contributor

digi604 commented Aug 14, 2014

yes we had a look at many different testing architectures over the year... PR with working implementation always welcome :)

@digi604
Copy link
Contributor

digi604 commented Aug 14, 2014

they fail on travis: https://travis-ci.org/divio/django-cms/builds/32526618

@yakky
Copy link
Member

yakky commented Oct 1, 2014

@qris: I'd like to merge this in 3.0.6 but current PR has too many extraneous commits.
Would you be able to create a clean PR against current develop?

@yakky yakky added this to the 3.0.6 milestone Oct 1, 2014
yakky and others added 2 commits October 2, 2014 00:32
Changing plugin delete template to fix error with django 1.7
Move to request.path_info to be more compatible
jsma and others added 19 commits October 3, 2014 21:27
Fixed initial migration for Page.template field choices
Fix resetting override url when editing basic settings
On single file modules (without __init__.py) `./manage.py cms check` fails with AttributeError: 'module' object has no attribute '__path__'

How to reproduce:

1. pip install feedparser
2. Add in settings.py: INSTALLED_APPS = INSTALLED_APPS + ('feedparser', )
3. Run ./manage.py cms check
Reset maximize classes when the drag handle is moved
…gration

Move remaining choices to be determined dynamically in the migrations
Fix fails on not packaged single file modules
Don't crash at startup if the custom user model has no first_name and
last_name fields.

The PageUserAdmin still won't actually work, so you'll have to subclass
it and change the fieldsets to include the fields that actually work, but
at least you can import it now.
Allows us to test whether PageUserAdmin works or not.
This conceals the original error that you actually want to fix.
@qris qris force-pushed the fix_custom_user_model_admin branch from 1c1be95 to 817f4ef Compare October 6, 2014 15:58
@qris
Copy link
Contributor Author

qris commented Oct 6, 2014

@yakky done

@yakky yakky closed this in #3483 Oct 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.