def record_plugin_history(self, sender, instance, **kwargs):
"""When a plugin is created or edited"""
from cms.models import CMSPlugin, Page
from .models import EditHistory
if not isinstance(instance, CMSPlugin):
return
user_id = cache.get('cms-user-id')
comment = cache.get('cms-comment')
content = generate_content(instance)
if content is None:
return
# Don't record a history of change if nothing changed.
history = EditHistory.objects.filter(plugin_id=instance.id)
if history.count() > 0:
# Temporary history object for uuid
this = EditHistory(content=content)
latest = history.latest()
if latest.content == content or this.uuid == latest.uuid:
return
EditHistory.objects.record(instance, user_id, comment, content)
评论列表
文章目录