zoukankan      html  css  js  c++  java
  • django-xadmin定制之列表页searchbar placeholder

    环境:xadmin-for-python3 python3.5.2 django1.9.12

    列表页的searchbar如果提供的可搜索字段,都没提示哪个字段可搜索,很不友好,本次定制主要增加input元素的placeholder,定制后见搜索区的提示效果:

    以下为要修改的相关代码:

    1. xadminpluginsfilters.py block_nav_form方法增加search_placeholder

    def block_nav_form(self, context, nodes):
            if self.search_fields:
                search_placeholder = ' '.join([str(get_fields_from_path(self.model, search_field)[-1]._verbose_name) for search_field in self.search_fields])
                context = get_context_dict(context or {})  # no error!
                context.update({
                    'search_var': SEARCH_VAR,
                    'remove_search_url': self.admin_view.get_query_string(remove=[SEARCH_VAR]),
                    'search_form_params': self.admin_view.get_form_params(remove=[SEARCH_VAR]),
                    'search_placeholder': search_placeholder
                })
                nodes.append(
                    loader.render_to_string(
                        'xadmin/blocks/model_list.nav_form.search_form.html',
                        context=context)
                )

    2.  xadmin emplatesxadminlocksmodel_list.nav_form.search_form.html 增加search_placeholder

    {% load i18n %}
    {% if cl.search_fields %}
    <form class="navbar-form navbar-left" action="" method="get">
        <div class="input-group search-group">
        {% if cl.search_query %}
          <span class="input-group-btn"><a class="btn btn-default" href="{{remove_search_url}}">x</a></span>
        {% endif %}
        <input id="searchbar" class="form-control" style="300px" type="text" name="{{ search_var }}" value="{{ cl.search_query }}" placeholder="{% trans 'Search' %} {{search_placeholder}}">
        <span class="input-group-btn"><button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button></span>
        </div>
        {{ search_form_params|safe }}
    </form>
    {% endif %}
  • 相关阅读:
    python 输出所有列表元素的乘积
    shell 变量赋值运算
    shell 判断变量是否为空
    js 获取地址栏域名以及URL
    python 获取列表大于指定长度的元素
    python 判断列表字符串元素首尾字符是否相同
    python 通过列表元素值截取列表并获取长度
    python 判断两个列表是否有公共元素
    python 获取列表的键值对
    python 判断列表的包含关系
  • 原文地址:https://www.cnblogs.com/roystime/p/7262985.html
Copyright © 2011-2022 走看看