def handleNewRegistration(reg, event):
    parentevent = reg.__parent__.__parent__
    regfolderish = reg.__parent__
    reg.manage_setLocalRoles('admin', ["Owner"])
    reg.reindexObjectSecurity()

    hasWaitingList = parentevent.enableWaitingList
    hasPrivateReg = parentevent.privateRegistration
    maxreg = parentevent.maxRegistrations
    numRegApproved = getNumApprovedAndConfirmed(regfolderish)

    workflowTool = getToolByName(reg, "portal_workflow")

    # private registration means manual adding of registrations
    if hasPrivateReg:
        #workflowTool.doActionFor(reg, 'approve')
        executeUnderSpecialRole(parentevent.__parent__,
                                "Manager",
                                workflowTool.doActionFor,
                                reg,
                                'approve')
    # haven't hit max, 'approve'
    elif maxreg == None or numRegApproved < maxreg:
        #workflowTool.doActionFor(reg, 'approve')
        executeUnderSpecialRole(parentevent.__parent__,
                                "Manager",
                                workflowTool.doActionFor,
                                reg,
                                'approve')
        sendEMail(parentevent, 'thank you', [reg.email], reg)
    # waiting list, and hit max == remain 'submitted' (on waiting list)
    elif hasWaitingList:
        sendEMail(parentevent, 'on waiting list', [reg.email], reg)
    # all other cases, 'deny'
    else:
        workflowTool.doActionFor(reg, 'deny')
        sendEMail(parentevent, 'registration full', [reg.email], reg)
Exemplo n.º 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