本文整理汇总了Python中django.utils.encoding.smart_unicode方法的典型用法代码示例。如果您正苦于以下问题:Python encoding.smart_unicode方法的具体用法?Python encoding.smart_unicode怎么用?Python encoding.smart_unicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.encoding
的用法示例。
在下文中一共展示了encoding.smart_unicode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _print_exec_out
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def _print_exec_out(cmd, out_buf, err_buf, exit_status, channel_name=None ):
from devops.asgi import channel_layer
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode('command executed: {}'.format(cmd))])})
print('command executed: {}'.format(cmd))
print('STDOUT:')
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode('STDOUT:')])})
for line in out_buf:
print line, "end="
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode(line.strip('\n'))])})
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode('end of STDOUT')])})
print('end of STDOUT')
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode('STDERR:')])})
print('STDERR:')
for line in err_buf:
print line, "end="
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode(line, "end=")])})
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode('end of STDERR')])})
print('end of STDERR')
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode('finished with exit status: {}'.format(exit_status))])})
print('finished with exit status: {}'.format(exit_status))
channel_layer.send(channel_name, {'text': json.dumps(['stdout',smart_unicode('------------------------------------')])})
print('------------------------------------')
示例2: run
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def run(self):
for server_ip in self.server_list:
self.message.reply_channel.send({"text":json.dumps(['stdout','\033[1;3;31mExecute task on server:%s \033[0m' %(smart_unicode(server_ip)) ] )},immediately=True)
#get server credential info
serverdata = Assets.objects.get(wip=server_ip)
port = serverdata.ssh_port
method = serverdata.user.auth_method
username = serverdata.user.username
if method == 'ssh-password':
credential = serverdata.user.password
else:
credential = serverdata.user.key
#do actual job
ssh = ShellHandler(server_ip,username,port,method,credential,channel_name=self.message.reply_channel.name)
for command in self.commands:
ssh.execute(command)
del ssh
示例3: choices
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def choices(self):
yield {
'selected': self.lookup_exact_val == '' and not self.lookup_isnull_val,
'query_string': self.query_string({},
[self.lookup_exact_name, self.lookup_isnull_name]),
'display': _('All'),
}
for pk_val, val in self.lookup_choices:
yield {
'selected': self.lookup_exact_val == smart_unicode(pk_val),
'query_string': self.query_string({
self.lookup_exact_name: pk_val,
}, [self.lookup_isnull_name]),
'display': val,
}
if (isinstance(self.field, ForeignObjectRel)
and self.field.field.null or hasattr(self.field, 'rel')
and self.field.null):
yield {
'selected': bool(self.lookup_isnull_val),
'query_string': self.query_string({
self.lookup_isnull_name: 'True',
}, [self.lookup_exact_name]),
'display': EMPTY_CHANGELIST_VALUE,
}
示例4: _get_new_field_html
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def _get_new_field_html(self, field_name):
try:
f, attr, value = lookup_field(field_name, self.org_obj, self)
except (AttributeError, ObjectDoesNotExist):
return EMPTY_CHANGELIST_VALUE
else:
allow_tags = False
if f is None:
allow_tags = getattr(attr, 'allow_tags', False)
boolean = getattr(attr, 'boolean', False)
if boolean:
allow_tags = True
text = boolean_icon(value)
else:
text = smart_unicode(value)
else:
if isinstance(f.rel, models.ManyToOneRel):
field_val = getattr(self.org_obj, f.name)
if field_val is None:
text = EMPTY_CHANGELIST_VALUE
else:
text = field_val
else:
text = display_for_field(value, f)
return mark_safe(text) if allow_tags else conditional_escape(text)
示例5: choices
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def choices(self):
yield {
'selected': self.lookup_exact_val == '' and not self.lookup_isnull_val,
'query_string': self.query_string({},
[self.lookup_exact_name, self.lookup_isnull_name]),
'display': _('All'),
}
for pk_val, val in self.lookup_choices:
yield {
'selected': self.lookup_exact_val == smart_unicode(pk_val),
'query_string': self.query_string({
self.lookup_exact_name: pk_val,
}, [self.lookup_isnull_name]),
'display': val,
}
if (is_related_field(self.field)
and self.field.field.null or hasattr(self.field, 'rel')
and self.field.null):
yield {
'selected': bool(self.lookup_isnull_val),
'query_string': self.query_string({
self.lookup_isnull_name: 'True',
}, [self.lookup_exact_name]),
'display': EMPTY_CHANGELIST_VALUE,
}
示例6: display_for_field
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def display_for_field(value, field):
from xadmin.views.list import EMPTY_CHANGELIST_VALUE
if field.flatchoices:
return dict(field.flatchoices).get(value, EMPTY_CHANGELIST_VALUE)
# NullBooleanField needs special-case null-handling, so it comes
# before the general null test.
elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField):
return boolean_icon(value)
elif value is None:
return EMPTY_CHANGELIST_VALUE
elif isinstance(field, models.DateTimeField):
return formats.localize(tz_localtime(value))
elif isinstance(field, (models.DateField, models.TimeField)):
return formats.localize(value)
elif isinstance(field, models.DecimalField):
return formats.number_format(value, field.decimal_places)
elif isinstance(field, models.FloatField):
return formats.number_format(value)
elif isinstance(field.rel, models.ManyToManyRel):
return ', '.join([smart_unicode(obj) for obj in value.all()])
else:
return smart_unicode(value)
示例7: handle
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def handle(self, *args, **options):
def patchSize(obj):
name = smart_unicode(obj.image_file.name)
path = name
try:
obj.size = obj.image_file.storage.size(path)
obj.save(keep_deleted=True)
except AttributeError:
path = os.path.join('images', name)
try:
obj.size = obj.image_file.storage.size(path)
obj.save(keep_deleted=True)
except AttributeError as e:
print e
qs = Image.all_objects.filter(size=0)
i = 0
total = qs.count()
for image in qs:
patchSize(image)
i += 1
for r in ImageRevision.all_objects.filter(image=image, size=0):
patchSize(r)
print "%d/%d" % (i, total)
sleep(0.1)
示例8: clean_and_parse_xml
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def clean_and_parse_xml(xml_string):
clean_xml_str = xml_string.strip()
clean_xml_str = re.sub(ur">\s+<", u"><", smart_unicode(clean_xml_str))
xml_obj = minidom.parseString(smart_str(clean_xml_str))
return xml_obj
示例9: __unicode__
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def __unicode__(self):
return smart_unicode(self.text).title()
示例10: __unicode__
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def __unicode__(self):
return smart_unicode(self.title)
示例11: __unicode__
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def __unicode__(self):
return smart_unicode(self.text)
示例12: __unicode__
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def __unicode__(self):
return smart_unicode(self.name)
示例13: handle
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def handle(self, *args, **options):
outdir = args[0] if len(args) > 0 else '.'
for ct in ContentType.objects.all():
model = ct.model_class()
if ct.app_label in ['photos', 'shapes', 'mturk', 'licenses', 'contenttypes']:
if ct.model not in ['shapeimagesample', 'pendingcontent']:
filename = '%s/%s.%s.csv' % (outdir, ct.app_label, ct.model)
print 'Dumping %s...' % filename
with open(filename, 'wb') as f:
writer = csv.writer(f, quoting=csv.QUOTE_ALL)
field_names = [f.name for f in model._meta.fields]
writer.writerow(field_names)
for row in model.objects.all().values_list(*field_names):
writer.writerow([smart_unicode(v).encode('utf-8') for v in row])
示例14: json_encode
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def json_encode(obj):
"""
On some platforms (CentOS 6.2, specifically) `tornado.escape.json_decode`
doesn't seem to work just right when it comes to returning unicode strings.
This is just a wrapper that ensures that the returned string is unicode.
"""
return to_unicode(_json_encode(obj))
示例15: valid_value
# 需要导入模块: from django.utils import encoding [as 别名]
# 或者: from django.utils.encoding import smart_unicode [as 别名]
def valid_value(self, value):
value = self.prepare_value(value)
for k, v in self.choices:
if value == smart_unicode(k):
return True
return False