Changeset 531

Show
Ignore:
Timestamp:
09/22/06 09:20:35
Author:
crchemist
Message:

Add possibility to notify user in rejection or approving his reply.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneComments/branches/plone-2.5/Extensions/Install.py

    r530 r531  
    99 
    1010import string 
    11 try: 
    12     True 
    13 except: 
    14     True = 1 
    15     False = 0 
    1611 
    1712def setupSkin(self, out, layers): 
     
    6863        out.write("Adding %s property sheet to portal_properies\n" % 'qPloneComments' ) 
    6964    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) 
    7766    # Tern on Anonymous commenting 
    7867    self.manage_permission(ReplyToItem, ['Anonymous','Manager','Member'], 1) 
     
    120109 
    121110 
    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  
     111def 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') ) 
    127117 
    128118def uninstall(self) : 
  • qPloneComments/branches/plone-2.5/config.py

    r530 r531  
    88CONFIGLET_NAME = "qPloneComments setup" 
    99 
     10PROPERTIES = (('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  
    1010# Patching createReply method of  
    1111# Products.CMFDefault.DiscussionItem.DiscussionItemContainer 
    12 def createReply( self, title, text, Creator=None ): 
     12def createReply( self, title, text, Creator=None, email=''): 
    1313    """ 
    1414        Create a reply in the proper place 
     
    3131 
    3232    pm = getToolByName(self, 'portal_membership') 
    33     value = 0 
     33 
    3434    if pm.isAnonymousUser(): 
    35         value = 1 
    36     if item.hasProperty('isAnon'): 
    37         item.manage_changeProperties({'id':'isAnon','value':value}) 
     35        userid = 'anonym' 
    3836    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') 
    4041 
    4142    item.review_state="private" 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_publish_comment.py

    r530 r531  
    1010from Products.CMFPlone import transaction_note 
    1111from Products.CMFCore.utils import getToolByName 
    12 from Products.qPloneComments.utils import publishDiscussion, send_email 
     12from Products.qPloneComments.utils import publishDiscussion,  
    1313 
    1414if obj is None: 
     
    2525publishDiscussion(reply) 
    2626 
    27 send_notification_message = send_email(reply, container, state="published") 
    2827 
    2928portal_status_message='Comment+successfully+published' 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_reply.cpy

    r530 r531  
    1111from Products.PythonScripts.standard import url_quote_plus 
    1212from Products.CMFCore.utils import getToolByName 
    13 from Products.qPloneComments.utils import send_email 
     13from Products.qPloneComments.utils import manage_mails 
    1414from Products.CMFPlone import PloneMessageFactory as _ 
    1515mtool = getToolByName(context, 'portal_membership') 
    1616dtool = getToolByName(context, 'portal_discussion') 
     17 
    1718req = context.REQUEST 
    1819pp = getToolByName(context,'portal_properties') 
    1920# Get properties 
    20 isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', None) 
    21 ifModerate = pp['qPloneComments'].getProperty('enable_moderation', None); 
     21isForAnonymous = pp['qPloneComments'].getProperty('enable_anonymous_commenting', False) 
     22ifModerate = pp['qPloneComments'].getProperty('enable_moderation', False) 
     23requireEmail = pp['qPloneComments'].getProperty('require_email', False) 
    2224if username or password: 
    2325    # The user username/password inputs on on the comment form were used, 
     
    6062        comment_creator = member.getUserName() 
    6163tb = dtool.getDiscussionFor(context) 
    62 id = tb.createReply(title=subject, text=body_text, Creator=comment_creator) 
     64if 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) 
     71else: 
     72    id = tb.createReply(title=subject, text=body_text, Creator=comment_creator) 
     73 
    6374reply = tb.getReply(id) 
    6475 
     
    6879 
    6980parent = tb.aq_parent 
    70 # Send notification e-mail 
    71 send_notification_message = send_email(reply, context, state="approve"
     81# Send notification e-mail   
     82manage_mails(reply, context, 'aproving'
    7283if not ifModerate: 
    73     send_notification_message += send_email(reply, context, state="published"
     84    manage_mails(reply, context, 'publishing'
    7485 
    7586# return to the discussable object. 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/2.5/discussion_reply_form.cpt

    r530 r531  
    109109                    </div> 
    110110                </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> 
    111130            </div> 
    112131 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/notify_comment_template.pt

    r530 r531  
    33     tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 
    44                 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" 
    67>To: <tal:x replace="options/mto"/> 
    78From: <tal:x replace="options/mfrom"/> 
     
    910 
    1011<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"/> 
     12Your comment on '<tal:x replace="obj/absolute_url" />' has been 
     13published. To see your comment, go to <tal:x replace="obj/absolute_url" /> 
    1414 
    1515-- 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_comments_setup.cpy

    r530 r531  
    1010from Products.CMFCore.utils import getToolByName 
    1111from Products.qPloneComments.utils import setAnonymCommenting 
    12 #from AccessControl.Permission import Permission 
     12 
    1313form = context.REQUEST.form 
    1414pp = getToolByName(context, 'portal_properties') 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_comments_setup_form.cpt

    r530 r531  
    3333    <!-- End of tabs --> 
    3434    <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> 
    3636 
    3737        <a href="" 
     
    7474 
    7575                <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', ''); 
    8888                                           tabindex tabindex/next;"/> 
    8989 
    9090                    <label i18n:translate="label_require_anonym_email"  
    91                            for="isRequireAnonymEmail">Require Anonym Email.</label> 
     91                           for="requireEmail">Require Anonym Email.</label> 
    9292 
    9393                </div> 
     
    110110                    <label i18n:translate="label_anonymous_commenting"  
    111111                           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> 
    151112                </div> 
    152113 
     
    160121                           tabindex ="" 
    161122                           tal:attributes="value isEnabledManagerModeration; 
    162                                           checked python:test(isEnabledManagerModeration, 'True', ''); 
     123                                           checked python:test(isEnabledManagerModeration, 'True', ''); 
    163124                                           tabindex tabindex/next;"/> 
    164125 
     
    180141                        The e-mail address where notifications about adding new comments will be sent. 
    181142                    </div> 
    182                      
     143 
    183144                    <div tal:content="error">Validation error output</div> 
    184145 
     
    196157                                 organization_name python:props_sheet.getProperty(property_id, '');" 
    197158                     tal:condition="python:props_sheet.hasProperty(property_id)"> 
    198          
     159 
    199160                    <label i18n:translate="label_organization_name">Email subject prefix (organization name)</label> 
    200          
     161 
    201162                    <div class="formHelp" id="organization_name_help" 
    202163                         i18n:translate="help_organization_name"> 
    203164                        You can change notification message templates customizing 'approve_comment_template' and 'published_comment_template' from qplonecomments skin. 
    204165                    </div> 
    205                      
     166 
    206167                    <input name="organization_name" 
    207168                           value="" 
     
    213174                </div> 
    214175 
    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> 
    228309        </form> 
    229310    </div> 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/prefs_recent_comments_delete.cpy

    r530 r531  
    1010 
    1111from Products.CMFCore.utils import getToolByName 
     12from Products.qPloneComments.utils import manage_mails 
    1213portal_discussion = getToolByName(context, "portal_discussion") 
    1314portal_catalog = getToolByName(context, "portal_catalog") 
     
    2526        talkback = parent = comment.aq_parent 
    2627 
    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') 
    2831 
    2932psm = 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  
    88##title= 
    99## 
    10  
    1110from Products.CMFCore.utils import getToolByName 
    12 from Products.qPloneComments.utils import publishDiscussion, send_email 
     11from Products.qPloneComments.utils import publishDiscussion, manage_mails 
    1312 
    1413request = context.REQUEST 
     
    2019    comment = portal_catalog(id=comment_id,portal_type='Discussion Item')[0].getObject() 
    2120    publishDiscussion(comment) 
    22     send_notification_message = send_email(comment, container, state="published"
     21    manage_mails(comment, container, action='publishing'
    2322 
    2423psm = 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  
    33     tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 
    44                 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" 
    67>To: <tal:x replace="options/mto"/> 
    78From: <tal:x replace="options/mfrom"/> 
     
    1011<tal:x replace="options/name"/>, 
    1112 
    12 Your comment on '<a href="" tal:attributes="href obj/absolute_url" tal:content="obj/Title"/>' did not receive 
    13 approval. Please direct any questions or concerns to <tal:x replace="options/email"/>. 
     13Your comment on <tal:x tal:replace="obj/absolute_url"/> did not receive 
     14approval. Please direct any questions or concerns to <tal:x replace="options/mfrom"/>. 
    1415 
    1516-- 
  • qPloneComments/branches/plone-2.5/skins/qplonecomments/reply_notify_template.pt

    r530 r531  
    33     tal:define="charset here/portal_properties/site_properties/default_charset|string:utf-8; 
    44                 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" 
    67>To: <tal:x replace="options/mto"/> 
    78From: <tal:x replace="options/mfrom"/> 
    8 Subject: <tal:x condition="organization_name" replace="string:[$organization_name] "/>New comment awaits moderation 
     9Subject: Someone replied to your comment on '<tal:x replace="obj/Title"/>' 
    910 
    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"/>, 
     12Someone replied to your comment '<tal:x replace="obj/absolute_url" />' 
     13on '<tal:x replace="here/absolute_url" />'. To read the response, go to 
     14'<tal:x replace="obj/absolute_url"/>'. 
    1415 
    1516-- 
  • qPloneComments/branches/plone-2.5/utils.py

    r530 r531  
    99        result =  getattr(config_ps, prop_name, marker) 
    1010    return result 
    11  
    12  
    13 # Send notification e-mail on Discussion_Reply  
    14 # Possible values for state: ["approve", "published"] 
    15 def send_email(reply, context, state="approve"): 
    16     # Check is notification active 
    17     notify = False 
    18     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 0 
    24  
    25     # Get parent object 
    26     parent = reply.inReplyTo() 
    27     mt = parent.meta_type 
    28     while mt == 'Discussion Item': 
    29         try: 
    30            parent = parent.inReplyTo() 
    31            mt = parent.meta_type 
    32         except: 
    33            break 
    34  
    35     # Get portal admin e-mail 
    36     portal = getToolByName(context, 'portal_url').getPortalObject() 
    37     from_address = portal.getProperty('email_from_address') 
    38  
    39     # Get email address based on state 
    40     to_address = None 
    41     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 email 
    52     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.MailHost 
    63             host.send( message ) 
    64         except: 
    65             return 0 
    66     return 1 
    67  
    6811 
    6912def publishDiscussion(self): 
     
    8225        portal.manage_permission('Reply to item', ['Manager','Member'], 1) 
    8326 
    84      
     27def 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 
     55def 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