コード例 #1
0
    def _handlePost(self, REQUEST=None):
        regs = [self.context.registrations[a]
                    for a in REQUEST.form
                     if a != 'submit' \
                        and a[:4] != 'cert' \
                        and REQUEST.form[a] == 'on']

        certinfo = {}
        for key in ['certtitle', 'certsubtitle', 'certprenamedesc',
                    'certpostnamedesc', 'certawardtitle', 'certdate',
                    'certsigdesc', 'certborder']:
            if key not in REQUEST.form or REQUEST.form[key] == None:
                certinfo[key] = ''
            else:
                certinfo[key] = REQUEST.form[key]

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

        pdf = generateCertificate(regs,
                                  portal_url,
                                  True,
                                  context=self.context,
                                  **certinfo)

        REQUEST.response.setHeader('Content-Disposition',
                                   'attachment; filename=%s' % pdf['filename'])
        REQUEST.response.setHeader('Content-Type', 'application/pdf')
        REQUEST.response.setHeader('Content-Length', len(pdf['file']))
        REQUEST.response.setHeader('Last-Modified',
                                   DateTime.rfc822(DateTime()))
        REQUEST.response.setHeader('Cache-Control', 'no-store')
        REQUEST.response.setHeader('Pragma', 'no-cache')
        REQUEST.response.write(pdf['file'])
コード例 #2
0
    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