• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python declarative.setdefaults函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tri.declarative.setdefaults函数的典型用法代码示例。如果您正苦于以下问题:Python setdefaults函数的具体用法?Python setdefaults怎么用?Python setdefaults使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: icon

    def icon(icon, is_report=False, icon_title="", show=True, **kwargs):
        """
        Shortcut to create font awesome-style icons.

        :param icon: the font awesome name of the icon
        """
        setdefaults(
            kwargs,
            dict(
                name="",
                display_name="",
                sortable=False,
                attrs__class__thin=True,
                show=lambda table, **rest: evaluate(show, table=table, **rest) and not is_report,
                title=icon_title,
                cell__value=lambda table, column, row, **_: True,
                cell__attrs__class__cj=True,
                cell__format=lambda value, **_: mark_safe(
                    '<i class="fa fa-lg fa-%s"%s></i>' % (icon, ' title="%s"' % icon_title if icon_title else "")
                )
                if value
                else "",
            ),
        )
        return Column(**kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:25,代码来源:__init__.py


示例2: multi_choice

 def multi_choice(**kwargs):
     setdefaults(kwargs, dict(
         attrs={'multiple': ''},
         choice_to_option=lambda form, field, choice: (choice, unicode(choice), unicode(choice), field.value_list and choice in field.value_list),
         is_list=True
     ))
     return Field.choice(**kwargs)
开发者ID:pombredanne,项目名称:tri.form,代码行数:7,代码来源:__init__.py


示例3: multi_choice_queryset

 def multi_choice_queryset(**kwargs):
     setdefaults(kwargs, dict(
         attrs={'multiple': ''},
         choice_to_option=should_not_evaluate(lambda form, field, choice: (choice, choice.pk, unicode(choice), field.value_list and choice in field.value_list)),
         is_list=True
     ))
     return Field.choice_queryset(**kwargs)
开发者ID:pombredanne,项目名称:tri.form,代码行数:7,代码来源:__init__.py


示例4: select

    def select(is_report=False, checkbox_name="pk", show=True, checked=lambda x: False, **kwargs):
        """
        Shortcut for a column of checkboxes to select rows. This is useful for implementing bulk operations.

        :param checkbox_name: the name of the checkbox. Default is "pk", resulting in checkboxes like "pk_1234".
        :param checked: callable to specify if the checkbox should be checked initially. Defaults to False.
        """
        setdefaults(
            kwargs,
            dict(
                name="__select__",
                title="Select all",
                display_name=mark_safe('<i class="fa fa-check-square-o"></i>'),
                sortable=False,
                show=lambda table, **rest: evaluate(show, table=table, **rest) and not is_report,
                attrs__class__thin=True,
                attrs__class__nopad=True,
                cell__attrs__class__cj=True,
                cell__value=lambda row, **_: mark_safe(
                    '<input type="checkbox"%s class="checkbox" name="%s_%s" />'
                    % (" checked" if checked(row.pk) else "", checkbox_name, row.pk)
                ),
            ),
        )
        return Column(**kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:25,代码来源:__init__.py


示例5: choice

 def choice(**kwargs):
     choices = kwargs["choices"]
     setdefaults(
         kwargs,
         dict(bulk__class=Field.choice, bulk__choices=choices, query__class=Variable.choice, query__choices=choices),
     )
     return Column(**kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:7,代码来源:__init__.py


示例6: choice_queryset

    def choice_queryset(**kwargs):
        """
        Field that has one value out of a set.
        :type choices: django.db.models.QuerySet
        """
        def choice_queryset_value_to_q(variable, op, value_string_or_f):
            if op != '=':
                raise QueryException('Invalid operator "%s" for variable "%s"' % (op, variable.name))
            if variable.attr is None:
                return Q()
            if isinstance(value_string_or_f, string_types) and value_string_or_f.lower() == 'null':
                return Q(**{variable.attr: None})
            try:
                instance = kwargs['choices'].get(**{variable.value_to_q_lookup: text_type(value_string_or_f)})
            except ObjectDoesNotExist:
                return None
            return Q(**{variable.attr + '__pk': instance.pk})

        setdefaults(kwargs, dict(
            gui__class=Field.choice_queryset,
            gui__choices=kwargs['choices'],
            gui__model=kwargs['model'],
            op_to_q_op=lambda op: 'exact',
            value_to_q_lookup='name',
            value_to_q=choice_queryset_value_to_q,
        ))
        return Variable(**kwargs)
开发者ID:TriOptima,项目名称:tri.query,代码行数:27,代码来源:__init__.py


示例7: __init__

    def __init__(self, **kwargs):
        """
        :param name: the name of the column
        :param attr: What attribute to use, defaults to same as name. Follows django conventions to access properties of properties, so "foo__bar" is equivalent to the python code `foo.bar`. This parameter is based on the variable name of the Column if you use the declarative style of creating tables.
        :param display_name: the text of the header for this column. By default this is based on the `name` parameter so normally you won't need to specify it.
        :param css_class: CSS class of the header
        :param url: URL of the header. This should only be used if "sorting" is off.
        :param title: title/tool tip of header
        :param show: set this to False to hide the column
        :param sortable: set this to False to disable sorting on this column
        :param sort_key: string denoting what value to use as sort key when this column is selected for sorting. (Or callable when rendering a table from list.)
        :param sort_default_desc: Set to True to make table sort link to sort descending first.
        :param group: string describing the group of the header. If this parameter is used the header of the table now has two rows. Consecutive identical groups on the first level of the header are joined in a nice way.
        :param auto_rowspan: enable automatic rowspan for this column. To join two cells with rowspan, just set this auto_rowspan to True and make those two cells output the same text and we'll handle the rest.
        :param cell__template: name of a template file. The template gets arguments: `table`, `bound_column`, `bound_row`, `row` and `value`.
        :param cell__value: string or callable that receives kw arguments: `table`, `column` and `row`. This is used to extract which data to display from the object.
        :param cell__format: string or callable that receives kw arguments: `table`, `column`, `row` and `value`. This is used to convert the extracted data to html output (use `mark_safe`) or a string.
        :param cell__attrs: dict of attr name to callables that receive kw arguments: `table`, `column`, `row` and `value`.
        :param cell__url: callable that receives kw arguments: `table`, `column`, `row` and `value`.
        :param cell__url_title: callable that receives kw arguments: `table`, `column`, `row` and `value`.
        """

        setdefaults(kwargs, dict(
            bulk=(Struct(extract_subkeys(kwargs, 'bulk', defaults=dict(show=False)))),
            query=(Struct(extract_subkeys(kwargs, 'query', defaults=dict(show=False)))),
            extra=(Struct(extract_subkeys(kwargs, 'extra'))),
        ))

        kwargs = {k: v for k, v in kwargs.items() if not k.startswith('bulk__') and not k.startswith('query__') and not k.startswith('extra__')}

        assert isinstance(kwargs['bulk'], dict)
        assert isinstance(kwargs['query'], dict)
        assert isinstance(kwargs['extra'], dict)

        super(Column, self).__init__(**kwargs)
开发者ID:pombredanne,项目名称:tri.table,代码行数:35,代码来源:__init__.py


示例8: choice_queryset

 def choice_queryset(**kwargs):
     model = kwargs.pop('model')
     setdefaults(kwargs, dict(
         extra=Struct(model=model),
         parse=lambda form, field, string_value: field.extra.model.objects.get(pk=string_value) if string_value else None,
         choice_to_option=lambda form, field, choice: (choice, choice.pk, unicode(choice), choice == field.value)
     ))
     return Field.choice(**kwargs)
开发者ID:pombredanne,项目名称:tri.form,代码行数:8,代码来源:__init__.py


示例9: integer

 def integer(**kwargs):  # pragma: no cover
     """
     Boolean field. Tries hard to parse a boolean value from its input.
     """
     setdefaults(kwargs, dict(
         gui__class=Field.integer,
     ))
     return Variable(**kwargs)
开发者ID:pombredanne,项目名称:tri.query,代码行数:8,代码来源:__init__.py


示例10: choice_queryset

 def choice_queryset(**kwargs):
     setdefaults(kwargs, dict(
         bulk__class=Field.choice_queryset,
         bulk__model=kwargs.get('model'),
         query__class=Variable.choice_queryset,
         query__model=kwargs.get('model'),
     ))
     return Column.choice(**kwargs)
开发者ID:pombredanne,项目名称:tri.table,代码行数:8,代码来源:__init__.py


示例11: number

 def number(**kwargs):
     """
     Shortcut for rendering a number. Sets the "rj" (as in "right justified") CSS class on the cell and header.
     """
     setdefaults(kwargs, dict(
         cell__attrs__class__rj=True
     ))
     return Column(**kwargs)
开发者ID:azureatom,项目名称:tri.table,代码行数:8,代码来源:__init__.py


示例12: download

 def download(is_report=False, **kwargs):
     """
     Shortcut for creating a clickable download icon. The URL defaults to `your_object.get_absolute_url() + 'download/'`. Specify the option cell__url to override.
     """
     setdefaults(kwargs, dict(
         cell__url=lambda row, **_: row.get_absolute_url() + 'download/',
         cell__value=lambda row, **_: getattr(row, 'pk', False),
     ))
     return Column.icon('download', is_report, 'Download', **kwargs)
开发者ID:pombredanne,项目名称:tri.table,代码行数:9,代码来源:__init__.py


示例13: delete

 def delete(is_report=False, **kwargs):
     """
     Shortcut for creating a clickable delete icon. The URL defaults to `your_object.get_absolute_url() + 'delete/'`. Specify the option cell__url to override.
     """
     setdefaults(kwargs, dict(
         cell__url=lambda row, **_: row.get_absolute_url() + 'delete/',
         display_name=''
     ))
     return Column.icon('trash-o', is_report, 'Delete', **kwargs)
开发者ID:pombredanne,项目名称:tri.table,代码行数:9,代码来源:__init__.py


示例14: edit

 def edit(is_report=False, **kwargs):
     """
     Shortcut for creating a clickable edit icon. The URL defaults to `your_object.get_absolute_url() + 'edit/'`. Specify the option cell__url to override.
     """
     setdefaults(kwargs, dict(
         cell__url=lambda row, **_: row.get_absolute_url() + 'edit/',
         display_name=''
     ))
     return Column.icon('pencil-square-o', is_report, 'Edit', **kwargs)
开发者ID:pombredanne,项目名称:tri.table,代码行数:9,代码来源:__init__.py


示例15: time

 def time(**kwargs):
     def parse_time(string_value, **_):
         try:
             return datetime.strptime(string_value, '%H:%M:%S').time()
         except ValueError as e:
             raise ValidationError(e.message)
     setdefaults(kwargs, dict(
         parse=parse_time
     ))
     return Field(**kwargs)
开发者ID:pombredanne,项目名称:tri.form,代码行数:10,代码来源:__init__.py


示例16: time

 def time(**kwargs):
     setdefaults(
         kwargs,
         dict(
             query__class=Variable.time,
             query__op_to_q_op=lambda op: {"=": "exact", ":": "contains"}.get(op) or Q_OP_BY_OP[op],
             bulk__class=Field.time,
         ),
     )
     return Column(**kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:10,代码来源:__init__.py


示例17: choice

 def choice(**kwargs):  # pragma: no cover
     """
     Field that has one value out of a set.
     :type choices: list
     """
     setdefaults(kwargs, dict(
         gui__choices=kwargs.get('choices'),
         gui__class=Field.choice,
     ))
     return Variable(**kwargs)
开发者ID:TriOptima,项目名称:tri.query,代码行数:10,代码来源:__init__.py


示例18: link

    def link(**kwargs):
        """
        Shortcut for creating a cell that is a link. The URL is the result of calling `get_absolute_url()` on the object.
        """

        def url(table, column, row, value):
            del table, value
            r = getattr_path(row, column.attr)
            return r.get_absolute_url() if r else ""

        setdefaults(kwargs, dict(cell__url=url))
        return Column(**kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:12,代码来源:__init__.py


示例19: multi_choice_queryset

 def multi_choice_queryset(**kwargs):
     setdefaults(
         kwargs,
         dict(
             bulk__class=Field.multi_choice_queryset,
             bulk__model=kwargs.get("model"),
             query__class=Variable.multi_choice_queryset,
             query__model=kwargs.get("model"),
             cell__format=lambda value, **_: ", ".join(["%s" % x for x in value.all()]),
         ),
     )
     return Column.choice(**kwargs)
开发者ID:TriOptima,项目名称:tri.table,代码行数:12,代码来源:__init__.py


示例20: boolean

 def boolean(**kwargs):
     """
     Boolean field. Tries hard to parse a boolean value from its input.
     """
     setdefaults(kwargs, dict(
         parse=lambda string_value, **_: bool_parse(string_value),
         required=False,
         template='tri_form/{style}_form_row_checkbox.html',
         input_template='tri_form/checkbox.html',
         is_boolean=True
     ))
     return Field(**kwargs)
开发者ID:pombredanne,项目名称:tri.form,代码行数:12,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python declarative.setdefaults_path函数代码示例发布时间:2022-05-27
下一篇:
Python transport_hid.HidTransport类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap