一个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>
呈现确认模式
使用以下标记呈现确认模式。您可以为每个删除按钮呈现每个确认模式,也可以呈现一个在删除按钮之间共享的模式。
{% 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
如何贡献
派生项目并提交拉取请求。需要更多的主题包。