From 9896102d29841ade96a736cc8718170162a90567 Mon Sep 17 00:00:00 2001
From: Renato Alves <rjalves@igc.gulbenkian.pt>
Date: Wed, 22 Feb 2012 19:45:09 +0000
Subject: [PATCH] User.get_profile() now accepts "cached" argument to allow
bypass of the cache.
---
django/contrib/auth/models.py | 4 ++--
tests/regressiontests/multiple_database/tests.py | 13 +++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index eb39868..3a745b0 100644
a
|
b
|
class User(models.Model):
|
371 | 371 | """ |
372 | 372 | send_mail(subject, message, from_email, [self.email]) |
373 | 373 | |
374 | | def get_profile(self): |
| 374 | def get_profile(self, cached=True): |
375 | 375 | """ |
376 | 376 | Returns site-specific profile for this user. Raises |
377 | 377 | SiteProfileNotAvailable if this site does not allow profiles. |
378 | 378 | """ |
379 | | if not hasattr(self, '_profile_cache'): |
| 379 | if not cached or not hasattr(self, '_profile_cache'): |
380 | 380 | from django.conf import settings |
381 | 381 | if not getattr(settings, 'AUTH_PROFILE_MODULE', False): |
382 | 382 | raise SiteProfileNotAvailable( |
diff --git a/tests/regressiontests/multiple_database/tests.py b/tests/regressiontests/multiple_database/tests.py
index e2f433e..34b7ce2 100644
a
|
b
|
class UserProfileTestCase(TestCase):
|
1629 | 1629 | self.assertEqual(alice.get_profile().flavor, 'chocolate') |
1630 | 1630 | self.assertEqual(bob.get_profile().flavor, 'crunchy frog') |
1631 | 1631 | |
| 1632 | alice_profile.flavor='chocolate stardust' |
| 1633 | alice_profile.save() |
| 1634 | |
| 1635 | bob_profile.flavor='crunchy frog bite' |
| 1636 | bob_profile.save() |
| 1637 | |
| 1638 | self.assertEqual(alice.get_profile().flavor, 'chocolate') |
| 1639 | self.assertEqual(alice.get_profile(cached=False).flavor, 'chocolate stardust') |
| 1640 | self.assertEqual(alice.get_profile().flavor, 'chocolate stardust') |
| 1641 | self.assertEqual(bob.get_profile().flavor, 'crunchy frog') |
| 1642 | self.assertEqual(bob.get_profile(cached=False).flavor, 'crunchy frog bite') |
| 1643 | self.assertEqual(bob.get_profile().flavor, 'crunchy frog bite') |
| 1644 | |
1632 | 1645 | class AntiPetRouter(object): |
1633 | 1646 | # A router that only expresses an opinion on syncdb, |
1634 | 1647 | # passing pets to the 'other' database |