Changeset 3535 in products for quintagroup.mailer/branches


Ignore:
Timestamp:
Aug 28, 2012 10:02:35 AM (12 years ago)
Author:
vmaksymiv
Message:

PPP fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.mailer/branches/devel/quintagroup/mailer/actions/mail.py

    r3527 r3535  
    22from OFS.SimpleItem import SimpleItem 
    33from zope.component import adapts, getUtility 
    4 from zope.component.interfaces import ComponentLookupError 
    54from zope.interface import Interface, implements 
    65from zope.formlib import form 
    76from zope import schema 
    87 
    9 from plone.app.contentrules.browser.formhelper import AddForm, EditForm  
     8from plone.app.contentrules.browser.formhelper import AddForm, EditForm 
    109from plone.contentrules.rule.interfaces import IRuleElementData, IExecutable 
    1110 
     
    1413from Products.CMFPlone.utils import safe_unicode 
    1514 
    16 from zope.sendmail.interfaces import IQueuedMailDelivery, IMailDelivery 
     15from zope.sendmail.interfaces import IMailDelivery 
    1716import email.MIMEText 
    1817import email.Header 
     
    2019attr_rexp = re.compile("\$\{item\.(\w+)\}") 
    2120 
     21 
    2222class IMailAction(Interface): 
    2323    """Definition of the configuration available for a mail action 
    2424    """ 
    25     subject = schema.TextLine(title=_(u"Subject"), 
    26             description=_(u"Subject of the message. ${title} replaced with object title"), 
    27             required=True) 
     25    subject = schema.TextLine(title=_(u"Subject"), description=_( 
     26        u"Subject of the message. ${title} replaced with object title"), 
     27        required=True) 
    2828 
    29     groups = schema.TextLine(title=_(u"Recipients"), 
    30             description=_("The group of users for whom you want to " 
    31                    "send this message. To send it to different groups, just separate them with ,"), 
    32             required=True) 
     29    groups = schema.TextLine(title=_(u"Recipients"), description=_( 
     30        "The group of users for whom you want to send this message. " 
     31        "To send it to different groups, just separate them with ,"), 
     32        required=True) 
    3333 
    34     message = schema.Text(title=_(u"Message"), 
    35             description=_(u"Type in here the message that you \ 
    36 want to mail. Some defined content can be replaced: ${title} will be replaced \ 
    37 by the title of the item. ${url} will be replaced by the URL of the item.\ 
    38 ${description} will be replaced by the description of the item.\ 
    39 ${item.<attribute>} will be replaced by the attribute of the item."), 
    40             required=True) 
     34    message = schema.Text(title=_(u"Message"), description=_( 
     35        u"Type in here the message that you want to mail. Some defined " 
     36        "content can be replaced: ${title} will be replaced by the title of " 
     37        "the item. ${url} will be replaced by the URL of the item. " 
     38        "${description} will be replaced by the description of the item. " 
     39        "${item.<attribute>} will be replaced by the attribute of the item."), 
     40        required=True) 
     41 
    4142 
    4243class MailAction(SimpleItem): 
     
    6970        self.event = event 
    7071 
    71  
    7272    def getEmailAddresses(self, groups): 
    73         mtool = getToolByName(self.context, 'portal_membership') 
    7473        users_tool = getToolByName(self.context, 'acl_users') 
    7574        addresses = [] 
     
    8483        return addresses 
    8584 
    86  
    8785    def __call__(self): 
    8886        groups = self.element.groups.split(',') 
    89         recipients = self.getEmailAddresses(groups) # list of email addresses 
     87        recipients = self.getEmailAddresses(groups)  # list of email addresses 
    9088 
    9189        mailer = getUtility(IMailDelivery, 'iw.mailer') 
     
    10199        from_address = portal.getProperty('email_from_address') 
    102100        if not from_address: 
    103             raise ValueError, 'You must enter an email in the portal properties' 
     101            raise ValueError('You must enter an email in the portal properties') 
    104102        from_name = portal.getProperty('email_from_name') 
    105103        source = "%s <%s>" % (from_name, from_address) 
    106104 
    107105        subject = self.element.subject.replace("${title}", event_title) 
    108          
     106 
    109107        for attr in attr_rexp.findall(subject): 
    110108            if getattr(obj, attr, None) is None: 
    111109                continue 
    112             if callable(getattr(obj, attr)):  
     110            if callable(getattr(obj, attr)): 
    113111                value = safe_unicode(getattr(obj, attr)()) 
    114             else:  
     112            else: 
    115113                value = safe_unicode(getattr(obj, attr)) 
    116114            subject = subject.replace("${item.%s}" % attr, unicode(value)) 
     
    122120            if getattr(obj, attr, None) is None: 
    123121                continue 
    124             if callable(getattr(obj, attr)):  
     122            if callable(getattr(obj, attr)): 
    125123                value = safe_unicode(getattr(obj, attr)()) 
    126             else:  
     124            else: 
    127125                value = safe_unicode(getattr(obj, attr)) 
    128126            body = body.replace("${item.%s}" % attr, unicode(value)) 
    129          
     127 
    130128        for userid, recipient in recipients: 
    131129            msgbody = body.replace('${userid}', userid) 
     
    137135            mailer.send(source, [recipient], msg.as_string()) 
    138136        return True 
     137 
    139138 
    140139class MailAddForm(AddForm): 
     
    152151        return a 
    153152 
     153 
    154154class MailEditForm(EditForm): 
    155155    """ 
     
    160160    description = _(u"A mail action can mail different recipient.") 
    161161    form_name = _(u"Configure element") 
    162  
Note: See TracChangeset for help on using the changeset viewer.