comment.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. """
  3. """
  4. from __future__ import unicode_literals
  5. from pelican import contents
  6. from pelican.contents import Content
  7. class Comment(Content):
  8. mandatory_properties = ('author', 'date')
  9. default_template = 'None'
  10. def __init__(self, id, avatar, content, metadata, settings, source_path, context):
  11. super(Comment,self).__init__( content, metadata, settings, source_path, context )
  12. self.id = id
  13. self.replies = []
  14. self.avatar = avatar
  15. self.title = "Posted by: " + str(metadata['author'])
  16. def addReply(self, comment):
  17. self.replies.append(comment)
  18. def getReply(self, id):
  19. for reply in self.replies:
  20. if reply.id == id:
  21. return reply
  22. else:
  23. deepReply = reply.getReply(id)
  24. if deepReply != None:
  25. return deepReply
  26. return None
  27. def __lt__(self, other):
  28. return self.metadata['date'] < other.metadata['date']
  29. def sortReplies(self):
  30. for r in self.replies:
  31. r.sortReplies()
  32. self.replies = sorted(self.replies)
  33. def countReplies(self):
  34. amount = 0
  35. for r in self.replies:
  36. amount += r.countReplies()
  37. return amount + len(self.replies)