未提供项目描述
项目描述
ckanext-comments
向CKAN页面添加评论树。
此插件提供了与CKAN主要实体之一相关的评论线程
- 数据集
- 资源
- 组
- 组织
- 用户。
所有功能都是API优先的,因此您可以通过API完成通过UI可以完成的所有操作。
默认情况下,不修改WebUI。需要在Jinja2模板中包含一个片段才能在页面上显示评论。
{# subject_type := package | group | resource | user #}
{% snippet 'comments/snippets/thread.html', subject_id=pkg.id, subject_type='package' %}
:info: 对于数据集,也可以通过启用ckanext.comments.enable_default_dataset_comments
选项来实现。
需求
- python >= 3.7
- CKAN >= 2.9
安装
要安装ckanext-comments
- 安装python包
pip install ckanext-comments
-
将
comments
添加到CKAN配置文件中的ckan.plugins
设置中 -
应用数据库迁移
ckan db upgrade -p comments
- 将
cooments/snippets/thread.html
添加到您的package/read.html
模板中,如下所示
{% ckan_extends %}
{% block primary_content_inner %}
{{ super() }}
{% snippet 'comments/snippets/thread.html', subject_id=pkg.id, subject_type='package' %}
{% endblock primary_content_inner %}
配置设置
# Require comment approval in order to make it visible
# (optional, default: true).
ckanext.comments.require_approval = false
# Editor(admin) can edit draft comments
# (optional, default: true).
ckanext.comments.draft_edits = true
# Author can edit own draft comments
# (optional, default: true).
ckanext.comments.draft_edits_by_author = false
# Editor(admin) can edit approved comments
# (optional, default: false).
ckanext.comments.approved_edits = false
# Author can edit own approved comments
# (optional, default: false).
ckanext.comments.approved_edits_by_author = false
# Number of reply levels that are shown on mobile layout
# (optional, default: 3).
ckanext.comments.mobile_depth_threshold = 3
# Include default thread implementation on the dataset page
# (optional, default: false).
ckanext.comments.enable_default_dataset_comments = true
# Register custom getter for a subject by providing a path to a function
# ckanext.comments.subject.{self.subject_type}_getter = path
# The function must accept an ID and return a model object
ckanext.comments.subject.question_getter = ckanext.msf_ask_question.model.question_getter
API
comments_thread_create
为主题创建一个线程。
参数
- subject_id(str): 被评论实体的唯一ID
- subject_type(str:package|resource|user|group): 被评论实体的类型
comments_thread_show
显示主题的线程。
参数
- subject_id(str): 被评论实体的唯一ID
- subject_type(str:package|resource|user|group): 被评论实体的类型
- init_missing(bool, 可选): 返回一个空线程而不是404
- include_comments(bool, 可选): 显示线程中的评论
- include_author(bool, 可选): 显示评论的作者
- combine_comments(bool, 可选): 将评论组合成树状结构
- after_date(str:ISO日期, 可选): 仅显示从给定日期开始的评论
comments_thread_delete
删除线程。
参数
- id(str): 线程ID
comments_comment_create
向线程添加评论。
参数
- subject_id(str): 被评论实体的唯一ID
- subject_type(str:package|resource|user|group): 被评论实体的类型
- content(str): 评论的消息
- reply_to_id(str, 可选): 回复现有的评论
- create_thread(bool, 可选): 如果不存在,则创建一个新的线程
comments_comment_show
显示评论的详细信息
参数
- id(str): 评论ID
comments_comment_approve
批准草稿评论
参数
- id(str): 评论ID
comments_comment_delete
移除现有评论
参数
- id(str): 评论ID
comments_comment_update
更新现有评论
参数
- id(str): 评论ID
- content(str): 评论的消息
测试
要运行测试,请执行
pytest
许可协议
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源分布
ckanext-comments-0.3.1.tar.gz (37.6 kB 查看散列)
构建分布
ckanext_comments-0.3.1-py3-none-any.whl (47.2 kB 查看散列)