本文整理汇总了Python中django.utils.text.get_text_list方法的典型用法代码示例。如果您正苦于以下问题:Python text.get_text_list方法的具体用法?Python text.get_text_list怎么用?Python text.get_text_list使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.text
的用法示例。
在下文中一共展示了text.get_text_list方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: construct_change_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def construct_change_message(self, request, form, formsets):
"""
Construct a change message from a changed object.
"""
change_message = []
if form.changed_data:
change_message.append(_('Changed %s.') % get_text_list(form.changed_data, _('and')))
if formsets:
for formset in formsets:
for added_object in formset.new_objects:
change_message.append(_('Added %(name)s "%(object)s".')
% {'name': force_text(added_object._meta.verbose_name),
'object': force_text(added_object)})
for changed_object, changed_fields in formset.changed_objects:
change_message.append(_('Changed %(list)s for %(name)s "%(object)s".')
% {'list': get_text_list(changed_fields, _('and')),
'name': force_text(changed_object._meta.verbose_name),
'object': force_text(changed_object)})
for deleted_object in formset.deleted_objects:
change_message.append(_('Deleted %(name)s "%(object)s".')
% {'name': force_text(deleted_object._meta.verbose_name),
'object': force_text(deleted_object)})
change_message = ' '.join(change_message)
return change_message or _('No fields changed.')
示例2: unique_error_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def unique_error_message(self, model_class, unique_check):
opts = model_class._meta
model_name = capfirst(opts.verbose_name)
# A unique field
if len(unique_check) == 1:
field_name = unique_check[0]
field = opts.get_field(field_name)
field_label = capfirst(field.verbose_name)
# Insert the error into the error dict, very sneaky
return field.error_messages['unique'] % {
'model_name': six.text_type(model_name),
'field_label': six.text_type(field_label)
}
# unique_together
else:
field_labels = [capfirst(opts.get_field(f).verbose_name) for f in unique_check]
field_labels = get_text_list(field_labels, _('and'))
return _("%(model_name)s with this %(field_label)s already exists.") % {
'model_name': six.text_type(model_name),
'field_label': six.text_type(field_labels)
}
示例3: get_change_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_change_message(fields):
"""
Create a change message for *fields* (a sequence of field names).
"""
return _('Changed %s.') % get_text_list(fields, _('and'))
示例4: change_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def change_message(self):
change_message = []
if self.org_obj is None:
change_message.append(_('Added.'))
elif self.form_obj.changed_data:
change_message.append(_('Changed %s.') % get_text_list(self.form_obj.changed_data, _('and')))
change_message = ' '.join(change_message)
return change_message or _('No fields changed.')
示例5: clean
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def clean(self):
# self.validate_unique()
cleaned_data = super(CheckUniqueTogether, self).clean()
unique_fields = self.get_unique_together()
if isinstance(unique_fields, (list, tuple)):
unique_filter = {}
instance = self.instance
model_name = instance._meta.verbose_name
for unique_field in unique_fields:
field = instance._meta.get_field(unique_field)
if field.editable and unique_field in self.fields:
unique_filter[unique_field] = cleaned_data.get(
unique_field)
else:
unique_filter[unique_field] = getattr(
instance, unique_field)
for k, v in unique_filter.items():
if not v:
return
existing_instances = type(instance).objects.filter(
**unique_filter).exclude(pk=instance.pk)
if existing_instances:
field_labels = [
instance._meta.get_field(f).verbose_name
for f in unique_fields
]
field_labels = text_type(get_text_list(field_labels, _('and')))
msg = _("%(model_name)s with this %(field_labels)s already exists.") % {
'model_name': model_name, 'field_labels': field_labels, }
for unique_field in unique_fields:
if unique_field in self.fields:
self.add_error(unique_field, msg)
示例6: get_unique_error_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_unique_error_message(self, unique_check):
if len(unique_check) == 1:
return ugettext("Please correct the duplicate data for %(field)s.") % {
"field": unique_check[0],
}
else:
return ugettext("Please correct the duplicate data for %(field)s, "
"which must be unique.") % {
"field": get_text_list(unique_check, six.text_type(_("and"))),
}
示例7: unique_error_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def unique_error_message(self, model_class, unique_check):
opts = model_class._meta
params = {
'model': self,
'model_class': model_class,
'model_name': six.text_type(capfirst(opts.verbose_name)),
'unique_check': unique_check,
}
# A unique field
if len(unique_check) == 1:
field = opts.get_field(unique_check[0])
params['field_label'] = six.text_type(capfirst(field.verbose_name))
return ValidationError(
message=field.error_messages['unique'],
code='unique',
params=params,
)
# unique_together
else:
field_labels = [capfirst(opts.get_field(f).verbose_name) for f in unique_check]
params['field_labels'] = six.text_type(get_text_list(field_labels, _('and')))
return ValidationError(
message=_("%(model_name)s with this %(field_labels)s already exists."),
code='unique_together',
params=params,
)
示例8: get_unique_error_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_unique_error_message(self, unique_check):
if len(unique_check) == 1:
return gettext("Please correct the duplicate data for %(field)s.") % {
"field": unique_check[0],
}
else:
return gettext("Please correct the duplicate data for %(field)s, which must be unique.") % {
"field": get_text_list(unique_check, _("and")),
}
示例9: unique_error_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def unique_error_message(self, model_class, unique_check):
opts = model_class._meta
params = {
'model': self,
'model_class': model_class,
'model_name': capfirst(opts.verbose_name),
'unique_check': unique_check,
}
# A unique field
if len(unique_check) == 1:
field = opts.get_field(unique_check[0])
params['field_label'] = capfirst(field.verbose_name)
return ValidationError(
message=field.error_messages['unique'],
code='unique',
params=params,
)
# unique_together
else:
field_labels = [capfirst(opts.get_field(f).verbose_name) for f in unique_check]
params['field_labels'] = get_text_list(field_labels, _('and'))
return ValidationError(
message=_("%(model_name)s with this %(field_labels)s already exists."),
code='unique_together',
params=params,
)
示例10: get_change_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_change_message(self):
"""
If self.change_message is a JSON structure, interpret it as a change
string, properly translated.
"""
if self.change_message and self.change_message[0] == '[':
try:
change_message = json.loads(self.change_message)
except ValueError:
return self.change_message
messages = []
for sub_message in change_message:
if 'added' in sub_message:
if sub_message['added']:
sub_message['added']['name'] = gettext(sub_message['added']['name'])
messages.append(gettext('Added {name} "{object}".').format(**sub_message['added']))
else:
messages.append(gettext('Added.'))
elif 'changed' in sub_message:
sub_message['changed']['fields'] = get_text_list(
sub_message['changed']['fields'], gettext('and')
)
if 'name' in sub_message['changed']:
sub_message['changed']['name'] = gettext(sub_message['changed']['name'])
messages.append(gettext('Changed {fields} for {name} "{object}".').format(
**sub_message['changed']
))
else:
messages.append(gettext('Changed {fields}.').format(**sub_message['changed']))
elif 'deleted' in sub_message:
sub_message['deleted']['name'] = gettext(sub_message['deleted']['name'])
messages.append(gettext('Deleted {name} "{object}".').format(**sub_message['deleted']))
change_message = ' '.join(msg[0].upper() + msg[1:] for msg in messages)
return change_message or gettext('No fields changed.')
else:
return self.change_message
示例11: get_change_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_change_message(self):
"""
If self.change_message is a JSON structure, interpret it as a change
string, properly translated.
"""
if self.change_message and self.change_message[0] == '[':
try:
change_message = json.loads(self.change_message)
except json.JSONDecodeError:
return self.change_message
messages = []
for sub_message in change_message:
if 'added' in sub_message:
if sub_message['added']:
sub_message['added']['name'] = gettext(sub_message['added']['name'])
messages.append(gettext('Added {name} "{object}".').format(**sub_message['added']))
else:
messages.append(gettext('Added.'))
elif 'changed' in sub_message:
sub_message['changed']['fields'] = get_text_list(
sub_message['changed']['fields'], gettext('and')
)
if 'name' in sub_message['changed']:
sub_message['changed']['name'] = gettext(sub_message['changed']['name'])
messages.append(gettext('Changed {fields} for {name} "{object}".').format(
**sub_message['changed']
))
else:
messages.append(gettext('Changed {fields}.').format(**sub_message['changed']))
elif 'deleted' in sub_message:
sub_message['deleted']['name'] = gettext(sub_message['deleted']['name'])
messages.append(gettext('Deleted {name} "{object}".').format(**sub_message['deleted']))
change_message = ' '.join(msg[0].upper() + msg[1:] for msg in messages)
return change_message or gettext('No fields changed.')
else:
return self.change_message
示例12: get_unique_error_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_unique_error_message(self, unique_check):
if len(unique_check) == 1:
return ugettext("Please correct the duplicate data for %(field)s.") % {
"field": unique_check[0],
}
else:
return ugettext("Please correct the duplicate data for %(field)s, which must be unique.") % {
"field": get_text_list(unique_check, six.text_type(_("and"))),
}
示例13: get_change_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_change_message(self):
"""
If self.change_message is a JSON structure, interpret it as a change
string, properly translated.
"""
if self.change_message and self.change_message[0] == '[':
try:
change_message = json.loads(self.change_message)
except ValueError:
return self.change_message
messages = []
for sub_message in change_message:
if 'added' in sub_message:
if sub_message['added']:
sub_message['added']['name'] = ugettext(sub_message['added']['name'])
messages.append(ugettext('Added {name} "{object}".').format(**sub_message['added']))
else:
messages.append(ugettext('Added.'))
elif 'changed' in sub_message:
sub_message['changed']['fields'] = get_text_list(
sub_message['changed']['fields'], ugettext('and')
)
if 'name' in sub_message['changed']:
sub_message['changed']['name'] = ugettext(sub_message['changed']['name'])
messages.append(ugettext('Changed {fields} for {name} "{object}".').format(
**sub_message['changed']
))
else:
messages.append(ugettext('Changed {fields}.').format(**sub_message['changed']))
elif 'deleted' in sub_message:
sub_message['deleted']['name'] = ugettext(sub_message['deleted']['name'])
messages.append(ugettext('Deleted {name} "{object}".').format(**sub_message['deleted']))
change_message = ' '.join(msg[0].upper() + msg[1:] for msg in messages)
return change_message or ugettext('No fields changed.')
else:
return self.change_message
示例14: get_unique_error_message
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def get_unique_error_message(self, unique_check):
if len(unique_check) == 1:
return ugettext("Please correct the duplicate data for %(field)s.") % {
"field": unique_check[0],
}
else:
return ugettext("Please correct the duplicate data for %(field)s, "
"which must be unique.") % {
"field": get_text_list(unique_check, six.text_type(_("and"))),
}
示例15: handle_noargs
# 需要导入模块: from django.utils import text [as 别名]
# 或者: from django.utils.text import get_text_list [as 别名]
def handle_noargs(self, *args, **options):
locale = options.get('locale')
domain = options.get('domain')
verbosity = int(options.get('verbosity'))
process_all = options.get('all')
extensions = options.get('extensions')
symlinks = options.get('symlinks')
ignore_patterns = options.get('ignore_patterns')
if options.get('use_default_ignore_patterns'):
ignore_patterns += ['CVS', '.*', '*~']
ignore_patterns = list(set(ignore_patterns))
no_wrap = options.get('no_wrap')
no_location = options.get('no_location')
no_obsolete = options.get('no_obsolete')
if domain == 'djangojs':
exts = extensions if extensions else ['js']
else:
exts = extensions if extensions else ['html', 'txt']
extensions = handle_extensions(exts)
if verbosity > 1:
self.stdout.write('examining files with the extensions: %s\n'
% get_text_list(list(extensions), 'and'))
make_messages(locale, domain, verbosity, process_all, extensions,
symlinks, ignore_patterns, no_wrap, no_location, no_obsolete, self.stdout)