当前位置: 首页>>代码示例>>Python>>正文


Python forms.pretty_name方法代码示例

本文整理汇总了Python中django.forms.forms.pretty_name方法的典型用法代码示例。如果您正苦于以下问题:Python forms.pretty_name方法的具体用法?Python forms.pretty_name怎么用?Python forms.pretty_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms.forms的用法示例。


在下文中一共展示了forms.pretty_name方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_field_or_method_label

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def _get_field_or_method_label(self, model, field_name):
        resource_label = self._get_resource_label(model, field_name)
        if resource_label is not None:
            return resource_label
        else:
            try:
                field = model._meta.get_field(field_name)
                if field.auto_created and (field.one_to_many or field.many_to_many):
                    return (
                        getattr(field.field, 'reverse_verbose_name', None) or
                        field.related_model._meta.verbose_name_plural
                    )
                elif field.auto_created and field.one_to_one:
                    return (
                        getattr(field.field, 'reverse_verbose_name', None) or
                        field.related_model._meta.verbose_name
                    )
                else:
                    return field.verbose_name
            except FieldDoesNotExist:
                method = get_class_method(model, field_name)
                return getattr(method, 'short_description', pretty_name(field_name)) 
开发者ID:matllubos,项目名称:django-is-core,代码行数:24,代码来源:table_views.py

示例2: get_search_columns

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def get_search_columns(cls):
        return [cls.CONFIG_FIELDS[name].label or pretty_name(name) for name in cls.SEARCH_RESULT_FIELDS] 
开发者ID:sfu-fas,项目名称:coursys,代码行数:4,代码来源:base.py

示例3: __init__

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def __init__(self, name, field, Handler):
        self.field_name = name
        self.field = field
        self.Handler = Handler

        if hasattr(Handler, 'SEARCH_FIELD_NAMES') and name in Handler.SEARCH_FIELD_NAMES:
            prettyname = Handler.SEARCH_FIELD_NAMES[name]
        else:
            prettyname = pretty_name(self.field_name)
        self.pretty_field_name = prettyname 
开发者ID:sfu-fas,项目名称:coursys,代码行数:12,代码来源:search.py

示例4: get_model_method_or_property_data

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def get_model_method_or_property_data(field_name, model, fun_kwargs):
    from is_core.forms.widgets import ReadonlyWidget

    class_method = get_class_method(model, field_name)

    method = (
        getattr(model, field_name)
        if hasattr(model, field_name) and not class_method and is_callable(getattr(model, field_name))
        else class_method
    )

    if method:
        if hasattr(method, 'field'):
            # Generic relation
            label = getattr(method.field, 'verbose_name', pretty_name(field_name))
        else:
            label = getattr(method, 'short_description', pretty_name(field_name))
        try:
            return (
                (None, label, ReadonlyWidget) if isinstance(model, type)
                else (_get_method_or_property_value(method, field_name, model, fun_kwargs), label, ReadonlyWidget)
            )
        except InvalidMethodArguments:
            return None
    elif hasattr(model, field_name):
        return (
            getattr(model, field_name), pretty_name(field_name), ReadonlyWidget
        )
    else:
        return None 
开发者ID:matllubos,项目名称:django-is-core,代码行数:32,代码来源:__init__.py

示例5: _get_view_readonly_data

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def _get_view_readonly_data(field_name, view, fun_kwargs):
    from is_core.forms.widgets import ReadonlyWidget

    method_field = view.get_method_returning_field_value(field_name)
    if method_field:
        try:
            return (
                _get_method_value(method_field, field_name, view, fun_kwargs),
                getattr(method_field, 'short_description', pretty_name(field_name)),
                ReadonlyWidget
            )
        except InvalidMethodArguments:
            return None
    else:
        return None 
开发者ID:matllubos,项目名称:django-is-core,代码行数:17,代码来源:__init__.py

示例6: _get_resource_label

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def _get_resource_label(self, model, field_name):
        resource = self.get_resource(model)
        if resource:
            method_field = resource.get_method_returning_field_value(field_name)
            return getattr(method_field, 'short_description', pretty_name(field_name)) if method_field else None
        else:
            return None 
开发者ID:matllubos,项目名称:django-is-core,代码行数:9,代码来源:table_views.py

示例7: prettify

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def prettify(value):
    return pretty_name(value) 
开发者ID:mediafactory,项目名称:yats,代码行数:4,代码来源:strings.py

示例8: format_chanes

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def format_chanes(new, is_staff):
    from django.forms.forms import pretty_name

    result = []
    for field in new:
        if not is_staff and field in settings.TICKET_NON_PUBLIC_FIELDS:
            continue
        result.append('%s: %s' % (pretty_name(field), new[field]))

    return '\n'.join(result) 
开发者ID:mediafactory,项目名称:yats,代码行数:12,代码来源:shortcuts.py

示例9: label_for_field

# 需要导入模块: from django.forms import forms [as 别名]
# 或者: from django.forms.forms import pretty_name [as 别名]
def label_for_field(name, model, model_admin=None, return_attr=False):
    """
    Returns a sensible label for a field name. The name can be a callable,
    property (but not created with @property decorator) or the name of an
    object's attribute, as well as a genuine fields. If return_attr is
    True, the resolved attribute (which could be a callable) is also returned.
    This will be None if (and only if) the name refers to a field.
    """
    attr = None
    try:
        field = _get_non_gfk_field(model._meta, name)
        try:
            label = field.verbose_name
        except AttributeError:
            # field is likely a ForeignObjectRel
            label = field.related_model._meta.verbose_name
    except FieldDoesNotExist:
        if name == "__unicode__":
            label = force_text(model._meta.verbose_name)
            attr = six.text_type
        elif name == "__str__":
            label = force_str(model._meta.verbose_name)
            attr = bytes
        else:
            if callable(name):
                attr = name
            elif model_admin is not None and hasattr(model_admin, name):
                attr = getattr(model_admin, name)
            elif hasattr(model, name):
                attr = getattr(model, name)
            else:
                message = "Unable to lookup '%s' on %s" % (name, model._meta.object_name)
                if model_admin:
                    message += " or %s" % (model_admin.__class__.__name__,)
                raise AttributeError(message)

            if hasattr(attr, "short_description"):
                label = attr.short_description
            elif (isinstance(attr, property) and
                  hasattr(attr, "fget") and
                  hasattr(attr.fget, "short_description")):
                label = attr.fget.short_description
            elif callable(attr):
                if attr.__name__ == "<lambda>":
                    label = "--"
                else:
                    label = pretty_name(attr.__name__)
            else:
                label = pretty_name(name)
    if return_attr:
        return (label, attr)
    else:
        return label 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:55,代码来源:utils.py


注:本文中的django.forms.forms.pretty_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。