Ticket #7517: site_delete.diff

File site_delete.diff, 1.1 KB (added by Marc Fargas, 16 years ago)

Remove Site from CACHE on delete.

  • django/contrib/sites/models.py

    diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
    index fb6d0a2..c928a4e 100644
    a b class Site(models.Model):  
    4444    def __unicode__(self):
    4545        return self.domain
    4646
     47    def delete(self):
     48        pk = self.pk
     49        super(Site, self).delete()
     50        try:
     51            del(SITE_CACHE[pk])
     52        except KeyError:
     53            pass
     54       
     55
    4756class RequestSite(object):
    4857    """
    4958    A class that shares the primary interface of Site (i.e., it has
  • new file django/contrib/sites/tests.py

    diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
    new file mode 100644
    index 0000000..d2ec331
    - +  
     1"""
     2>>> # Make sure that get_current() does not return a deleted Site object.
     3>>> from django.contrib.sites.models import Site
     4>>> s = Site.objects.get_current()
     5>>> s
     6<Site: example.com>
     7
     8>>> s.delete()
     9>>> Site.objects.get_current()
     10Traceback (most recent call last):
     11...
     12DoesNotExist: Site matching query does not exist.
     13"""
Back to Top