本文整理汇总了Python中django.utils.text.camel_case_to_spaces方法的典型用法代码示例。如果您正苦于以下问题:Python text.camel_case_to_spaces方法的具体用法?Python text.camel_case_to_spaces怎么用?Python text.camel_case_to_spaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.text
的用法示例。
在下文中一共展示了text.camel_case_to_spaces方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate_handler_stub
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
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()
示例2: _update_from_name
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
def _update_from_name(self, name):
self.name = name
self.verbose_name = self.verbose_name or camel_case_to_spaces(name)
self.verbose_name_plural = self.verbose_name_plural or self.verbose_name + 's'
示例3: decamel
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
def decamel(value):
try:
return camel_case_to_spaces(value)
except:
return value
示例4: _update_from_name
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
def _update_from_name(self, name):
self.name = name
self.verbose_name = self.verbose_name or camel_case_to_spaces(name)
self.verbose_name_plural = (self.verbose_name_plural or
self.verbose_name + 's')
示例5: mutation_parameters
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
def mutation_parameters() -> dict:
dict_params = {
'login': LoginMutation.Field(),
'logout': LogoutMutation.Field(),
}
dict_params.update((camel_case_to_spaces(n).replace(' ', '_'), mut.Field())
for n, mut in registry.forms.items())
return dict_params
示例6: snake_case
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
def snake_case(string):
return camel_case_to_spaces(string).replace(' ', '_')
示例7: captitle
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
def captitle(title):
return capfirst(camel_case_to_spaces(title))
示例8: contribute_to_class
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
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, attr_name, getattr(self.meta, attr_name))
self.original_attrs[attr_name] = getattr(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" % ','.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())
示例9: contribute_to_class
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
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, attr_name, 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 = 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))
else:
self.verbose_name_plural = format_lazy('{}s', self.verbose_name)
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())
示例10: contribute_to_class
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
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, attr_name, 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 = 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, 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())
示例11: contribute_to_class
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
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, attr_name, 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())
示例12: _add_form
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import camel_case_to_spaces [as 别名]
def _add_form(cls: Type[AbstractForm], node: str, dict_params: dict) -> Type[graphene.Mutation]:
if node in registry.forms: # pragma: no cover
return registry.forms[node]
registry.page_prefetch_fields.add(cls.__name__.lower())
dict_params['Meta'].interfaces += (Page,)
dict_params['form_fields'] = graphene.List(FormField)
def form_fields(self, _info):
return list(FormField(name=field_.clean_name, field_type=field_.field_type,
label=field_.label, required=field_.required,
help_text=field_.help_text, choices=field_.choices,
default_value=field_.default_value)
for field_ in self.form_fields.all())
dict_params['resolve_form_fields'] = form_fields
registry.pages[cls] = type(node, (DjangoObjectType,), dict_params)
args = type("Arguments", (), {'values': GenericScalar(),
"url": graphene.String(required=True)})
_node = node
def mutate(_self, info, url, values):
url_prefix = url_prefix_for_site(info)
query = wagtailPage.objects.filter(url_path=url_prefix + url.rstrip('/') + '/')
instance = with_page_permissions(
info.context,
query.specific()
).live().first()
user = info.context.user
# convert camelcase to dashes
values = {camel_case_to_spaces(k).replace(' ', '-'): v for k, v in values.items()}
form = instance.get_form(values, None, page=instance, user=user)
if form.is_valid():
# form_submission
instance.process_form_submission(form)
return registry.forms[_node](result="OK")
else:
return registry.forms[_node](result="FAIL", errors=[FormError(*err) for err in form.errors.items()])
dict_params = {
"Arguments": args,
"mutate": mutate,
"result": graphene.String(),
"errors": graphene.List(FormError),
}
tp = type(node + "Mutation", (graphene.Mutation,), dict_params) # type: Type[graphene.Mutation]
registry.forms[node] = tp
return tp