[v4 1/5] Resolve removed 'AUTH_PROFILE_MODULE' setting

Stephen Finucane stephenfinucane at hotmail.com
Mon Mar 23 08:03:19 AEDT 2015


The 'AUTH_PROFILE_MODULE' setting, and the 'get_profile()' method on
the 'User' model are removed in Django 1.7. This causes errors when
using Patchwork with Django 1.7+.

There are three changes necessary:

 * Replace profile model's 'ForeignKey' with a 'OneToOneField'
 * Remove all 'get_profile()' calls
 * Delete 'AUTH_PROFILE_MODULE' settings from 'settings.py'

These changes are discussed here:

    http://deathofagremmie.com/2014/05/24/retiring-get-profile-and-auth-profile-module/

Django 1.6 also introduces two other notable changes:

 * The 'XViewMiddleware' module has been moved
 * A new test runner has been introduced

It is not possible to fix these issues without breaking compatibility
with Django 1.5. As a result they have been ignored and must be
resolved in a future release.

Signed-off-by: Stephen Finucane <stephenfinucane at hotmail.com>
---
Changes for v4:
 - Remove final references to 'get_profile'
 - Remove 'AUTH_PROFILE_MODULE' setting as it no longer affects unit
   tests due to above.
Changes for v3:
 - Update references to 'UserProfile' fields
 - Readd 'AUTH_PROFILE_MODULE' setting. It's not used, but removing it
   breaks unit tests.
Changes for v2:
 - Remove mistakenly included changes to non-'UserProfile' models
---
 apps/patchwork/filters.py            |  6 +++---
 apps/patchwork/forms.py              |  2 +-
 apps/patchwork/models.py             |  9 ++++-----
 apps/patchwork/paginator.py          |  2 +-
 apps/patchwork/tests/test_bundles.py |  2 +-
 apps/patchwork/tests/utils.py        |  2 +-
 apps/patchwork/views/project.py      |  2 +-
 apps/patchwork/views/user.py         | 14 +++++++-------
 apps/settings.py                     |  2 --
 templates/base.html                  |  2 +-
 templates/patchwork/patch.html       |  2 +-
 templates/patchwork/profile.html     | 14 +++++++-------
 templates/patchwork/project.html     |  2 +-
 13 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/apps/patchwork/filters.py b/apps/patchwork/filters.py
index 8323fe8..8c9690e 100644
--- a/apps/patchwork/filters.py
+++ b/apps/patchwork/filters.py
@@ -350,11 +350,11 @@ class DelegateFilter(Filter):
 
     def condition(self):
         if self.delegate:
-            return self.delegate.get_profile().name()
+            return self.delegate.profile.name()
         return self.no_delegate_str
 
     def _form(self):
-        delegates = User.objects.filter(userprofile__maintainer_projects =
+        delegates = User.objects.filter(profile__maintainer_projects =
                 self.filters.project)
 
         str = '<select name="delegate">'
@@ -378,7 +378,7 @@ class DelegateFilter(Filter):
                 selected = ' selected'
 
             str += '<option %s value="%s">%s</option>' % (selected,
-                    d.id, d.get_profile().name())
+                    d.id, d.profile.name())
         str += '</select>'
 
         return mark_safe(str)
diff --git a/apps/patchwork/forms.py b/apps/patchwork/forms.py
index 8219769..0327958 100644
--- a/apps/patchwork/forms.py
+++ b/apps/patchwork/forms.py
@@ -89,7 +89,7 @@ class DeleteBundleForm(forms.Form):
 
 class DelegateField(forms.ModelChoiceField):
     def __init__(self, project, *args, **kwargs):
-        queryset = User.objects.filter(userprofile__in = \
+        queryset = User.objects.filter(profile__in = \
                 UserProfile.objects \
                         .filter(maintainer_projects = project) \
                         .values('pk').query)
diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py
index 4bed9b8..54b8656 100644
--- a/apps/patchwork/models.py
+++ b/apps/patchwork/models.py
@@ -41,7 +41,7 @@ class Person(models.Model):
             return self.email
 
     def link_to_user(self, user):
-        self.name = user.get_profile().name()
+        self.name = user.profile.name()
         self.user = user
 
     class Meta:
@@ -63,14 +63,14 @@ class Project(models.Model):
     def is_editable(self, user):
         if not user.is_authenticated():
             return False
-        return self in user.get_profile().maintainer_projects.all()
+        return self in user.profile.maintainer_projects.all()
 
     class Meta:
         ordering = ['linkname']
 
 
 class UserProfile(models.Model):
-    user = models.ForeignKey(User, unique = True)
+    user = models.OneToOneField(User, unique = True, related_name='profile')
     primary_project = models.ForeignKey(Project, null = True, blank = True)
     maintainer_projects = models.ManyToManyField(Project,
             related_name = 'maintainer_project')
@@ -94,7 +94,6 @@ class UserProfile(models.Model):
                                             submitter__in = submitters)
                                         .values('project_id').query)
 
