1 | import urllib, md5 #hashlib |
---|
2 | |
---|
3 | from Acquisition import aq_inner |
---|
4 | from AccessControl import getSecurityManager |
---|
5 | from Products.CMFPlone.utils import getToolByName |
---|
6 | |
---|
7 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
8 | from plone.app.layout.viewlets import comments |
---|
9 | |
---|
10 | class CommentsViewlet(comments.CommentsViewlet): |
---|
11 | """A custom version of the comments viewlet |
---|
12 | """ |
---|
13 | |
---|
14 | render = ViewPageTemplateFile('comments.pt') |
---|
15 | |
---|
16 | def is_moderation_enabled(self): |
---|
17 | """ Returns a boolean indicating whether the user has enabled moderation |
---|
18 | in the qPloneComments configlet |
---|
19 | """ |
---|
20 | portal_properties = getToolByName(self.context, 'portal_properties') |
---|
21 | try: |
---|
22 | return portal_properties.qPloneComments.getProperty('enable_moderation', None) |
---|
23 | except AttributeError: |
---|
24 | return False |
---|
25 | |
---|
26 | def can_moderate(self): |
---|
27 | """ Returns a boolean indicating whether the user has the 'Moderate Discussion' |
---|
28 | permission |
---|
29 | """ |
---|
30 | return getSecurityManager().checkPermission('Moderate Discussion', aq_inner(self.context)) |
---|
31 | |
---|
32 | def getGravatar(self, reply): |
---|
33 | purl = getToolByName(self.context, 'portal_url') |
---|
34 | default = purl() + '/defaultUser.gif' |
---|
35 | email = '' |
---|
36 | |
---|
37 | creator = reply.Creator() |
---|
38 | if creator and not creator=='Anonymous User': |
---|
39 | mtool = getToolByName(self.context, "portal_membership") |
---|
40 | member = mtool.getMemberById(creator) |
---|
41 | email = member and member.getProperty('email','') or '' |
---|
42 | else: |
---|
43 | email = reply.getProperty('email',d='') |
---|
44 | if not email: |
---|
45 | return default |
---|
46 | |
---|
47 | size = 40 |
---|
48 | gravatar_url = "http://www.gravatar.com/avatar.php?" |
---|
49 | # construct the url |
---|
50 | gravatar_url += urllib.urlencode({'gravatar_id':md5.md5(email).hexdigest(), |
---|
51 | 'default':default, 'size':str(size)}) |
---|
52 | |
---|
53 | return gravatar_url |
---|