magic-removal: Made django.db.models.options.default_names UPPERCASE and a tuple
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1739 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d828a40cb8
commit
f58e704341
|
@ -4,20 +4,18 @@ from django.db.models.fields import AutoField
|
||||||
from django.db.models.loading import get_installed_model_modules
|
from django.db.models.loading import get_installed_model_modules
|
||||||
from django.db.models.query import orderlist2sql
|
from django.db.models.query import orderlist2sql
|
||||||
from django.db.models.exceptions import FieldDoesNotExist
|
from django.db.models.exceptions import FieldDoesNotExist
|
||||||
|
|
||||||
from bisect import bisect
|
from bisect import bisect
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
# Calculate the module_name using a poor-man's pluralization.
|
# Calculate the module_name using a poor-man's pluralization.
|
||||||
get_module_name = lambda class_name: class_name.lower() + 's'
|
get_module_name = lambda class_name: class_name.lower() + 's'
|
||||||
|
|
||||||
# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
|
# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
|
||||||
get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip()
|
get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip()
|
||||||
|
|
||||||
|
DEFAULT_NAMES = ('module_name', 'verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
|
||||||
default_names = ['module_name','verbose_name','verbose_name_plural','db_table','ordering',
|
'unique_together', 'admin','where_constraints', 'exceptions', 'permissions',
|
||||||
'unique_together', 'admin','where_constraints', 'exceptions', 'permissions',
|
'get_latest_by','order_with_respect_to', 'module_constants')
|
||||||
'get_latest_by','order_with_respect_to', 'module_constants']
|
|
||||||
|
|
||||||
class Options:
|
class Options:
|
||||||
def __init__(self, meta):
|
def __init__(self, meta):
|
||||||
|
@ -36,17 +34,17 @@ class Options:
|
||||||
self.module_constants = {}
|
self.module_constants = {}
|
||||||
self.admin = None
|
self.admin = None
|
||||||
self.meta = meta
|
self.meta = meta
|
||||||
|
|
||||||
def merge_meta(self):
|
def merge_meta(self):
|
||||||
meta_attrs = self.meta.__dict__
|
meta_attrs = self.meta.__dict__
|
||||||
del meta_attrs['__module__']
|
del meta_attrs['__module__']
|
||||||
del meta_attrs['__doc__']
|
del meta_attrs['__doc__']
|
||||||
for attr_name in default_names:
|
for attr_name in DEFAULT_NAMES:
|
||||||
setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
|
setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name)))
|
||||||
if meta_attrs != {}:
|
if meta_attrs != {}:
|
||||||
raise TypeError, "'class META' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
|
raise TypeError, "'class META' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())
|
||||||
|
|
||||||
def contribute_to_class(self, cls, name):
|
def contribute_to_class(self, cls, name):
|
||||||
self.model = cls
|
self.model = cls
|
||||||
cls._meta = self
|
cls._meta = self
|
||||||
self.object_name = cls.__name__
|
self.object_name = cls.__name__
|
||||||
|
|
Loading…
Reference in New Issue