<s> from django . db import models <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . contenttypes import generic <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . dispatch import receiver <EOL> from django . db . models . signals import post_syncdb <EOL> from . moduleregistry import new_registry <EOL> from . import conf <EOL> class Model ( models . Model ) : <EOL> class Meta : <EOL> abstract = True <EOL> def __unicode__ ( self ) : <EOL> return u'<STR_LIT:%s>' % self . value <EOL> class SettingManager ( models . Manager ) : <EOL> def get_value ( self , name , ** kw ) : <EOL> if '<STR_LIT:default>' in kw : <EOL> if not self . value_object_exists ( name ) : <EOL> return kw . get ( '<STR_LIT:default>' ) <EOL> return self . get ( name = name ) . setting_object . value <EOL> def value_object_exists ( self , name ) : <EOL> queryset = self . filter ( name = name ) <EOL> return queryset . exists ( ) and queryset [ <NUM_LIT:0> ] . setting_object <EOL> def set_value ( self , name , SettingClass , value , validate = False ) : <EOL> setting = Setting ( name = name ) <EOL> if self . value_object_exists ( name ) : <EOL> setting = self . get ( name = name ) <EOL> setting_object = setting . setting_object <EOL> setting_object . delete ( ) <EOL> setting_object = SettingClass ( value = value ) <EOL> if validate : <EOL> setting_object . clean_fields ( ) <EOL> setting_object . save ( ) <EOL> setting . setting_object = setting_object <EOL> setting . save ( ) <EOL> return setting <EOL> class Setting ( models . Model ) : <EOL> class Meta : <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> objects = SettingManager ( ) <EOL> setting_type = models . ForeignKey ( ContentType ) <EOL> setting_id = models . PositiveIntegerField ( ) <EOL> setting_object = generic . GenericForeignKey ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> name = models . CharField ( max_length = <NUM_LIT:255> , unique = conf . DJANGO_SETTINGS_UNIQUE_NAMES ) <EOL> registry = new_registry ( __name__ ) <EOL> del new_registry <EOL> class Email ( Model ) : <EOL> value = models . EmailField ( ) <EOL> class Meta : <EOL> abstract = True <EOL> registry . register ( Email ) <EOL> class String ( Model ) : <EOL> value = models . CharField ( max_length = <NUM_LIT> ) <EOL> class Meta : <EOL> abstract = True <EOL> registry . register ( String ) <EOL> class Integer ( Model ) : <EOL> value = models . IntegerField ( ) <EOL> class Meta : <EOL> abstract = True <EOL> registry . register ( Integer ) <EOL> class PositiveInteger ( Model ) : <EOL> value = models . PositiveIntegerField ( ) <EOL> class Meta : <EOL> abstract = True <EOL> registry . register ( PositiveInteger ) <EOL> @ receiver ( post_syncdb ) <EOL> def handle_post_syncdb ( sender , ** kwargs ) : <EOL> from django_settings . dataapi import initialize_data <EOL> initialize_data ( ) </s>
