pinax / pinax-project-teams

a starter project that has account management, profiles, teams and basic collaborative content.
20 stars 6 forks source link

Edit Profile link (/profile/edit/) results in AttributeError #3

Closed TCAllen07 closed 9 years ago

TCAllen07 commented 9 years ago

I'm working with an essentially "raw" copy of the pinax-project-teams project, and having created a single user (a superuser account as well) named "trevor" and logged in, trying to edit the user profile errors out.

Starting from /u// and clicking the "Edit Profile" button leads to /profile/edit/, which throws: AttributeError: 'User' object has no attribute 'get_profile', which is called from //profiles/views.py. I've included the stacktrace below, and can provide any of the info Django's debug capability provides (Request info & local vars, etc), just let me know.

I thought I'd try subclassing the django.contrib.auth.models.User object myself under project_name/project_name/profiles/models.py, but I'm rather new to Django and figure I'm likely to make it worse! ;-) But I'll probably play with it anyway, and update here if I figure anything out.

Environment:
Request Method: GET
Request URL: http://arx:8000/profile/edit/

Django Version: 1.7.5
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'bootstrapform',
 'pinax_theme_bootstrap',
 'account',
 'eventlog',
 'metron',
 'easy_thumbnails',
 'kaleo',
 'teams',
 'wiki',
 'zenithapp',
 'zenithapp.profiles')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "/home/trevor/zenithproject/webapp/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/trevor/zenithproject/webapp/env/local/lib/python2.7/site-packages/django/views/generic/base.py" in view
  69.             return self.dispatch(request, *args, **kwargs)
File "/home/trevor/zenithproject/webapp/env/local/lib/python2.7/site-packages/account/mixins.py" in dispatch
  17.             return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
File "/home/trevor/zenithproject/webapp/env/local/lib/python2.7/site-packages/django/views/generic/base.py" in dispatch
  87.         return handler(request, *args, **kwargs)
File "/home/trevor/zenithproject/webapp/env/local/lib/python2.7/site-packages/django/views/generic/edit.py" in get
  225.         self.object = self.get_object()
File "/home/trevor/zenithproject/webapp/zenithapp/zenithapp/profiles/views.py" in get_object
  18.         return self.request.user.get_profile()
File "/home/trevor/zenithproject/webapp/env/local/lib/python2.7/site-packages/django/utils/functional.py" in inner
  225.         return func(self._wrapped, *args)

Exception Type: AttributeError at /profile/edit/
Exception Value: 'User' object has no attribute 'get_profile'
TCAllen07 commented 9 years ago

The issue is just another incompatibility of this project with Django 1.7 ( I chronicled the initial installation issues in a StackOverflow post ). The user.get_profile() method is deprecated in 1.7. Two minor edits resolve this problem. First, in profiles.models.py replace the Profile-User relationship with a OneToOneField including a back-reference:

class Profile(models.Model):
    # user = models.ForeignKey(User)
    user = models.OneToOneField(User, related_name="profile")

Then in profiles.views.py, update the get_object() call like so:

class ProfileEditView(LoginRequiredMixin, UpdateView):
   # ... 
    def get_object(self):
        # return self.request.user.get_profile()
        return self.request.user.profile

I would make a pull request with the update, but I get the impression this particular repo isn't really being updated for Django 1.7. Rather it looks like pinax-project-account is replacing this 1.7 and onward.