-
     def sync_person(self):
         pass
 
@@ -121,7 +120,7 @@ class UserProfile(models.Model):
 
 def _user_saved_callback(sender, created, instance, **kwargs):
     try:
-        profile = instance.get_profile()
+        profile = instance.profile
     except UserProfile.DoesNotExist:
         profile = UserProfile(user = instance)
     profile.save()
diff --git a/apps/patchwork/paginator.py b/apps/patchwork/paginator.py
index 8d8be64..31c0190 100644
--- a/apps/patchwork/paginator.py
+++ b/apps/patchwork/paginator.py
@@ -37,7 +37,7 @@ class Paginator(paginator.Paginator):
         patches_per_page = settings.DEFAULT_PATCHES_PER_PAGE
 
         if request.user.is_authenticated():
-            patches_per_page = request.user.get_profile().patches_per_page
+            patches_per_page = request.user.profile.patches_per_page
 
         n = request.META.get('ppp')
         if n:
diff --git a/apps/patchwork/tests/test_bundles.py b/apps/patchwork/tests/test_bundles.py
index 5e8b95b..38f3a2c 100644
--- a/apps/patchwork/tests/test_bundles.py
+++ b/apps/patchwork/tests/test_bundles.py
@@ -193,7 +193,7 @@ class BundleMaintainerUpdateTest(BundleUpdateTest):
 
     def setUp(self):
         super(BundleMaintainerUpdateTest, self).setUp()
-        profile = self.user.get_profile()
+        profile = self.user.profile
         profile.maintainer_projects.add(defaults.project)
         profile.save()
 
diff --git a/apps/patchwork/tests/utils.py b/apps/patchwork/tests/utils.py
index c36b6c1..782ed36 100644
--- a/apps/patchwork/tests/utils.py
+++ b/apps/patchwork/tests/utils.py
@@ -79,7 +79,7 @@ def create_user():
 
 def create_maintainer(project):
     user = create_user()
-    profile = user.get_profile()
+    profile = user.profile
     profile.maintainer_projects.add(project)
     profile.save()
     return user
diff --git a/apps/patchwork/views/project.py b/apps/patchwork/views/project.py
index 05f0912..114dbe0 100644
--- a/apps/patchwork/views/project.py
+++ b/apps/patchwork/views/project.py
@@ -29,7 +29,7 @@ def project(request, project_id):
     context.project = project
 
     context['maintainers'] = User.objects.filter( \
-            userprofile__maintainer_projects = project)
+            profile__maintainer_projects = project)
     context['n_patches'] = Patch.objects.filter(project = project,
             archived = False).count()
     context['n_archived_patches'] = Patch.objects.filter(project = project,
diff --git a/apps/patchwork/views/user.py b/apps/patchwork/views/user.py
index a9d6c4c..126ecc9 100644
--- a/apps/patchwork/views/user.py
+++ b/apps/patchwork/views/user.py
@@ -86,7 +86,7 @@ def register_confirm(request, conf):
         person = Person.objects.get(email__iexact = conf.user.email)
     except Person.DoesNotExist:
         person = Person(email = conf.user.email,
-                name = conf.user.get_profile().name())
+                name = conf.user.profile.name())
     person.user = conf.user
     person.save()
 
@@ -97,14 +97,14 @@ def profile(request):
     context = PatchworkRequestContext(request)
 
     if request.method == 'POST':
