跳转到主要内容

CKAN扩展,允许用户在不要求登录的情况下订阅更新

项目描述

https://travis-ci.org/davidread/ckanext-subscribe.svg?branch=master https://coveralls.io/repos/github/davidread/ckanext-subscribe/badge.svg?branch=master Latest Version Supported Python versions Development Status License

ckanext-subscribe

CKAN扩展,允许用户在不要求登录的情况下订阅数据集/组织/组更新。

此功能是CKAN现有“关注”功能的补充,允许已登录用户订阅以获取更新电子邮件。登录可能成为对一些数据集的业余兴趣的障碍。生成和存储密码对用户来说是一种负担,而对于业余使用,仅使用临时电子邮件链接,如本扩展中所示,更为合适。

doc/sign-up.png

更多截图: https://github.com/davidread/ckanext-subscribe/tree/master/doc

要求

与核心CKAN版本的兼容性

CKAN版本

兼容性

2.6及以下

2.7

2.8

2.9

尚未

安装

要安装ckanext-subscribe

  1. 激活您的CKAN虚拟环境,例如

    . /usr/lib/ckan/default/bin/activate
  2. 将ckanext-subscribe Python包安装到您的虚拟环境中

    pip install ckanext-subscribe
  3. subscribe添加到您的CKAN配置文件中的ckan.plugins设置(默认配置文件位于/etc/ckan/default/production.ini)。

  4. 确保在CKAN配置文件的[app:main]部分正确设置了ckan.site_url。这用于生成通知邮件正文中的链接。例如

    ckan.site_url = https://example.com
  5. 确保在CKAN配置文件的[app:main]部分正确设置了smtp.mail_from。这是CKAN的电子邮件通知看起来来自的电子邮件地址。例如

    smtp.mail_from = info@example.com

    这结合您的ckan.site_title来形成发送的电子邮件的From:头信息,例如

    From: Sunnyville Open Data <info@example.com>

    如果您想使用备用回复地址,例如“no-reply”地址,请在CKAN配置文件的[app:main]部分设置smtp.reply_to。例如

    smtp.reply_to = noreply@example.com
  6. 如果您没有在托管您的CKAN实例的机器上本地运行SMTP服务器,您可以将email-settings更改为通过外部SMTP服务器发送电子邮件。例如,以下配置文件中的[app:main]部分的设置将使用Gmail账户发送电子邮件(不建议用于生产网站!)

    smtp.server = smtp.gmail.com:587
    smtp.starttls = True
    smtp.user = your_username@gmail.com
    smtp.password = your_gmail_password
    smtp.mail_from = your_username@gmail.com
  7. 初始化数据库中的订阅表

    paster --plugin=ckanext-subscribe subscribe initdb
  8. 重新启动CKAN。例如,如果您已在Ubuntu上使用Apache部署CKAN

    sudo service apache2 reload
  9. 您需要定期运行‘send-any-notifications’命令。您可以在命令行中看到它正在运行

    paster --plugin=ckanext-subscribe subscribe send-any-notifications -c /etc/ckan/default/production.ini

    然而,您可能希望设置一个cron作业每分钟运行一次。我们将编辑cron表。在开发机器上,只需为您自己的用户执行此操作

    crontab -e

    或在生产机器上使用‘ckan’用户,而不是在命令行中检查通知,创建CRON作业。为此,使用以下命令编辑cron表(可能需要您选择一个编辑器)

    sudo crontab -e -u ckan

    将此行粘贴到您的crontab中,再次用您自己的paster路径和ini文件替换

    # m h  dom mon dow   command
      * *  *   *   *     /usr/lib/ckan/default/bin/paster --plugin=ckanext-subscribe subscribe send-any-notifications --config=/etc/ckan/default/production.ini

    这个特定的示例将每分钟检查一次通知

    在此cron中,您可能还会看到它运行一个用于/api/action/send_email_notifications的paster命令。这是类似但功能不同的操作,是CKAN核心用于向已创建用户账户的用户发送电子邮件(例如,“关注者”功能)。有关更多信息,请参阅此处:https://docs.ckan.org/en/2.8/maintaining/email-notifications.html

配置设置

# Email notifications older than this time period will not be sent.
# So, after a pause in the sending of emails, when it restarts, it will not
# notify about activity which is:
# * older than this period, for immediate subscriptions
# * older than this period + 1 day, for daily subscriptions
# * older than this period + 1 week, for weekly subscriptions
# Accepted formats: ‘2 days’, ‘14 days’, ‘4:35:00’ (hours, minutes, seconds),
#                  ‘7 days, 3:23:34’, etc.
# See also: https://docs.ckan.org/en/2.8/maintaining/configuration.html#ckan-email-notifications-since
# (optional, default: ‘2 days’)
ckan.email_notifications_since = 24:00:00

