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 %}
  • 相关阅读:
    成绩等级
    函数值
    最大数
    温度转换
    何时使用hadoop fs、hadoop dfs与hdfs dfs命令
    Hadoop常见异常及其解决方案
    Hadoop2.4.1入门实例:MaxTemperature
    单机/伪分布式Hadoop2.4.1安装文档
    用Apache Ivy实现项目里的依赖管理
    【Nutch2.2.1基础教程之2.1】集成Nutch/Hbase/Solr构建搜索引擎之一:安装及运行【单机环境】
  • 原文地址:https://www.cnblogs.com/roystime/p/7262985.html
Copyright © 2011-2022 走看看