Commit 1fc0077a authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #7517 -- Added code to remove Sites from the site cache when they are...

Fixed #7517 -- Added code to remove Sites from the site cache when they are deleted. Thanks to Marc Fargas for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7724 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent b83fcacf
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -44,6 +44,15 @@ class Site(models.Model):
    def __unicode__(self):
        return self.domain

    def delete(self):
        pk = self.pk
        super(Site, self).delete()
        try:
            del(SITE_CACHE[pk])
        except KeyError:
            pass
        

class RequestSite(object):
    """
    A class that shares the primary interface of Site (i.e., it has
+13 −0
Original line number Diff line number Diff line
"""
>>> # Make sure that get_current() does not return a deleted Site object.
>>> from django.contrib.sites.models import Site
>>> s = Site.objects.get_current()
>>> s
<Site: example.com>

>>> s.delete()
>>> Site.objects.get_current()
Traceback (most recent call last):
...
DoesNotExist: Site matching query does not exist.
"""