# The time that daily and weekly notification subscriptions are sent (UTC
# timezone)
ckanext.subscribe.daily_and_weekly_notification_time = 09:00

# The day of the week that weekly notification subscriptions are sent
ckanext.subscribe.weekly_notification_day = friday

故障排除

未发送通知电子邮件

  1. 检查您的cron计划是否正常工作

    tail -f /var/log/syslog | grep subscribe

    您应该每分钟看到消息

    Jan 10 15:24:01 ip-172-30-3-71 CRON[29231]: (ubuntu) CMD (/usr/lib/ckan/default/bin/paster --plugin=ckanext-subscribe subscribe run --config=/etc/ckan/default/production.ini)
  2. 为数据集/组/组织创建一个测试活动,您已订阅

    paster --plugin=ckanext-subscribe subscribe create-test-activity mydataset --config=/etc/ckan/default/production.ini

    由于cron激活的paster命令的日志目前没有存储在任何地方,所以最好在命令行中测试它

    paster --plugin=ckanext-subscribe subscribe send-any-notifications --config=/etc/ckan/default/production.ini

    您应该看到该数据集的订阅者收到了电子邮件

    2020-01-06 16:30:40,591 DEBUG [ckanext.subscribe.notification] send_any_immediate_notifications
    2020-01-06 16:30:40,628 DEBUG [ckanext.subscribe.notification] sending 1 emails (immediate frequency)
    2020-01-06 16:30:42,116 INFO  [ckanext.subscribe.mailer] Sent email to david.read@hackneyworkshop.com
  3. 之后清理所有测试活动

    paster --plugin=ckanext-subscribe subscribe delete-test-activity --config=/etc/ckan/default/production.ini

NameError: global name ‘Subscription’ is not defined

您需要在数据库中初始化订阅表。请参阅上述“安装”部分进行操作。

KeyError: “Action ‘subscribe_signup’ not found”

您需要在CKAN配置中启用subscribe插件。请参阅上述“安装”部分进行操作。

ProgrammingError: (ProgrammingError) relation “subscription” does not exist

您正在使用–reset-db运行测试,并且此扩展与它不兼容。相反,如果您在运行测试之前需要擦除表,请这样做

sudo -u postgres psql ckan_test -c 'drop table if exists subscription; drop table if exists subscribe_login_code; drop table if exists subscribe;'

或者简单

sudo -u postgres dropdb ckan_test
sudo -u postgres createdb -O ckan_default ckan_test -E utf-8
paster --plugin=ckan db init -c ../ckan/test-core.ini

开发者安装

为了开发安装 ckanext-subscribe,激活您的 CKAN 虚拟环境,然后执行

git clone https://github.com/davidread/ckanext-subscribe.git
cd ckanext-subscribe
python setup.py develop
pip install -r dev-requirements.txt

从步骤 3 继续安装步骤

测试

要运行测试,请执行

nosetests --nologcapture --with-pylons=test.ini

要运行测试并生成覆盖率报告,首先确保您的虚拟环境中已安装 coverage(pip install coverage),然后运行

nosetests --nologcapture --with-pylons=test.ini --with-coverage --cover-package=ckanext.subscribe --cover-inclusive --cover-erase --cover-tests

发布 ckanext-subscribe 的新版本

ckanext-subscribe 应该在 PyPI 上作为 https://pypi.ac.cn/project/ckanext-subscribe 提供。要将新版本发布到 PyPI,请按照以下步骤操作

  1. 更新 setup.py 文件中的版本号。有关如何选择版本号的说明,请参阅 PEP 440

  2. 更新 CHANGELOG.md

  3. 确保您拥有最新版本的必要软件包

    pip install --upgrade setuptools wheel twine
  4. 创建新版本的源和二进制分发

    python setup.py sdist bdist_wheel && twine check dist/*

    修复任何错误。

  5. 将源分发上传到 PyPI

    twine upload dist/*
  6. 提交任何悬而未决的更改

    git commit -a
    git push
  7. 使用 setup.py 文件中的版本号在 GitHub 上标记项目的最新发布。例如,如果 setup.py 中的版本号是 0.0.1,则执行

    git tag 0.0.1
    git push --tags

项目详细信息


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关 安装软件包 的更多信息。

源分发

ckanext-subscribe-1.1.0.tar.gz (47.5 kB 查看哈希值

上传时间

构建分发

ckanext_subscribe-1.1.0-py2-none-any.whl (58.8 kB 查看哈希值

上传时间 Python 2

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面