Ticket #17750: 0001-User.get_profile-now-accepts-cached-argument-to-allo.patch

File 0001-User.get_profile-now-accepts-cached-argument-to-allo.patch, 2.4 KB (added by Renato Alves, 13 years ago)
  • django/contrib/auth/models.py

    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):  
    371371        """
    372372        send_mail(subject, message, from_email, [self.email])
    373373
    374     def get_profile(self):
     374    def get_profile(self, cached=True):
    375375        """
    376376        Returns site-specific profile for this user. Raises
    377377        SiteProfileNotAvailable if this site does not allow profiles.
    378378        """
    379         if not hasattr(self, '_profile_cache'):
     379        if not cached or not hasattr(self, '_profile_cache'):
    380380            from django.conf import settings
    381381            if not getattr(settings, 'AUTH_PROFILE_MODULE', False):
    382382                raise SiteProfileNotAvailable(
  • tests/regressiontests/multiple_database/tests.py

    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):  
    16291629        self.assertEqual(alice.get_profile().flavor, 'chocolate')
    16301630        self.assertEqual(bob.get_profile().flavor, 'crunchy frog')
    16311631
     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
    16321645class AntiPetRouter(object):
    16331646    # A router that only expresses an opinion on syncdb,
    16341647    # passing pets to the 'other' database
Back to Top