]> git.ozlabs.org Git - patchwork/commitdiff
Resolve removed 'AUTH_PROFILE_MODULE' setting
authorStephen Finucane <stephenfinucane@hotmail.com>
Tue, 7 Apr 2015 21:20:48 +0000 (22:20 +0100)
committerJeremy Kerr <jk@ozlabs.org>
Sun, 3 May 2015 05:46:52 +0000 (13:46 +0800)
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@hotmail.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
13 files changed:
apps/patchwork/filters.py
apps/patchwork/forms.py
apps/patchwork/models.py
apps/patchwork/paginator.py
apps/patchwork/tests/test_bundles.py
apps/patchwork/tests/utils.py
apps/patchwork/views/project.py
apps/patchwork/views/user.py
apps/settings.py
templates/base.html
templates/patchwork/patch.html
templates/patchwork/profile.html
templates/patchwork/project.html

index 8323fe86a0fe5549701646b5bbda75ee5cf82f74..8c9690eeaf22de4fbe152354ce1bdccea946cc8e 100644 (file)
@@ -350,11 +350,11 @@ class DelegateFilter(Filter):
 
     def condition(self):
         if self.delegate:
 
     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):
         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">'
                 self.filters.project)
 
         str = '<select name="delegate">'
@@ -378,7 +378,7 @@ class DelegateFilter(Filter):
                 selected = ' selected'
 
             str += '<option %s value="%s">%s</option>' % (selected,
                 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)
         str += '</select>'
 
         return mark_safe(str)
index 82197696588b3ced6f8a86bf71e7db18d8e0dc4b..03279588a1ef40d045bb02982a49dbed17d6c24e 100644 (file)
@@ -89,7 +89,7 @@ class DeleteBundleForm(forms.Form):
 
 class DelegateField(forms.ModelChoiceField):
     def __init__(self, project, *args, **kwargs):
 
 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)
                 UserProfile.objects \
                         .filter(maintainer_projects = project) \
                         .values('pk').query)
index 4bed9b8b2b526ecca4c5ea613b59048a3b7ea456..54b86566d7bd9a07b0dabb18c978b3d9b44f01f1 100644 (file)
@@ -41,7 +41,7 @@ class Person(models.Model):
             return self.email
 
     def link_to_user(self, user):
             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:
         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
     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):
 
     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')
     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)
 
                                             submitter__in = submitters)
                                         .values('project_id').query)
 
-
     def sync_person(self):
         pass
 
     def sync_person(self):
         pass
 
@@ -121,7 +120,7 @@ class UserProfile(models.Model):
 
 def _user_saved_callback(sender, created, instance, **kwargs):
     try:
 
 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()
     except UserProfile.DoesNotExist:
         profile = UserProfile(user = instance)
     profile.save()
index 8d8be644efba4c1e6da8609712544b0505d3fdfd..31c01905289bdd3422e70e3734c228e39ef9c6e8 100644 (file)
@@ -37,7 +37,7 @@ class Paginator(paginator.Paginator):
         patches_per_page = settings.DEFAULT_PATCHES_PER_PAGE
 
         if request.user.is_authenticated():
         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:
 
         n = request.META.get('ppp')
         if n:
index 5e8b95ba92f7fafd3dcda2f04698b0c731133275..38f3a2c48a39bf69d265b40e52ec44ff16f3d05c 100644 (file)
@@ -193,7 +193,7 @@ class BundleMaintainerUpdateTest(BundleUpdateTest):
 
     def setUp(self):
         super(BundleMaintainerUpdateTest, self).setUp()
 
     def setUp(self):
         super(BundleMaintainerUpdateTest, self).setUp()
-        profile = self.user.get_profile()
+        profile = self.user.profile
         profile.maintainer_projects.add(defaults.project)
         profile.save()
 
         profile.maintainer_projects.add(defaults.project)
         profile.save()
 
index c36b6c12555b90f8c03f63f35e9bd2c5d76fd172..782ed369cca0254a80d20abd5a90b7a70c3f614d 100644 (file)
@@ -79,7 +79,7 @@ def create_user():
 
 def create_maintainer(project):
     user = 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
     profile.maintainer_projects.add(project)
     profile.save()
     return user
