一个可以导出结果为CSV或PDF的Django调查应用程序,使用您本地的语言。
项目描述
Django调查
一个可以导出结果为CSV或PDF的Django调查应用程序,使用您本地的语言。
django-survey-and-report
在PyPI上。基于并兼容 django-survey
。您将能够从旧版本的 django-survey
迁移数据,但已移植到python 3,并且可以使用您本地的语言导出结果为CSV或PDF。
作为 Tidelift订阅 的一部分,提供对django-survey-and-report的专业支持
目录
可用的语言
该软件用英语开发。其他可用的语言有
- 巴西葡萄牙语,感谢 Rafael Capaci
- 中文,感谢 朱聖黎 (Zhu Sheng Li)
- 法语,感谢 Pierre Sassoulas
- 感谢德国的Georg Elsas
- 感谢印度尼西亚的Dhana Dhira
- 感谢日本的Nobukuni Suzue
- 感谢西班牙的Javier Ordóñez
- 感谢俄罗斯的Vlad M.
- 感谢波兰的Daniel Horner
- 感谢荷兰的John Guyver
- 感谢土耳其的Hüseyin Emre Armağan
- 感谢希腊的Sotirios Zogos
入门指南
将django-survey-and-report
添加到您的需求中,并使用pip获取。
echo 'django-survey-and-report' >> requirements.txt
pip install -r requirements.txt
将bootstrapform
和survey
添加到您的设置中的INSTALLED_APPS
INSTALLED_APPS = [
# Your own installed apps here
]
from pathlib import Path
CSV_DIRECTORY = Path("csv") # Define the directory where csv are exported
TEX_DIRECTORY = Path("tex") # Define the directory where tex files and pdf are exported
INSTALLED_APPS += [
'bootstrapform',
'survey'
]
将URL条目添加到您项目的urls.py中,例如
from django.conf import settings
from django.conf.urls import include
try:
from django.conf.urls import url
except ImportError:
# Django 4.0 replaced url by something else
# See https://stackoverflow.com/a/70319607/2519059
from django.urls import re_path as url
urlpatterns = [
# Your own url pattern here
]
if 'survey' in settings.INSTALLED_APPS:
urlpatterns += [
url(r'^survey/', include('survey.urls'))
]
注意:您可以使用任何您想要的URL前缀。
您也可以更改一些选项
# Permit to open the csv in Excel without problem with separator
# Using this trick : https://superuser.com/a/686415/567417
EXCEL_COMPATIBLE_CSV = True
# The separator for questions (Default to ",")
CHOICES_SEPARATOR = "|"
# What is shown in export when the user do not answer (Default to "Left blank")
USER_DID_NOT_ANSWER = "NAA"
# Path to the Tex configuration file (default to an internal file that should be sufficient)
from pathlib import Path
TEX_CONFIGURATION_FILE = Path("tex", "tex.conf")
# Default color for exported pdf pie (default to "red!50")
SURVEY_DEFAULT_PIE_COLOR = "blue!50"
要卸载django-survey-and-report
,只需在您的INSTALLED_APPS
中取消注释或删除'survey'行。
如果您想使用PDF渲染,则需要安装xelatex
。如果您使用桑基图生成,还必须安装python-tk
(Python 2.7)或python3-tk
(Python 3.x)。
制作调查
使用管理界面,您可以创建调查、添加问题、设置问题类别,并标记它们为必填或非必填。您可以使用逗号分隔的单词定义答案选项。
前端调查视图将根据在管理界面中定义和发布的已定义问题自动填充。我们使用bootstrap3来渲染它们。
可以通过管理后端、导出的csv文件或使用latex生成的pdf文件查看提交的响应。
从调查结果生成PDF报告
PDF生成有一个默认配置,但您可能希望更改TEX_CONFIGURATION_FILE
以获得更好的结果(特别是对于英语以外的语言)。
您可以在yaml文件中管理报告的创建方式,全局、调查或问题。为了渲染PDF,您需要安装xelatex
。您还需要python3-tk用于桑基图。
结果仅在需要时为服务器生成,但您可以用以下方式作为开发人员强制生成:
python manage.py exportresult -h
以下是一个配置文件的示例。您可以使用以下方法生成一个配置文件:
python manage.py generatetexconf -h
基本示例
generic:
document_option: 11pt
"Test survëy":
document_class: report
questions:
"Lorem ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.":
chart:
type: polar
text: pin
"Dolor sit amët, consectetur<strong> adipiscing</strong> elit.":
chart:
type: cloud
text: inside
然后使用非常好的pgf-pie库生成PDF。
桑基图
如果您已安装python3-tk,您还可以使用桑基图显示两个问题之间的关系
"Lorem ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.":
chart:
type: sankey
question: "Dolor sit amët, consectetur<strong> adipiscing</strong> elit."
您将得到以下结果
高级示例
您还可以通过基数限制显示的答案,过滤它们,将它们分组并选择每个答案或答案组的颜色。
如果您要为上一个问题使用此配置
"Test survëy":
"Dolor sit amët, consectetur<strong> adipiscing</strong> elit.":
multiple_charts:
"Sub Sub Section with radius=3":
color:
Yës: blue!50
No: red!50
Whatever: red!50!blue!50
radius: 3
"Sub Sub Section with text=pin":
group_together:
Nah:
- No
- Whatever
K.:
- Yës
color:
Nah: blue!33!red!66
K.: blue!50
text: pin
chart:
radius: 1
type: cloud
text: inside
您将得到以下结果
实现自定义处理
如果您想进行自己的处理,可以使用自己的类,例如。
配置
"Test survëy":
questions:
"Ipsum dolor sit amët, <strong> consectetur </strong> adipiscing elit.":
chart:
type: survey.tests.exporter.tex.CustomQuestion2TexChild
在survey.tests.exporter.tex.CustomQuestion2TexChild
中的代码
from survey.exporter.tex.question2tex_chart import Question2TexChart
class CustomQuestion2TexChild(Question2TexChart):
def get_results(self):
self.type = "polar"
return """ 2/There were no answer at all,
3/But we have a custom treatment to show some,
2/You can make minor changes too !"""
结果
有关配置文件的完整示例,请参阅doc中的example_conf.yaml
,您也可以使用python manage.py generatetexconf -h
生成配置文件,它将为每个调查和问题创建默认结构。
在Python开发期间,您可以阅读
- 在
Question2TexChart
中PieChart的默认报告器:https://github.com/Pierre-Sassoulas/django-survey/blob/master/survey/exporter/tex/question2tex_chart.py#L13 - 在
Question3TexSankey
中的桑基报告器:https://github.com/Pierre-Sassoulas/django-survey/blob/master/survey/exporter/tex/question2tex_sankey.py#L15 Question2TexRax
中的原始报告器: https://github.com/Pierre-Sassoulas/django-survey/blob/master/survey/exporter/tex/question2tex_raw.py.
如果您的新导出器对其他人有参考价值,请不要犹豫提交拉取请求,我会将其集成。
致谢
基于 jessykate 的 django-survey,以及 jibaku、joshualoving 和 ijasperyang 在 jessykate 项目分叉中的贡献。
我们在报告过程中使用了 anazalea 的 pySankey 生成桑基图。
项目详情
下载文件
根据您的平台下载文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
构建分发
哈希值 for django_survey_and_report-1.4.7-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | a20d906188b0d00bc1679203f1061fc4f170cc9f85ed401416803c60ae3a66d7 |
|
MD5 | 2524c53e29766f6f2466158bee5c8c7e |
|
BLAKE2b-256 | 8d3e636b368b01d0981d714fc762613c137cbae2480206cdcac6b95ccd964472 |