def getDefaultValue(self, field):
     return getDefaultValueForCertField(field)
    def _handlePost(self, REQUEST=None):
        emailtype = REQUEST.form['emailtype']
        tolist = REQUEST.form['emailtoaddresses'].splitlines()
        attachments = []

        # get attachments
        if REQUEST.form['attachment1'].filename != '':
            attachments.append({
                'name': REQUEST.form['attachment1'].filename,
                'data': REQUEST.form['attachment1'].read()})
        if REQUEST.form['attachment2'].filename != '':
            attachments.append({
                'name': REQUEST.form['attachment2'].filename,
                'data': REQUEST.form['attachment2'].read()})
        if REQUEST.form['attachment3'].filename != '':
            attachments.append({
                'name': REQUEST.form['attachment3'].filename,
                'data': REQUEST.request.form['attachment3'].read()})
        if REQUEST.form['attachment4'].filename != '':
            attachments.append({
                'name': REQUEST.form['attachment4'].filename,
                'data': REQUEST.form['attachment4'].read()})

        # if a certificate is requested, then generate the certificate, and add
        # it to the attachment list
        if 'certreq' in REQUEST.form and REQUEST.form['certreq'] == 'on':
            # get registrations
            regs = []
            for r in self.context.registrations:
                reg = self.context.registrations[r]
                for toemail in tolist:
                    if reg.email in toemail:
                        regs.append(reg)
                        break

            # get portal url
            urltool = getToolByName(self.context, 'portal_url')
            portal = urltool.getPortalObject()
            portal_url = portal.absolute_url()

            # get cert info
            certinfo = {}
            for key in ["title", "subtitle", "prenamedesc", "postnamedesc",
                        "awardtitle", "date", "sigdesc", "border"]:
                certinfo['cert%s' % (key,)] = getDefaultValueForCertField(key)

            # get pdf content
            pdf = generateCertificate(registrations=regs,
                                      portal_url=portal_url,
                                      underlines_for_empty_values=False,
                                      context=self.context,
                                      **certinfo)

            # add to attachments
            attachments.append({
                    'name': 'certificate.pdf',
                    'data': pdf['file']
                })

        mfrom = REQUEST.form['emailfromaddress']
        msubject = REQUEST.form['emailsubject']
        mbody = REQUEST.form['emailbody']
        for toaddress in tolist:
            # should return a list of one since emails are unique in this
            # system
            reg = [self.__parent__.registrations[a]
                    for a in self.__parent__.registrations
                     if self.__parent__.registrations[a].email in toaddress]
            # if there is no reg, then just send an email with no registration
            # confirmation link, otherwise include the confirmation link (if
            # the event is configured to include one)
            if len(reg) <= 0:
                sendEMail(self.__parent__, emailtype, [toaddress], None,
                          attachments, mfrom, msubject, mbody)
            else:
                sendEMail(self.__parent__, emailtype, [toaddress], reg[0],
                          attachments, mfrom, msubject, mbody)

        self.emailSent = True