Changeset 531
- Timestamp:
- 09/22/06 09:20:35
- Files:
-
- qPloneComments/branches/plone-2.5/Extensions/Install.py (modified) (3 diffs)
- qPloneComments/branches/plone-2.5/config.py (modified) (1 diff)
- qPloneComments/branches/plone-2.5/patch.py (modified) (2 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_publish_comment.py (modified) (2 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_reply.cpy (modified) (3 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_reply_form.cpt (modified) (1 diff)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/notify_comment_template.pt (modified) (2 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_comments_setup.cpy (modified) (1 diff)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_comments_setup_form.cpt (modified) (7 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_recent_comments_delete.cpy (modified) (2 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_recent_comments_publish.cpy (modified) (2 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/rejected_comment_template.pt (modified) (2 diffs)
- qPloneComments/branches/plone-2.5/skins/qplonecomments/reply_notify_template.pt (modified) (1 diff)
- qPloneComments/branches/plone-2.5/utils.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
qPloneComments/branches/plone-2.5/Extensions/Install.py
r530 r531 9 9 10 10 import string 11 try:12 True13 except:14 True = 115 False = 016 11 17 12 def setupSkin(self, out, layers): … … 68 63 out.write("Adding %s property sheet to portal_properies\n" % 'qPloneComments' ) 69 64 props_sheet = pp['qPloneComments'] 70 updateProperty(props_sheet, id="enable_moderation", value="True", property_type='boolean', out=out) 71 updateProperty(props_sheet, id="require_anonym_email", value="True", property_type='boolean', out=out) 72 updateProperty(props_sheet, id="enable_anonymous_commenting", value="True", property_type='boolean', out=out) 73 updateProperty(props_sheet, id="enable_published_notification", value="True", property_type='boolean', out=out) 74 updateProperty(props_sheet, id="enable_approve_notification", value="True", property_type='boolean', out=out) 75 updateProperty(props_sheet, id="email_discussion_manager", value="", property_type='string', out=out) 76 updateProperty(props_sheet, id="email_subject_prefix", value="", property_type='string', out=out) 65 updateProperties(props_sheet, out, PROPERTIES) 77 66 # Tern on Anonymous commenting 78 67 self.manage_permission(ReplyToItem, ['Anonymous','Manager','Member'], 1) … … 120 109 121 110 122 def updateProperty(pp_ps, id, value, property_type, out): 123 if not pp_ps.hasProperty(id): 124 pp_ps.manage_addProperty(id, value, property_type) 125 out.write("Adding %s property to %s property sheet\n" % (id, 'qPloneComments') ) 126 111 def updateProperties(pp_ps, out, *args): 112 for prop in args: 113 for prop_id, prop_value, prop_type in prop: 114 if not pp_ps.hasProperty(prop_id): 115 pp_ps.manage_addProperty(prop_id, prop_value, prop_type) 116 out.write("Adding %s property to %s property sheet\n" % (prop_id, 'qPloneComments') ) 127 117 128 118 def uninstall(self) : qPloneComments/branches/plone-2.5/config.py
r530 r531 8 8 CONFIGLET_NAME = "qPloneComments setup" 9 9 10 PROPERTIES = (('enable_approve_user_notification', 'True', 'boolean'), 11 ('enable_reply_user_notification', 'True', 'boolean'), 12 ('enable_rejected_user_notification', 'True', 'boolean'), 13 ('enable_moderation', 'True', 'boolean'), 14 ('require_email', 'False', 'boolean'), 15 ('enable_anonymous_commenting', 'True', 'boolean'), 16 ('enable_published_notification', 'True', 'boolean'), 17 ('enable_approve_notification', 'True', 'boolean'), 18 ('email_discussion_manager', '', 'string'), 19 ('email_subject_prefix', '', 'string')) qPloneComments/branches/plone-2.5/patch.py
r530 r531 10 10 # Patching createReply method of 11 11 # Products.CMFDefault.DiscussionItem.DiscussionItemContainer 12 def createReply( self, title, text, Creator=None ):12 def createReply( self, title, text, Creator=None, email=''): 13 13 """ 14 14 Create a reply in the proper place … … 31 31 32 32 pm = getToolByName(self, 'portal_membership') 33 value = 0 33 34 34 if pm.isAnonymousUser(): 35 value = 1 36 if item.hasProperty('isAnon'): 37 item.manage_changeProperties({'id':'isAnon','value':value}) 35 userid = 'anonym' 38 36 else: 39 item.manage_addProperty(id='isAnon', value=value, type='boolean') 37 userid = pm.getAuthenticatedMember().getId() 38 39 item.manage_addProperty(id='userid', value=userid, type='string') 40 item.manage_addProperty(id='email', value=email, type='string') 40 41 41 42 item.review_state="private" qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_publish_comment.py
r530 r531 10 10 from Products.CMFPlone import transaction_note 11 11 from Products.CMFCore.utils import getToolByName 12 from Products.qPloneComments.utils import publishDiscussion, send_email12 from Products.qPloneComments.utils import publishDiscussion, 13 13 14 14 if obj is None: … … 25 25 publishDiscussion(reply) 26 26 27 send_notification_message = send_email(reply, container, state="published")28 27 29 28 portal_status_message='Comment+successfully+published' qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_reply.cpy
r530 r531 11 11 from Products.PythonScripts.standard import url_quote_plus 12 12 from Products.CMFCore.utils import getToolByName 13 from Products.qPloneComments.utils import send_email13 from Products.qPloneComments.utils import manage_mails 14 14 from Products.CMFPlone import PloneMessageFactory as _ 15 15 mtool = getToolByName(context, 'portal_membership') 16 16 dtool = getToolByName(context, 'portal_discussion') 17 17 18 req = context.REQUEST 18 19 pp = getToolByName(context,'portal_properties') 19 20 # Get properties 20 isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None) 21 ifModerate = pp['qPloneComments'].getProperty('enable_moderation', None); 21 isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', False) 22 ifModerate = pp['qPloneComments'].getProperty('enable_moderation', False) 23 requireEmail = pp['qPloneComments'].getProperty('require_email', False) 22 24 if username or password: 23 25 # The user username/password inputs on on the comment form were used, … … 60 62 comment_creator = member.getUserName() 61 63 tb = dtool.getDiscussionFor(context) 62 id = tb.createReply(title=subject, text=body_text, Creator=comment_creator) 64 if requireEmail: 65 if mtool.isAnonymousUser(): 66 email = req.get('user_email', '') 67 else: 68 email = mtool.getAuthenticatedMember().getProperty('email') 69 70 id = tb.createReply(title=subject, text=body_text, Creator=comment_creator, email=email) 71 else: 72 id = tb.createReply(title=subject, text=body_text, Creator=comment_creator) 73 63 74 reply = tb.getReply(id) 64 75 … … 68 79 69 80 parent = tb.aq_parent 70 # Send notification e-mail 71 send_notification_message = send_email(reply, context, state="approve")81 # Send notification e-mail 82 manage_mails(reply, context, 'aproving') 72 83 if not ifModerate: 73 send_notification_message += send_email(reply, context, state="published")84 manage_mails(reply, context, 'publishing') 74 85 75 86 # return to the discussable object. qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_reply_form.cpt
r530 r531 109 109 </div> 110 110 </div> 111 112 <div class="field" 113 tal:define="property_id string:require_email; 114 props_sheet here/portal_properties/qPloneComments" 115 tal:condition="python:props_sheet.getProperty(property_id) and isAnon"> 116 117 <label for="user_email" i18n:translate="label_discussion-manager_email">Please enter your email:</label> 118 <span class="fieldRequired" title="Required" 119 i18n:attributes="title title_required;" 120 i18n:translate="label_required">(Required) 121 </span> 122 <div tal:content="string:">Validation error output</div> 123 124 <input name="user_email" 125 value="" 126 size="40" 127 tabindex="" 128 tal:attributes="tabindex tabindex/next;" /> 129 </div> 111 130 </div> 112 131 qPloneComments/branches/plone-2.5/skins/qplonecomments/notify_comment_template.pt
r530 r531 3 3 tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 4 4 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 5 organization_name options/organization_name" 5 organization_name options/organization_name; 6 obj nocall:options/obj" 6 7 >To: <tal:x replace="options/mto"/> 7 8 From: <tal:x replace="options/mfrom"/> … … 9 10 10 11 <tal:x replace="options/name"/>, 11 12 Your comment on '<a href="" tal:attributes="href obj/absolute_url" tal:content="obj/Title"/>' has been 13 published. To see your comment, go to <tal:x replace="obj/Title"/> 12 Your comment on '<tal:x replace="obj/absolute_url" />' has been 13 published. To see your comment, go to <tal:x replace="obj/absolute_url" /> 14 14 15 15 -- qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_comments_setup.cpy
r530 r531 10 10 from Products.CMFCore.utils import getToolByName 11 11 from Products.qPloneComments.utils import setAnonymCommenting 12 #from AccessControl.Permission import Permission 12 13 13 form = context.REQUEST.form 14 14 pp = getToolByName(context, 'portal_properties') qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_comments_setup_form.cpt
r530 r531 33 33 <!-- End of tabs --> 34 34 <div class="documentContent" metal:define-slot="prefs_content"> 35 <h1 i18n:translate="qpc_setup"> qPloneComments Setup</h1>35 <h1 i18n:translate="qpc_setup">Plone Comments Setup</h1> 36 36 37 37 <a href="" … … 74 74 75 75 <div class="field" 76 tal:define="property_id string:require_ anonym_email;77 isRequireAnonymEmail python:props_sheet.getProperty(property_id, False);"78 tal:condition="python:props_sheet.hasProperty(property_id)"> 79 80 <input type="checkbox" 81 class="noborder" 82 name=" isRequireAnonymEmail"83 id=" isRequireAnonymEmail"84 tabindex ="" 85 tal:attributes="name property_id; 86 value isRequireAnonymEmail;87 checked python:test( isRequireAnonymEmail, 'True', '');76 tal:define="property_id string:require_email; 77 requireEmail python:props_sheet.getProperty(property_id, False);" 78 tal:condition="python:props_sheet.hasProperty(property_id)"> 79 80 <input type="checkbox" 81 class="noborder" 82 name="requireEmail" 83 id="requireEmail" 84 tabindex ="" 85 tal:attributes="name property_id; 86 value requireEmail; 87 checked python:test(requireEmail, 'True', ''); 88 88 tabindex tabindex/next;"/> 89 89 90 90 <label i18n:translate="label_require_anonym_email" 91 for=" isRequireAnonymEmail">Require Anonym Email.</label>91 for="requireEmail">Require Anonym Email.</label> 92 92 93 93 </div> … … 110 110 <label i18n:translate="label_anonymous_commenting" 111 111 for="isEnabledAnonymousCommenting">Enable anonymous comenting.</label> 112 113 </div>114 115 <div class="field"116 tal:define="property_id string:enable_published_notification;117 isEnabledPublishedNotification python:props_sheet.getProperty(property_id, False);"118 tal:condition="python:props_sheet.hasProperty(property_id)">119 120 <input type="checkbox"121 class="noborder"122 name="isEnabledPublishedNotification"123 id="isEnabledPublishedNotification"124 tabindex =""125 tal:attributes="name property_id;126 value isEnabledPublishedNotification;127 checked python:test(isEnabledPublishedNotification, 'True', '');128 tabindex tabindex/next;"/>129 130 <label i18n:translate="label_enable_published_notification"131 for="isEnabledPublishedNotification">Enable Document Owner notification on new comments.</label>132 </div>133 134 <div class="field"135 tal:define="property_id string:enable_approve_notification;136 isEnableApproveNotification python:props_sheet.getProperty(property_id, False);"137 tal:condition="python:props_sheet.hasProperty(property_id)">138 139 <input type="checkbox"140 class="noborder"141 name="isEnableApproveNotification"142 id="isEnableApproveNotification"143 tabindex =""144 tal:attributes="name property_id;145 value isEnableApproveNotification;146 checked python:test(isEnableApproveNotification, 'True', '');147 tabindex tabindex/next;"/>148 149 <label i18n:translate="label_enable_approve_notification"150 for="isEnableApproveNotification">Enable Discussion Manager notification on new comments.</label>151 112 </div> 152 113 … … 160 121 tabindex ="" 161 122 tal:attributes="value isEnabledManagerModeration; 162 checked python:test(isEnabledManagerModeration, 'True', '');123 checked python:test(isEnabledManagerModeration, 'True', ''); 163 124 tabindex tabindex/next;"/> 164 125 … … 180 141 The e-mail address where notifications about adding new comments will be sent. 181 142 </div> 182 143 183 144 <div tal:content="error">Validation error output</div> 184 145 … … 196 157 organization_name python:props_sheet.getProperty(property_id, '');" 197 158 tal:condition="python:props_sheet.hasProperty(property_id)"> 198 159 199 160 <label i18n:translate="label_organization_name">Email subject prefix (organization name)</label> 200 161 201 162 <div class="formHelp" id="organization_name_help" 202 163 i18n:translate="help_organization_name"> 203 164 You can change notification message templates customizing 'approve_comment_template' and 'published_comment_template' from qplonecomments skin. 204 165 </div> 205 166 206 167 <input name="organization_name" 207 168 value="" … … 213 174 </div> 214 175 215 <div class="formControls"> 216 <input type="hidden" name="form.submitted" value="1" /> 217 218 <input class="context" 219 tabindex="" 220 type="submit" 221 name="form.button.form_submit" 222 value="Save" 223 i18n:attributes="value" 224 tal:attributes="tabindex tabindex/next;" 225 /> 226 </div> 227 </fieldset> 176 </fieldset> 177 178 179 180 181 <fieldset> 182 <legend i18n:translate="legend_qpc_notification_legend">Notification tuning</legend> 183 184 <div class="field" 185 tal:define="property_id string:enable_published_notification; 186 isEnabledPublishedNotification python:props_sheet.getProperty(property_id, False);" 187 tal:condition="python:props_sheet.hasProperty(property_id)"> 188 189 <input type="checkbox" 190 class="noborder" 191 name="isEnabledPublishedNotification" 192 id="isEnabledPublishedNotification" 193 tabindex ="" 194 tal:attributes="name property_id; 195 value isEnabledPublishedNotification; 196 checked python:test(isEnabledPublishedNotification, 'True', ''); 197 tabindex tabindex/next;"/> 198 199 <label i18n:translate="label_enable_published_notification" 200 for="isEnabledPublishedNotification">Enable Document Owner notification on new comments.</label> 201 </div> 202 203 <div class="field" 204 tal:define="property_id string:enable_approve_notification; 205 isEnableApproveNotification python:props_sheet.getProperty(property_id, False);" 206 tal:condition="python:props_sheet.hasProperty(property_id)"> 207 208 <input type="checkbox" 209 class="noborder" 210 name="isEnableApproveNotification" 211 id="isEnableApproveNotification" 212 tabindex ="" 213 tal:attributes="name property_id; 214 value isEnableApproveNotification; 215 checked python:test(isEnableApproveNotification, 'True', ''); 216 tabindex tabindex/next;"/> 217 218 <label i18n:translate="label_enable_approve_notification" 219 for="isEnableApproveNotification">Enable Discussion Manager notification on new comments.</label> 220 </div> 221 222 <div class="field" 223 tal:define="property_id string:enable_approve_user_notification; 224 isEnableApproveUserNotification python:props_sheet.getProperty(property_id, False);" 225 tal:condition="python:props_sheet.hasProperty(property_id)"> 226 227 <input type="checkbox" 228 class="noborder" 229 name="isEnableApproveUserNotification" 230 id="isEnableApproveUserNotification" 231 tabindex ="" 232 tal:attributes="name property_id; 233 value isEnableApproveUserNotification; 234 checked python:test(isEnableApproveUserNotification, 'True', ''); 235 tabindex tabindex/next;"/> 236 237 <label i18n:translate="label_enable_approve_notification" 238 for="isEnableApproveUserNotification">Enable Commentator notification on comment was published.</label> 239 </div> 240 241 <div class="field" 242 tal:define="property_id string:enable_rejected_user_notification; 243 isRejectionNotificationEnabled python:props_sheet.getProperty(property_id, False);" 244 tal:condition="python:props_sheet.hasProperty(property_id)"> 245 246 <input type="checkbox" 247 class="noborder" 248 name="isRejectionNotificationEnabled" 249 id="isRejectionNotificationEnabled" 250 tabindex ="" 251 tal:attributes="name property_id; 252 value isRejectionNotificationEnabled; 253 checked python:test(isRejectionNotificationEnabled, 'True', ''); 254 tabindex tabindex/next;"/> 255 256 <label i18n:translate="label_enable_approve_notification" 257 for="isRejectionNotificationEnabled">Enable Commentator notification on comment was rejected.</label> 258 </div> 259 260 <div class="field" 261 tal:define="property_id string:enable_reply_user_notification; 262 isReplyNotificationEnabled python:props_sheet.getProperty(property_id, False);" 263 tal:condition="python:props_sheet.hasProperty(property_id)"> 264 265 <input type="checkbox" 266 class="noborder" 267 name="isReplyNotificationEnabled" 268 id="isReplyNotificationEnabled" 269 tabindex ="" 270 tal:attributes="name property_id; 271 value isReplyNotificationEnabled; 272 checked python:test(isReplyNotificationEnabled, 'True', ''); 273 tabindex tabindex/next;"/> 274 275 <label i18n:translate="label_enable_approve_notification" 276 for="isReplyNotificationEnabled">Enable Commentator notification on comment was replied.</label> 277 </div> 278 279 <div class="field" 280 tal:define="property_id string:enable_reply_user_notification; 281 isReplyNotificationEnabled python:props_sheet.getProperty(property_id, False);" 282 tal:condition="python:props_sheet.hasProperty(property_id)"> 283 284 <input type="checkbox" 285 class="noborder" 286 name="isReplyNotificationEnabled" 287 id="isReplyNotificationEnabled" 288 tabindex ="" 289 tal:attributes="name property_id; 290 value isReplyNotificationEnabled; 291 checked python:test(isReplyNotificationEnabled, 'True', ''); 292 tabindex tabindex/next;"/> 293 294 <label i18n:translate="label_enable_approve_notification" 295 for="isReplyNotificationEnabled">Enable Commentator notification on comment was replied.</label> 296 </div> 297 </fieldset> 298 299 <div class="formControls"> 300 <input type="hidden" name="form.submitted" value="1" /> 301 <input class="context" 302 tabindex="" 303 type="submit" 304 name="form.button.form_submit" 305 value="Save" 306 i18n:attributes="value" 307 tal:attributes="tabindex tabindex/next;"/> 308 </div> 228 309 </form> 229 310 </div> qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_recent_comments_delete.cpy
r530 r531 10 10 11 11 from Products.CMFCore.utils import getToolByName 12 from Products.qPloneComments.utils import manage_mails 12 13 portal_discussion = getToolByName(context, "portal_discussion") 13 14 portal_catalog = getToolByName(context, "portal_catalog") … … 25 26 talkback = parent = comment.aq_parent 26 27 27 talkback.deleteReply( comment_id ) 28 comment = portal_catalog(id=comment_id,portal_type='Discussion Item')[0].getObject() 29 talkback.deleteReply(comment_id) 30 manage_mails(comment, context, 'deleting') 28 31 29 32 psm = comment_ids and 'Comments was successfully deleted.' or 'Please select items to be processed.' qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_recent_comments_publish.cpy
r530 r531 8 8 ##title= 9 9 ## 10 11 10 from Products.CMFCore.utils import getToolByName 12 from Products.qPloneComments.utils import publishDiscussion, send_email11 from Products.qPloneComments.utils import publishDiscussion, manage_mails 13 12 14 13 request = context.REQUEST … … 20 19 comment = portal_catalog(id=comment_id,portal_type='Discussion Item')[0].getObject() 21 20 publishDiscussion(comment) 22 send_notification_message = send_email(comment, container, state="published")21 manage_mails(comment, container, action='publishing') 23 22 24 23 psm = comment_ids and 'Comments was successfully published.' or 'Please select items to be processed.' qPloneComments/branches/plone-2.5/skins/qplonecomments/rejected_comment_template.pt
r530 r531 3 3 tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 4 4 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 5 organization_name options/organization_name" 5 organization_name options/organization_name; 6 obj nocall:options/obj" 6 7 >To: <tal:x replace="options/mto"/> 7 8 From: <tal:x replace="options/mfrom"/> … … 10 11 <tal:x replace="options/name"/>, 11 12 12 Your comment on '<a href="" tal:attributes="href obj/absolute_url" tal:content="obj/Title"/>'did not receive13 approval. Please direct any questions or concerns to <tal:x replace="options/ email"/>.13 Your comment on <tal:x tal:replace="obj/absolute_url"/> did not receive 14 approval. Please direct any questions or concerns to <tal:x replace="options/mfrom"/>. 14 15 15 16 -- qPloneComments/branches/plone-2.5/skins/qplonecomments/reply_notify_template.pt
r530 r531 3 3 tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 4 4 dummy python:request.RESPONSE.setHeader('Content-Type', 'text/html;;charset=%s' % charset); 5 organization_name options/organization_name" 5 organization_name options/organization_name; 6 obj nocall:options/obj" 6 7 >To: <tal:x replace="options/mto"/> 7 8 From: <tal:x replace="options/mfrom"/> 8 Subject: <tal:x condition="organization_name" replace="string:[$organization_name] "/>New comment awaits moderation9 Subject: Someone replied to your comment on '<tal:x replace="obj/Title"/>' 9 10 10 <tal:x define="obj nocall:options/obj">11 New comment added to page "<tal:x replace="obj/Title"/>" at: 12 <tal:x replace="obj/absolute_url"/> 13 </tal:x> 11 <tal:x replace="options/name"/>, 12 Someone replied to your comment '<tal:x replace="obj/absolute_url" />' 13 on '<tal:x replace="here/absolute_url" />'. To read the response, go to 14 '<tal:x replace="obj/absolute_url"/>'. 14 15 15 16 -- qPloneComments/branches/plone-2.5/utils.py
r530 r531 9 9 result = getattr(config_ps, prop_name, marker) 10 10 return result 11 12 13 # Send notification e-mail on Discussion_Reply14 # Possible values for state: ["approve", "published"]15 def send_email(reply, context, state="approve"):16 # Check is notification active17 notify = False18 if state=="approve":19 notify = getProp(context, "enable_approve_notification", False)20 elif state=="published":21 notify = getProp(context, "enable_published_notification", False)22 if not notify:23 return 024 25 # Get parent object26 parent = reply.inReplyTo()27 mt = parent.meta_type28 while mt == 'Discussion Item':29 try:30 parent = parent.inReplyTo()31 mt = parent.meta_type32 except:33 break34 35 # Get portal admin e-mail36 portal = getToolByName(context, 'portal_url').getPortalObject()37 from_address = portal.getProperty('email_from_address')38 39 # Get email address based on state40 to_address = None41 if state=="published":42 creator_id = parent.Creator()43 if creator_id:44 mtool = getToolByName(context, 'portal_membership')45 creator = mtool.getMemberById(creator_id)46 if creator:47 to_address = creator.getProperty('email', None)48 elif state=="approve":49 to_address = getProp(context, "email_discussion_manager", None)50 51 # Combine and send email52 if to_address:53 if state=="published":54 template = getattr(context, 'published_comment_template')55 elif state=="approve":56 template = getattr(context, 'approve_comment_template')57 58 organization_name = getProp(context, "email_subject_prefix", "")59 message = template(obj=parent, mto=to_address,60 mfrom=from_address, organization_name=organization_name)61 try:62 host = context.MailHost63 host.send( message )64 except:65 return 066 return 167 68 11 69 12 def publishDiscussion(self): … … 82 25 portal.manage_permission('Reply to item', ['Manager','Member'], 1) 83 26 84 27 def manage_mails(reply, context, action): 28 def getEnabledProperties(pp_ps): 29 return filter(lambda x: pp_ps.getProperty(x), pp_ps.propertyIds()) 30 31 def sendMails(props, actions, key): 32 for p in props: 33 if p in actions[key]: 34 send_email(reply, context, p) 35 36 prop_sheet = context.portal_properties['qPloneComments'] 37 props = getEnabledProperties(prop_sheet) 38 39 actions = { 'onPublish': ('enable_approve_user_notification', 40 'enable_reply_user_notification', 41 'enable_published_notification'), 42 'onDelete' : ('enable_rejected_user_notification',), 43 'onApprove': ('enable_approve_notification',)} 44 45 if action == 'publishing': 46 sendMails(props, actions, 'onPublish') 47 48 elif action == 'deleting': 49 sendMails(props, actions, 'onDelete') 50 51 elif action == 'aproving': 52 sendMails(props, actions, 'onApprove') 53 54 55 def send_email(reply, context, state): 56 def send(context, template, args): 57 msg = getattr(context, template)(**args) 58 return context.MailHost.send(msg) 59 60 def getEmail(obj, context): 61 userid = obj.getProperty('userid', '') 62 if userid == 'anonym': 63 return obj.getProperty('email', '') 64 else: 65 return context.portal_membership.getMemberById(userid).getProperty('email', '') 66 67 def getAdminEmail(context): 68 return context.portal_url.getPortalObject().getProperty('email_from_address') 69 70 def getParent(reply): 71 reply = reply.inReplyTo() 72 return reply.meta_type == 'Discussion Item' and getParent(reply) or reply 73 74 def getDIParent(reply): 75 r = reply.inReplyTo() 76 return r.meta_type == 'Discussion Item' and r or None 77 """ 78 parent = reply.inReplyTo() 79 mt = parent.meta_type 80 while mt == 'Discussion Item': 81 try: 82 parent = parent.inReplyTo() 83 mt = parent.meta_type 84 except: 85 break 86 return parent""" 87 88 def getParentOwnerEmail(reply, context): 89 creator_id = getParent(reply).Creator() 90 creator = getToolByName(context, 'portal_membership').getMemberById(creator_id) 91 if creator: 92 return creator.getProperty('email', '') 93 return '' 94 95 def getOrganizationName(context): 96 return getProp(context, 'email_subject_prefix', '') 97 98 args = {} 99 if reply: 100 user_email = getEmail(reply, context) 101 reply_parent = getParent(reply) 102 103 organization_name = getOrganizationName(context) 104 creator_name = reply.Creator() 105 admin_email = getAdminEmail(context) 106 107 if state == 'enable_approve_user_notification': 108 if user_email: 109 template = 'notify_comment_template' 110 args={'mto': user_email, 111 'mfrom': admin_email, 112 'obj': reply_parent, 113 'organization_name': organization_name, 114 'name': creator_name} 115 else: 116 args = {} 117 118 elif state == 'enable_rejected_user_notification': 119 if user_email: 120 template = 'rejected_comment_template' 121 args={'mto': user_email, 122 'mfrom': admin_email, 123 'obj': reply_parent, 124 'organization_name': organization_name, 125 'name': creator_name} 126 else: 127 args = {} 128 129 elif state == 'enable_reply_user_notification': 130 template = 'reply_notify_template' 131 di_parrent = getDIParent(reply) 132 if di_parrent: 133 args={'mto': getEmail(di_parrent, context), 134 'mfrom': admin_email, 135 'obj': reply_parent, 136 'organization_name': organization_name, 137 'name': creator_name} 138 else: 139 args = {} 140 141 elif state == 'enable_published_notification': 142 template = 'published_comment_template' 143 args={'mto':getParentOwnerEmail(reply, context), 144 'mfrom':admin_email, 145 'obj':reply_parent, 146 'organization_name':organization_name} 147 148 elif state == 'enable_approve_notification': 149 template = 'approve_comment_template' 150 args={'mto':getProp(context, "email_discussion_manager", None), 151 'mfrom':admin_email, 152 'obj':reply_parent, 153 'organization_name':organization_name} 154 if args: 155 return send(context, template, args) 156 else: 157 return 1
