一个django应用程序,它简化了一些常见的html呈现

django-html-sweatshop的Python项目详细描述


一些常见的html呈现是乏味的。让django html血汗工厂做这项艰苦的工作。

功能

  • digg风格的分页,可选择与django-tables2集成
  • 显示消息
  • 删除前弹出确认对话框

安装

开始使用django-html-sweatshop

  • pip

    安装
    $ pip install django-html-sweatshop
    
  • 将应用程序添加到INSTALLED_APPS

    INSTALLED_APPS = (
        ...
        'html_sweatshop',
        'django_tables2', #Required if you need digg style pagination
        ...
    )
    

digg样式分页

提供了一组标记来呈现digg风格的分页。要使用这些标记,请将它们加载到模板中

{% load digg_pagination_tags %}

原始分页

用法:

{% digg_paginator page_obj page_field theme %}

这是呈现分页的原始方式。如https://docs.djangoproject.com/en/1.9/topics/pagination/所述,您必须处理分页的实际工作(一些通用视图可以为您完成这部分工作)。此标记将处理分页的呈现。它提供了比其他两个更大的灵活性。

page_obj

Optional. A page object as outlined in https://docs.djangoproject.com/en/1.9/topics/pagination/#page-objects. By default, a variable named “page_obj” in the context will be used if it’s not provided.

page_field

Optional. The name of the page parameter in the url. For example, if “page_field” is set to “page”, when the link of the second page is clicked, “page=2” will be appended to the url. The default value is “page”.

theme

Optional. The theme pack to use. Right now Bootstrap 3 is the only valid theme available. So there’s no need to set this parameter.

Django-Table2集成

用法:

{% digg_paginator_tables2 table theme %}

此标记提供与django-tables2的集成。它通常与django-tables2附带的singletableview通用视图一起使用。但是django-tables2标记呈现的表可能在分页时看起来与默认表模板不同。

table

Optional. A table instance of django-tables2. Please refer to django-tables2 document regarding table class. By default, a variable named “table” in the context will be used if it’s not provided.

theme

Optional. The theme pack to use. Right now Bootstrap 3 is the only valid theme available. So there’s no need to set this parameter.

Django-Table2无缝集成

用法:

{% render_paginated_table table theme %}

此标记提供与django-tables2的无缝集成。与其他两个只呈现分页的标记不同,这个标记同时呈现表和分页。

table

Optional. A table instance of django-tables2. Please refer to django-tables2 document regarding table class. By default, a variable named “table” in the context will be used if it’s not provided.

theme

Optional. The theme pack to use. Right now Bootstrap 3 is the only valid theme available. So there’s no need to set this parameter.

信息中心

用有意义的背景色和图标显示所有消息的标记。要使用此标记,请将其加载到模板中

{% load message_centre_tags %}

然后在要显示消息的位置

{% message_centre dismissible theme %}

dismissible

Optional. A boolean value to indicate if the messages are dissmissible (depending on the theme pack). By default, its value is HTML_SWEATSHOP_MESSAGE_CENTRE_MESSAGE_DISMISSIBLE which defaults to True.

theme

Optional. The theme pack to use. Right now Bootstrap 3 is the only valid theme available. So there’s no need to set this parameter.

一步删除

deleteview泛型视图使删除过程分为两步。第一步,呈现确认页。第二步,提交删除。但是在大多数系统中,在提交删除之前,只需弹出一个确认模式,所有的操作都发生在同一个页面上。

我们提供了一个标记和一个jquery插件来简化它。

加载标签定义

{% load one_step_delete_tags static %}

加载jquery插件

在应该包含js的地方加载jquery插件。包含jquery本身是您自己的责任。

{% include_one_step_delete_js %}

<script type=”text/javascript” src=”{% static ‘one_step_delete/js/init_one_step_delete.js’ %}”></script>

渲染删除按钮

根据主题包呈现删除按钮。以bootstrap 3主题为例,delete按钮可以是

<button class=”btn btn-danger” data-toggle=”modal” data-target=”…” data-modal-title=”…” data-modal-action=”…” data-obj-description=”…”>…</button>

可以定义一些特定于jquery插件的数据属性,以允许多个delete按钮共享相同的确认模式。

data-modal-title

Replace the modal title with this value when the button is clicked.

data-modal-action

Replace the action url of deletion submission with this value when the button is clicked.

data-obj-description

If you are satisfied with the overall message in the modal body, you can replace the description of the object to delete with this value to fine tune the message when the button is clicked.

data-body

Replace the message of the modal body with this value totally when the button is clicked.

呈现确认模式

使用以下标记呈现确认模式。您可以为每个删除按钮呈现每个确认模式,也可以呈现一个在删除按钮之间共享的模式。

{% render_confirm_modal dialog_id obj obj_description url title body theme %}

dialog_id

Optional. The HTML id of the confirmation modal. Defaults to “confirmation-modal”.

obj

Optional. A model object to be deleted. Once provided, a default confirmation message can be inferred by the tag.

obj_description

Optional. The default confirmation message use the verbose name of “obj” as the description. It can be overridden by this parameter.

url

Optional. The action url delete is submitted to. By default it’s empty.

title

Optional. The title of the confirmation modal. By default, it’s “Are you sure?”

body

Optional. Used to override the whole default confirmation message.

theme

Optional. The theme pack to use. Right now Bootstrap 3 is the only valid theme available. So there’s no need to set this parameter.

设置

HTML_SWEATSHOP_DIGG_PAGINATION_LEADING_PAGE_RANGE_DISPLAYED

Defaults to 10

HTML_SWEATSHOP_DIGG_PAGINATION_TRAILING_PAGE_RANGE_DISPLAYED

Defaults to 10

HTML_SWEATSHOP_DIGG_PAGINATION_NUM_PAGES_OUTSIDE_RANGE

Defaults to 2

HTML_SWEATSHOP_DIGG_PAGINATION_LEADING_PAGE_RANGE

Defaults to 8

HTML_SWEATSHOP_DIGG_PAGINATION_TRAILING_PAGE_RANGE

Defaults to 8

HTML_SWEATSHOP_DIGG_PAGINATION_ADJACENT_PAGES

Defaults to 4

HTML_SWEATSHOP_THEME

The theme pack to use. Defauls to ‘bootstrap3’

HTML_SWEATSHOP_MESSAGE_CENTRE_MESSAGE_DISMISSIBLE

If the messages are dimissible. Defaults to True

演示

签出源代码。内部e在“源代码”文件夹中,运行以下命令:

mkvirtualenv demo

pip install -r requirements.txt

python manage.py runserver

如何贡献

派生项目并提交拉取请求。需要更多的主题包。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将cassandra中的行数据转换为与列相关的嵌套json   java如何使用jcr XPath在jcr:content/@jcr:data中搜索?   java在使用openCV进行安卓开发时如何利用手机的广角镜头   java解析扩展了接口,结束了一个潜在的无限循环   位置服务的@Override方法中存在java Android应用程序错误   java本地线程的用途和需求是什么   具有左右子访问的java节点树遍历   java验证JsonWebToken签名   JUL日志处理程序中的java日志记录   嵌入式Java读取给定时间段的串行数据。   java有没有办法从多个URL获取多个图像?   java线程通过等待intent阻止自己发送intent   java Spring MVC解析多部分内容请求   java JPA/Hibernate静态元模型属性未填充NullPointerException   java格式错误的字符(需要引号,得到I)~正在处理   java为什么PrintWriter对象抛出FileNotFoundException?   java Neo4j未正确保存标签   java IE不加载图像