[PATCH v3] Resolve removed 'AUTH_PROFILE_MODULE' setting
Stephen Finucane
stephenfinucane at hotmail.com
Mon Nov 24 00:48:21 AEDT 2014
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 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 +++++++-------
8 files changed, 19 insertions(+), 20 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})]
--
1.9.3
More information about the Patchwork
mailing list