Python django.utils.text 模块,camel_case_to_spaces() 实例源码
我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用django.utils.text.camel_case_to_spaces()。
def generate_handler_stub(router, handler_template=HANDLER_TEMPLATE):
output = StringIO()
func_name_to_operation = {}
for path in router.get_paths():
for operation in path.get_operations():
snake_operation_id = camel_case_to_spaces(operation.id).replace(' ', '_')
func_name_to_operation[snake_operation_id] = operation
for func_name, operation in sorted(func_name_to_operation.items()):
parameter_names = [p['name'] for p in operation.parameters]
handler = handler_template.format(
func_name=func_name,
operation_id=operation.id,
parameters=','.join(parameter_names),
)
output.write(handler)
output.write('\n\n\n')
return output.getvalue()
def generate_handler_stub(router,
)
output.write(handler)
output.write('\n\n\n')
return output.getvalue()
def snake_case(string):
return camel_case_to_spaces(string).replace(' ', '_')
def snake_case(string):
return camel_case_to_spaces(string).replace(' ', '_')
def __get__(self, instance, owner):
class Options(object):
model = owner
object_name = owner.__name__
model_name = owner.__name__.lower()
verbose_name = camel_case_to_spaces(owner.__name__)
class pk(object):
@classmethod
def value_to_string(cls, obj):
return str(obj.pk)
if instance:
Options.fields = [DynamicField(name=attr) for attr in instance._attrs]
return Options()
def captitle(title):
return capfirst(camel_case_to_spaces(title))
def contribute_to_class(self, cls, name):
from django.db import connection
from django.db.backends.utils import truncate_name
cls._Meta = self
self.model = cls
# First,construct the default values for these options.
self.object_name = cls.__name__
self.model_name = self.object_name.lower()
self.verbose_name = camel_case_to_spaces(self.object_name)
# Store the original user-defined values for each option,
# for use when serializing the model deFinition
self.original_attrs = {}
# Next,apply any overridden values from 'class Meta'.
if self.Meta:
Meta_attrs = self.Meta.__dict__.copy()
for name in self.Meta.__dict__:
# Ignore any private attributes that Django doesn't care about.
# NOTE: We can't modify a dictionary's contents while looping
# over it,so we loop over the *original* dictionary instead.
if name.startswith('_'):
del Meta_attrs[name]
for attr_name in DEFAULT_NAMES:
if attr_name in Meta_attrs:
setattr(self, attr_name, Meta_attrs.pop(attr_name))
self.original_attrs[attr_name] = getattr(self, attr_name)
elif hasattr(self.Meta, attr_name):
setattr(self, getattr(self.Meta, attr_name))
self.original_attrs[attr_name] = getattr(self, attr_name)
self.unique_together = normalize_together(self.unique_together)
self.index_together = normalize_together(self.index_together)
# verbose_name_plural is a special case because it uses a 's'
# by default.
if self.verbose_name_plural is None:
self.verbose_name_plural = string_concat(self.verbose_name, 's')
# order_with_respect_and ordering are mutually exclusive.
self._ordering_clash = bool(self.ordering and self.order_with_respect_to)
# Any leftover attributes must be invalid.
if Meta_attrs != {}:
raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(Meta_attrs.keys()))
else:
self.verbose_name_plural = string_concat(self.verbose_name, 's')
del self.Meta
# If the db_table wasn't provided,use the app_label + model_name.
if not self.db_table:
self.db_table = "%s_%s" % (self.app_label, self.model_name)
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
def contribute_to_class(self, attr_name)
self.unique_together = normalize_together(self.unique_together)
self.index_together = normalize_together(self.index_together)
# verbose_name_plural is a special case because it uses a 's'
# by default.
if self.verbose_name_plural is None:
self.verbose_name_plural = format_lazy('{}s', self.verbose_name)
# order_with_respect_and ordering are mutually exclusive.
self._ordering_clash = bool(self.ordering and self.order_with_respect_to)
# Any leftover attributes must be invalid.
if Meta_attrs != {}:
raise TypeError("'class Meta' got invalid attribute(s): %s" % ','.join(Meta_attrs.keys()))
else:
self.verbose_name_plural = format_lazy('{}s', self.verbose_name)
del self.Meta
# If the db_table wasn't provided, connection.ops.max_name_length())
def contribute_to_class(self, connection.ops.max_name_length())
def contribute_to_class(self, connection.ops.max_name_length())
def contribute_to_class(self, connection.ops.max_name_length())
def contribute_to_class(self, connection.ops.max_name_length())
def contribute_to_class(self, attr_name)
ut = Meta_attrs.pop('unique_together', self.unique_together)
self.unique_together = normalize_together(ut)
it = Meta_attrs.pop('index_together', self.index_together)
self.index_together = normalize_together(it)
# verbose_name_plural is a special case because it uses a 's'
# by default.
if self.verbose_name_plural is None:
self.verbose_name_plural = string_concat(self.verbose_name, 's')
# Any leftover attributes must be invalid.
if Meta_attrs != {}:
raise TypeError("'class Meta' got invalid attribute(s): %s" % ', connection.ops.max_name_length())
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。