Commits

Anonymous committed 8aedf74 Draft

SOUTH remove longsettings table since it is pointless. all values might as well be text fields

Comments (0)

Files changed (5)

 .. Note::
     Superusers will have access to this setting without enabling any specific permissions
 
-Permissions for insert, delete or permission for longsetting are ignored and only the above-mentioned permission is used.
-
 Exporting Settings
 ------------------
 

livesettings/models.py

 
 log = logging.getLogger('configuration.models')
 
-__all__ = ['SettingNotSet', 'Setting', 'LongSetting', 'find_setting']
+__all__ = ['SettingNotSet', 'Setting', 'find_setting']
 
 try:
     is_site_initializing
     return siteid
 
 def find_setting(group, key, site=None):
-    """Get a setting or longsetting by group and key, cache and return it."""
+    """Get a setting by group and key, cache and return it."""
        
     siteid = _safe_get_siteid(site)
     setting = None
                     setting = Setting.objects.get(site__id__exact=siteid, key__exact=key, group__exact=group)
 
                 except Setting.DoesNotExist:
-                    # maybe it is a "long setting"
-                    try:
-                        setting = LongSetting.objects.get(site__id__exact=siteid, key__exact=key, group__exact=group)
-           
-                    except LongSetting.DoesNotExist:
-                        pass
+                    pass
             
                 cache_set(ck, value=setting)
 
     site = models.ForeignKey(Site, verbose_name=_('Site'))
     group = models.CharField(max_length=100, blank=False, null=False)
     key = models.CharField(max_length=100, blank=False, null=False)
-    value = models.CharField(max_length=255, blank=True)
+    value = models.TextField(blank=True)
 
     objects = SettingManager()
 
         
     class Meta:
         unique_together = ('site', 'group', 'key')
-
-
-class LongSettingManager(models.Manager):
-    def get_query_set(self):
-        all = super(LongSettingManager, self).get_query_set()
-        siteid = _safe_get_siteid(None)
-        return all.filter(site__id__exact=siteid)
-
-class LongSetting(models.Model, CachedObjectMixin):
-    """A Setting which can handle more than 255 characters"""
-    site = models.ForeignKey(Site, verbose_name=_('Site'))
-    group = models.CharField(max_length=100, blank=False, null=False)
-    key = models.CharField(max_length=100, blank=False, null=False)
-    value = models.TextField(blank=True)
-
-    objects = LongSettingManager()
-
-    def __nonzero__(self):
-        return self.id is not None
-
-    def cache_key(self, *args, **kwargs):
-        # note same cache pattern as Setting.  This is so we can look up in one check.
-        # they can't overlap anyway, so this is moderately safe.  At the worst, the 
-        # Setting will override a LongSetting.
-        return cache_key('Setting', self.site, self.group, self.key)
-
-    def delete(self):
-        self.cache_delete()
-        super(LongSetting, self).delete()
-
-    def save(self, force_insert=False, force_update=False):
-        try:
-            site = self.site
-        except Site.DoesNotExist:
-            self.site = Site.objects.get_current()
-        super(LongSetting, self).save(force_insert=force_insert, force_update=force_update)
-        self.cache_set()
-        
-    class Meta:
-        unique_together = ('site', 'group', 'key')
-    

livesettings/tests.py

 
         self.assertEqual(v, ['set a', 'set d'])
 
-class LongSettingTest(TestCase):
-    def setUp(self):
-        wide = config_register(LongStringValue(BASE_GROUP, 'LONG', ordering=1, default="woot"))
-        self.wide = wide
-        self.wide.update('*' * 1000)
-
-    def testLongStorage(self):
-        w = config_value('BASE', 'LONG')
-        self.assertEqual(len(w), 1000)
-        self.assertEqual(w, '*'*1000)
-
-    def testShortInLong(self):
-        self.wide.update("test")
-        w = config_value('BASE', 'LONG')
-        self.assertEqual(len(w), 4)
-        self.assertEqual(w, 'test')
-
-    def testDelete(self):
-        remember = self.wide.setting.id
-        self.wide.update('woot')
-
-        try:
-            LongSetting.objects.get(pk = remember)
-            self.fail("Should be deleted")
-        except LongSetting.DoesNotExist:
-            pass
-
 class OverrideTest(TestCase):
     """Test settings overrides"""
     def setUp(self):

livesettings/values.py

 from django.utils.encoding import smart_str
 from django.utils.safestring import mark_safe
 from django.utils.translation import gettext, ugettext_lazy as _
-from livesettings.models import find_setting, LongSetting, Setting, SettingNotSet
+from livesettings.models import find_setting, Setting, SettingNotSet
 from livesettings.overrides import get_overrides
 from livesettings.utils import load_module, is_string_like, is_list_or_tuple
 import datetime
                 return ''
         return new_value
 
-class LongStringValue(Value):
-
+class LongStringValue(StringValue):
     class field(forms.CharField):
         def __init__(self, *args, **kwargs):
             kwargs['required'] = False
             kwargs['widget'] = forms.Textarea()
             forms.CharField.__init__(self, *args, **kwargs)
 
-    def make_setting(self, db_value):
-        log.debug('new long setting %s.%s', self.group.key, self.key)
-        return LongSetting(group=self.group.key, key=self.key, value=db_value)
-
-    def to_python(self, value):
-        if value == NOTSET:
-            value = ""
-        return unicode(value)
-
-    to_editor = to_python
-
 class MultipleStringValue(Value):
 
     class field(forms.CharField):
     to_editor = to_python
 
 class LongMultipleStringValue(MultipleStringValue):
-    def make_setting(self, db_value):
-        log.debug('new long setting %s.%s', self.group.key, self.key)
-        return LongSetting(group=self.group.key, key=self.key, value=db_value)
+    """
+    Exists for backwards compatibility only
+    """
+    pass
 
 class ModuleValue(Value):
     """Handles setting modules, storing them as strings in the db."""

livesettings/views.py

 def export_as_python(request):
     """Export site settings as a dictionary of dictionaries"""
 
-    from livesettings.models import Setting, LongSetting
+    from livesettings.models import Setting
     import pprint
 
     work = {}
-    both = list(Setting.objects.all())
-    both.extend(list(LongSetting.objects.all()))
-
-    for s in both:
+    for s in Setting.objects.all():
         sitesettings = work.setdefault(s.site.id, {'DB': False, 'SETTINGS':{}})['SETTINGS']
         sitegroup = sitesettings.setdefault(s.group, {})
         sitegroup[s.key] = s.value