38
def derivate_django_schema(schema, exclude=None):
39
"""Return a modified version of a schema.
41
The source schema *must* have a 'version' attribute and
44
The resulting schema is almost a copy of the original one, except
45
for excluded options in the 'django' section.
50
# create the schema class
51
cls = type(schema.__name__, (schema,), {'version': schema.version})
52
# include all non-excluded options
54
for option in schema().django.options():
55
if option.name in exclude:
57
options[option.name] = option
58
# create the 'django' section
59
django_section = type('django', (Section,), options)
60
setattr(cls, 'django', django_section)
35
64
class BaseDjangoSchema(Schema):
36
65
version = '1.0.2 final'
53
82
help="Whether to use the 'Etag' header. This saves bandwidth but "
54
83
"slows down performance.")
56
admins = ListOption(item=TupleOption(2), default=[],
85
admins = ListOption(item=TupleOption(length=2), default=[],
57
86
help="People who get code error notifications. In the format "
58
87
"(('Full Name', 'email@domain.com'), "
59
88
"('Full Name', 'anotheremail@domain.com'))")
696
739
date_input_formats = ListOption(
697
740
item=StringOption(),
699
'%%Y-%%m-%%d', '%%m/%%d/%%Y', '%%m/%%d/%%y', # '2006-10-25', '10/25/2006', '10/25/06'
700
'%%b %%d %%Y', '%%b %%d, %%Y', # 'Oct 25 2006', 'Oct 25, 2006'
701
'%%d %%b %%Y', '%%d %%b, %%Y', # '25 Oct 2006', '25 Oct, 2006'
702
'%%B %%d %%Y', '%%B %%d, %%Y', # 'October 25 2006', 'October 25, 2006'
703
'%%d %%B %%Y', '%%d %%B, %%Y', # '25 October 2006', '25 October, 2006'
742
'%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'
743
'%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006'
744
'%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006'
745
'%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006'
746
'%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006'
705
748
help="Default formats to be used when parsing dates from input "
706
749
"boxes, in order")
707
750
time_input_formats = ListOption(
708
751
item=StringOption(),
710
'%%H:%%M:%%S', # '14:30:59'
753
'%H:%M:%S', # '14:30:59'
713
756
help="Default formats to be used when parsing times from input "
714
757
"boxes, in order")
715
758
datetime_input_formats = ListOption(
716
759
item=StringOption(),
718
'%%Y-%%m-%%d %%H:%%M:%%S', # '2006-10-25 14:30:59'
719
'%%Y-%%m-%%d %%H:%%M', # '2006-10-25 14:30'
720
'%%Y-%%m-%%d', # '2006-10-25'
721
'%%m/%%d/%%Y %%H:%%M:%%S', # '10/25/2006 14:30:59'
722
'%%m/%%d/%%Y %%H:%%M', # '10/25/2006 14:30'
723
'%%m/%%d/%%Y', # '10/25/2006'
724
'%%m/%%d/%%y %%H:%%M:%%S', # '10/25/06 14:30:59'
725
'%%m/%%d/%%y %%H:%%M', # '10/25/06 14:30'
726
'%%m/%%d/%%y', # '10/25/06'
761
'%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59'
762
'%Y-%m-%d %H:%M', # '2006-10-25 14:30'
763
'%Y-%m-%d', # '2006-10-25'
764
'%m/%d/%Y %H:%M:%S', # '10/25/2006 14:30:59'
765
'%m/%d/%Y %H:%M', # '10/25/2006 14:30'
766
'%m/%d/%Y', # '10/25/2006'
767
'%m/%d/%y %H:%M:%S', # '10/25/06 14:30:59'
768
'%m/%d/%y %H:%M', # '10/25/06 14:30'
769
'%m/%d/%y', # '10/25/06'
728
771
help="Default formats to be used when parsing dates and times "
729
772
"from input boxes, in order")
884
931
('zh-tw', gettext_noop('Traditional Chinese')),
934
installed_apps = ListOption(item=StringOption(),
935
help="List of strings representing installed apps",
937
'django.contrib.auth',
938
'django.contrib.contenttypes',
939
'django.contrib.sessions',
940
'django.contrib.sites',
941
'django.contrib.messages',
942
'django.contrib.staticfiles',
887
945
template_context_processors = ListOption(
888
946
item=StringOption(),
889
947
help="List of processors used by RequestContext to populate the "
890
948
"context. Each one should be a callable that takes the request "
891
949
"object as its only parameter and returns a dictionary to add to "
894
952
'django.contrib.auth.context_processors.auth',
895
953
'django.core.context_processors.debug',
896
954
'django.core.context_processors.i18n',
1010
1065
self._schemas[version] = schema_cls
1012
1067
def get(self, version, strict=True):
1013
if version not in self._schemas:
1014
msg = "No schema registered for version %r" % version
1016
raise ValueError(msg)
1068
if version in self._schemas:
1069
return self._schemas[version]
1071
msg = "No schema registered for version %r" % version
1073
raise ValueError(msg)
1077
logging.warn("Dynamically creating schema for version %r" % version)
1078
schema = self.build(version)
1081
def build(self, version_string=None, options=None):
1082
if version_string is None:
1083
version_string = get_version()
1085
options = dict([(name.lower(), value) for (name, value) in
1086
inspect.getmembers(global_settings) if name.isupper()])
1087
project_options = dict([(name.lower(), value) for (name, value) in
1088
inspect.getmembers(project_settings) if name.isupper()])
1089
options.update(project_options)
1091
class DjangoSchema(Schema):
1092
version = version_string
1094
class django(Section):
1097
def get_option_type(name, value):
1105
unicode: StringOption,
1108
return StringOption(name=name, default=value, null=True)
1020
versions = sorted(self._schemas.keys())
1022
raise ValueError("No schemas registered")
1025
for v in sorted(self._schemas.keys()):
1030
logging.warn("Falling back to schema for version %r" % version)
1031
return self._schemas[version]
1110
option_type = type_mappings[type(value)]
1111
kwargs = {'name': name, 'default': value}
1113
if option_type in (DictOption, ListOption):
1114
# get inner item type
1115
if option_type == DictOption:
1116
items = value.values()
1122
item_type = type_mappings.get(type(items[0]), None)
1123
# make sure all items have a consistent type
1125
current_item_type = type_mappings.get(
1127
if current_item_type != item_type:
1129
# mismatching types found. fallback to default
1132
if item_type is not None:
1133
kwargs['item'] = item_type()
1135
return option_type(**kwargs)
1137
for name, value in options.items():
1138
if name == '__CONFIGGLUE_PARSER__':
1140
option = get_option_type(name, value)
1141
setattr(DjangoSchema.django, name, option)
1143
# register schema for it to be available during next query
1144
self.register(DjangoSchema, version_string)
1034
1148
schemas = DjangoSchemaFactory()