-        form = UserProfileForm(instance = request.user.get_profile(),
+        form = UserProfileForm(instance = request.user.profile,
                 data = request.POST)
         if form.is_valid():
             form.save()
     else:
-        form = UserProfileForm(instance = request.user.get_profile())
+        form = UserProfileForm(instance = request.user.profile)
 
-    context.project = request.user.get_profile().primary_project
+    context.project = request.user.profile.primary_project
     context['bundles'] = Bundle.objects.filter(owner = request.user)
     context['profileform'] = form
 
@@ -184,7 +184,7 @@ def todo_lists(request):
     todo_lists = []
 
     for project in Project.objects.all():
-        patches = request.user.get_profile().todo_patches(project = project)
+        patches = request.user.profile.todo_patches(project = project)
         if not patches.count():
             continue
 
@@ -195,13 +195,13 @@ def todo_lists(request):
 
     context = PatchworkRequestContext(request)
     context['todo_lists'] = todo_lists
-    context.project = request.user.get_profile().primary_project
+    context.project = request.user.profile.primary_project
     return render_to_response('patchwork/todo-lists.html', context)
 
 @login_required
 def todo_list(request, project_id):
     project = get_object_or_404(Project, linkname = project_id)
-    patches = request.user.get_profile().todo_patches(project = project)
+    patches = request.user.profile.todo_patches(project = project)
     filter_settings = [(DelegateFilter,
             {'delegate': request.user})]
 
diff --git a/apps/settings.py b/apps/settings.py
index e663c48..379fbc5 100644
--- a/apps/settings.py
+++ b/apps/settings.py
@@ -86,8 +86,6 @@ TEMPLATE_CONTEXT_PROCESSORS = (
     "django.core.context_processors.i18n",
     "django.core.context_processors.media")
 
-AUTH_PROFILE_MODULE = "patchwork.userprofile"
-
 INSTALLED_APPS = (
     'django.contrib.auth',
     'django.contrib.contenttypes',
diff --git a/templates/base.html b/templates/base.html
index 56091b4..f04d6e1 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -22,7 +22,7 @@
      ><strong>{{ user.username }}</strong></a>
     <br/>
      <a href="{% url 'patchwork.views.user.todo_lists' %}">todo
-      ({{ user.get_profile.n_todo_patches }})</a> ::
+      ({{ user.profile.n_todo_patches }})</a> ::
      <a href="{% url 'patchwork.views.bundle.bundles' %}">bundles</a>
      <br/>
      <a href="{% url 'patchwork.views.user.profile' %}">profile</a> ::
diff --git a/templates/patchwork/patch.html b/templates/patchwork/patch.html
index c04e32b..96314ac 100644
--- a/templates/patchwork/patch.html
+++ b/templates/patchwork/patch.html
@@ -68,7 +68,7 @@ function toggle_headers(link_id, headers_id)
 {% if patch.delegate %}
   <tr>
    <th>Delegated to:</th>
-   <td>{{ patch.delegate.get_profile.name }}</td>
+   <td>{{ patch.delegate.profile.name }}</td>
   </tr>
 {% endif %}
  <tr>
diff --git a/templates/patchwork/profile.html b/templates/patchwork/profile.html
index 624efe2..116d6d6 100644
--- a/templates/patchwork/profile.html
+++ b/templates/patchwork/profile.html
@@ -7,16 +7,16 @@
 {% block body %}
 
 <p>
-{% if user.get_profile.maintainer_projects.count %}
+{% if user.profile.maintainer_projects.count %}
 Maintainer of
-{% for project in user.get_profile.maintainer_projects.all %}
+{% for project in user.profile.maintainer_projects.all %}
 <a href="{% url 'patchwork.views.patch.list' project_id=project.linkname %}"
 >{{ project.linkname }}</a>{% if not forloop.last %},{% endif %}{% endfor %}.
 {% endif %}
 
-{% if user.get_profile.contributor_projects.count %}
+{% if user.profile.contributor_projects.count %}
 Contributor to
-{% for project in user.get_profile.contributor_projects.all %}
+{% for project in user.profile.contributor_projects.all %}
 <a href="{% url 'patchwork.views.patch.list' project_id=project.linkname %}"
 >{{ project.linkname }}</a>{% if not forloop.last %},{% endif %}{% endfor %}.
 {% endif %}
@@ -25,10 +25,10 @@ Contributor to
 <div class="leftcol">
 <div class="box">
  <h2>Todo</h2>
-{% if user.get_profile.n_todo_patches %}
+{% if user.profile.n_todo_patches %}
  <p>Your <a href="{% url 'patchwork.views.user.todo_lists' %}">todo
-  list</a> contains {{ user.get_profile.n_todo_patches }}
-  patch{{ user.get_profile.n_todo_patches|pluralize:"es" }}.</p>
+  list</a> contains {{ user.profile.n_todo_patches }}
+  patch{{ user.profile.n_todo_patches|pluralize:"es" }}.</p>
 {% else %}
  <p>Your todo list contains patches that have been delegated to you. You
   have no items in your todo list at present.</p>
diff --git a/templates/patchwork/project.html b/templates/patchwork/project.html
index 73e85df..be8cadc 100644
--- a/templates/patchwork/project.html
+++ b/templates/patchwork/project.html
@@ -18,7 +18,7 @@
   <th>Maintainer{{maintainers|length|pluralize}}</th>
   <td>
    {% for maintainer in maintainers %}
-    {{ maintainer.get_profile.name }}
+    {{ maintainer.profile.name }}
      <<a href="mailto:{{maintainer.email}}">{{maintainer.email}}</a>>
      <br />
    {% endfor %}
-- 
2.1.0



More information about the Patchwork mailing list