index 05f0912f09d52f9ab8ab4b7d49c25269fd293639..114dbe07dae7f9828c70564eb4794b3e92c3ee71 100644 (file)
@@ -29,7 +29,7 @@ def project(request, project_id):
     context.project = project
 
     context['maintainers'] = User.objects.filter( \
     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,
     context['n_patches'] = Patch.objects.filter(project = project,
             archived = False).count()
     context['n_archived_patches'] = Patch.objects.filter(project = project,
index a9d6c4c67f8bc0abf45a0c26ea042fd5cc6aae80..126ecc95c4ca27444aff1721271baf648fd0a0a3 100644 (file)
@@ -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,
         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()
 
     person.user = conf.user
     person.save()
 
@@ -97,14 +97,14 @@ def profile(request):
     context = PatchworkRequestContext(request)
 
     if request.method == 'POST':
     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:
                 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
 
     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():
     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
 
         if not patches.count():
             continue
 
@@ -195,13 +195,13 @@ def todo_lists(request):
 
     context = PatchworkRequestContext(request)
     context['todo_lists'] = todo_lists
 
     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)
     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})]
 
     filter_settings = [(DelegateFilter,
             {'delegate': request.user})]
 
index e663c48cc50426d818bf71b66c4c62129db0d38d..379fbc5128771a43e6a5ac17adf477604ce9c977 100644 (file)
@@ -86,8 +86,6 @@ TEMPLATE_CONTEXT_PROCESSORS = (
     "django.core.context_processors.i18n",
     "django.core.context_processors.media")
 
     "django.core.context_processors.i18n",
     "django.core.context_processors.media")
 
-AUTH_PROFILE_MODULE = "patchwork.userprofile"
-
 INSTALLED_APPS = (
     'django.contrib.auth',
     'django.contrib.contenttypes',
 INSTALLED_APPS = (
     'django.contrib.auth',
     'django.contrib.contenttypes',
index 56091b4545161de508e969f32a5ca7eef2a19d21..f04d6e1e781df5b15a4d1fc227d56a0f880068ae 100644 (file)
@@ -22,7 +22,7 @@
      ><strong>{{ user.username }}</strong></a>
     <br/>
      <a href="{% url 'patchwork.views.user.todo_lists' %}">todo
      ><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> ::
      <a href="{% url 'patchwork.views.bundle.bundles' %}">bundles</a>
      <br/>
      <a href="{% url 'patchwork.views.user.profile' %}">profile</a> ::
index be831e9c31f551d429d27333556199d0b8fbac32..f18ee3b789e92de900f4814a79fb90027c693f03 100644 (file)
@@ -68,7 +68,7 @@ function toggle_headers(link_id, headers_id)
 {% if patch.delegate %}
   <tr>
    <th>Delegated to:</th>
 {% if patch.delegate %}
   <tr>
    <th>Delegated to:</th>
-   <td>{{ patch.delegate.get_profile.name }}</td>
+   <td>{{ patch.delegate.profile.name }}</td>
   </tr>
 {% endif %}
  <tr>
   </tr>
 {% endif %}
  <tr>
index 624efe294a912772078b85694041044774ccc612..116d6d63bfdf575bb6f903b8832b1293327cea10 100644 (file)
@@ -7,16 +7,16 @@
 {% block body %}
 
 <p>
 {% block body %}
 
 <p>
-{% if user.get_profile.maintainer_projects.count %}
+{% if user.profile.maintainer_projects.count %}
 Maintainer of
 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 %}
 
 <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
 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 %}
 <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>
 <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
  <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>
 {% else %}
  <p>Your todo list contains patches that have been delegated to you. You
   have no items in your todo list at present.</p>
index 73e85df9aab9a19ed79cab7724fd815a2c79f915..be8cadc1f99096630cefe50be7fbee6153073b89 100644 (file)
@@ -18,7 +18,7 @@
   <th>Maintainer{{maintainers|length|pluralize}}</th>
   <td>
    {% for maintainer in maintainers %}
   <th>Maintainer{{maintainers|length|pluralize}}</th>
   <td>
    {% for maintainer in maintainers %}
-    {{ maintainer.get_profile.name }}
+    {{ maintainer.profile.name }}
      &lt;<a href="mailto:{{maintainer.email}}">{{maintainer.email}}</a>&gt;
      <br />
    {% endfor %}
      &lt;<a href="mailto:{{maintainer.email}}">{{maintainer.email}}</a>&gt;
      <br />
    {% endfor %}