Mercurial > public > sg101
comparison gpp/core/models.py @ 2:f3ad863505bf
Got rid of the core.SiteConfig model and all usage.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 11 Apr 2009 17:57:22 +0000 |
parents | dbd703f7d63a |
children | 91fd31dc78fb |
comparison
equal
deleted
inserted
replaced
1:dbd703f7d63a | 2:f3ad863505bf |
---|---|
1 """ | 1 """ |
2 This file contains the core Models used in gpp. | 2 This file contains the core Models used in gpp. |
3 The SiteConfig information is cached in a similar manner to django.contrib.sites. | |
4 """ | 3 """ |
5 | 4 |
6 from django.db import models | 5 from django.db import models |
7 | |
8 SITE_CACHE = {} | |
9 | |
10 class SiteConfigManager(models.Manager): | |
11 def get_current(self): | |
12 """ | |
13 Returns the current SiteConfig based on the SITE_ID in the | |
14 project's settings. The SiteConfig object is cached the first | |
15 time it's retrieved from the database. | |
16 """ | |
17 from django.conf import settings | |
18 try: | |
19 sid = settings.SITE_ID | |
20 except AttributeError: | |
21 from django.core.exceptions import ImproperlyConfigured | |
22 raise ImproperlyConfigured("You're using the Django \"sites framework\" without having set the SITE_ID setting. " + | |
23 "Create a site in your database and set the SITE_ID setting to fix this error.") | |
24 try: | |
25 current_site_config = SITE_CACHE[sid] | |
26 except KeyError: | |
27 current_site_config = self.get(pk = sid) | |
28 SITE_CACHE[sid] = current_site_config | |
29 return current_site_config | |
30 | |
31 | |
32 def clear_cache(self): | |
33 """Clears the SiteConfig object cache.""" | |
34 global SITE_CACHE | |
35 SITE_CACHE = {} | |
36 | |
37 | |
38 class SiteConfig(models.Model): | |
39 """model to represent the site's basic configuration and settings""" | |
40 site_slogan = models.CharField(max_length = 128, blank = True) | |
41 admin_name = models.CharField(max_length = 64) | |
42 admin_email = models.EmailField() | |
43 date_created = models.DateField() | |
44 | |
45 objects = SiteConfigManager() | |
46 | |
47 | |
48 def __unicode__(self): | |
49 return u'SiteConfig ' + unicode(self.id) | |
50 | |
51 | |
52 def delete(self): | |
53 pk = self.pk | |
54 super(SiteConfig, self).delete() | |
55 try: | |
56 del(SITE_CACHE[pk]) | |
57 except KeyError: | |
58 pass | |
59 | 6 |
60 | 7 |
61 class DebugLog(models.Model): | 8 class DebugLog(models.Model): |
62 '''Model to represent debug logs used during development; arbitary text can be stored''' | 9 '''Model to represent debug logs used during development; arbitary text can be stored''' |
63 | 10 |