You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DjangoBlog-Maintenance-Anal.../src/plugins/view_count/plugin.py

37 lines
1.1 KiB

from djangoblog.plugin_manage.base_plugin import BasePlugin
from djangoblog.plugin_manage import hooks
class ViewCountPlugin(BasePlugin):
"""
文章浏览次数统计插件
功能:自动记录和统计文章的浏览次数
"""
# 插件基本信息
PLUGIN_NAME = '文章浏览次数统计'
PLUGIN_DESCRIPTION = '统计文章的浏览次数'
PLUGIN_VERSION = '0.1.0'
PLUGIN_AUTHOR = 'liangliangyy'
def register_hooks(self):
"""
注册钩子函数
将浏览统计方法注册到文章内容获取后的钩子
"""
hooks.register('after_article_body_get', self.record_view)
def record_view(self, article, *args, **kwargs):
"""
记录文章浏览次数
参数:
article: Article对象 - 需要记录浏览次数的文章
*args, **kwargs: 其他参数(在此插件中未使用)
"""
# 调用文章的viewed()方法来增加浏览次数
article.viewed()
# 实例化插件,自动注册到系统
plugin = ViewCountPlugin()