def sendemail(self):
        """ Send confirmation email about registration """
        attendee = self.context

        try:
            directory, _f = os.path.split(os.path.abspath(__file__))
            template = os.path.join(directory, 'regemail1.txt')
            template = unicode(open(template).read())

            id = "%04d-%04d-%04d" % (randint(0,9999), randint(0,9999), randint(0,9999))
            msg = template % dict(id=id, 
                                  firstname=attendee.firstname, 
                                  key=attendee.getId(),
                                  email=attendee.email, 
                                  year=regutils.getConferenceYear(),
                                  )
            msg = msg.encode('utf-8')

            fromaddr = '*****@*****.**'
            toaddrs = [attendee.email, fromaddr,]
            
            mh = getToolByName(self.context, 'MailHost')
            mh.send(msg, mto=toaddrs, mfrom=fromaddr, 
                    encode='utf8', charset='utf8')
            
            return True

        except Exception, e:
            logging.error( "Count not send mail to: %s : %s" % (attendee.email, e))
    def addToCart(self, attendee):
        year = regutils.getConferenceYear()
        utility = component.getUtility(interfaces.IShoppingCartUtility)
        cart = utility.get(self.context, create=True)

        # Look up the price
        product_code = attendee.price_id
        prices = fetch_prices()
        if product_code in prices:
            cost = float(prices[product_code]['total_price'])
        else:
            cost = 311.49

        intids = component.getUtility(IIntIds)
        iid = intids.queryId(attendee)
        if iid is None:
            iid = intids.register(attendee)

        nitem = BPTEventLineItem()
        nitem.item_id = str(iid)  # archetypes uid
        nitem.uid = iid

        # Already in there, remove the old one
        if nitem.item_id in cart:
            del cart[nitem.item_id]

        nitem.name = "Plone Conference %s Ticket - %s" % (year,
                                                          attendee.Title())
        nitem.description = nitem.name  # description
        nitem.cost = cost
        nitem.quantity = 1
        nitem.product_code = product_code

        # add to cart
        cart[nitem.item_id] = nitem
        cart.last_item = nitem.item_id

        # send email with details to get registration back
        if cost != 0:
            email(attendee, self.context).sendemail()

        logging.debug("Added!", nitem.item_id)
    def addToCart(self, attendee):
        year = regutils.getConferenceYear()
        utility = component.getUtility( interfaces.IShoppingCartUtility )
        cart = utility.get(self.context, create=True)
        
        # Look up the price
        product_code = attendee.price_id
        prices = fetch_prices()
        if product_code in prices:
            cost = float(prices[product_code]['total_price'])
        else:
            cost = 311.49

        intids = component.getUtility( IIntIds )
        iid = intids.queryId( attendee )
        if iid is None:
            iid = intids.register( attendee )

        nitem = BPTEventLineItem()
        nitem.item_id = str(iid) # archetypes uid
        nitem.uid = iid

        # Already in there, remove the old one
        if nitem.item_id in cart:
            del cart[nitem.item_id]

        nitem.name = "Plone Conference %s Ticket - %s" % (year, attendee.Title())
        nitem.description = nitem.name # description
        nitem.cost = cost
        nitem.quantity = 1
        nitem.product_code = product_code
        
        # add to cart
        cart[ nitem.item_id ] = nitem
        cart.last_item = nitem.item_id        

        # send email with details to get registration back
        if cost != 0:
            email(attendee, self.context).sendemail()

        logging.debug("Added!", nitem.item_id)
Exemple #4
0
    def sendemail(self):
        """ Send confirmation email about registration """
        attendee = self.context

        try:
            directory, _f = os.path.split(os.path.abspath(__file__))
            template = os.path.join(directory, 'regemail1.txt')
            template = unicode(open(template).read())

            id = "%04d-%04d-%04d" % (randint(0, 9999), randint(
                0, 9999), randint(0, 9999))
            msg = template % dict(
                id=id,
                firstname=attendee.firstname,
                key=attendee.getId(),
                email=attendee.email,
                year=regutils.getConferenceYear(),
            )
            msg = msg.encode('utf-8')

            fromaddr = '*****@*****.**'
            toaddrs = [
                attendee.email,
                fromaddr,
            ]

            mh = getToolByName(self.context, 'MailHost')
            mh.send(msg,
                    mto=toaddrs,
                    mfrom=fromaddr,
                    encode='utf8',
                    charset='utf8')

            return True

        except Exception, e:
            logging.error("Count not send mail to: %s : %s" %
                          (attendee.email, e))
 def getConferenceYear(self):
     return regutils.getConferenceYear()
class RegistrationForm(group.GroupForm, form.Form):
    grok.name('registration')
    grok.require('zope2.View')
    grok.context(IRegistrationFolder)

    fields = field.Fields(IAttendee).select('uid')

    groups = (ContactGroup, TicketGroup, PreferencesGroup, BadgeGroup,
              PrivacyGroup)

    template = ViewPageTemplateFile('templates/registration_form.pt')

    label = _(u"Register for Plone Conference %s" %
              regutils.getConferenceYear())

    enable_form_tabbing = False

    def getConferenceYear(self):
        return regutils.getConferenceYear()

    def update(self):
        # disable Plone's editable border
        self.request.set('disable_border', True)
        content = self.getContent()
        if content is not None:
            self.groups = [g(content, self.request, self) for g in self.groups]
        else:
            self.ignoreContext = True

        # call the base class version - this is very important!
        super(RegistrationForm, self).update()

    def updateWidgets(self):
        super(RegistrationForm, self).updateWidgets()
        self.widgets['uid'].mode = HIDDEN_MODE

    def getContent(self):

        key = self.request.form.get('key')
        if not key:
            try:
                data, errors = self.extractData(setErrors=False)
                key = data.get('uid')
            except AttributeError:
                pass

        if key:
            try:
                key = int(key)
            except ValueError:
                return

            return self.getattendee(key)

    def getattendee(self, uid):
        intids = component.getUtility(IIntIds)
        wf = getToolByName(self.context, 'portal_workflow')
        for attendee in self.context.attendees.contentValues():
            if intids.getId(attendee) == uid:
                # XXX add check for workflow state == unpa
                if wf.getStatusOf("attendee_workflow",
                                  attendee)["review_state"] == 'unpaid':
                    return attendee

    @button.buttonAndHandler(_(u'Register'))
    def handleApply(self, action):

        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        uid = data.get('uid')
        if uid:  # this is an existing registration
            attendee = self.getattendee(uid)
            if attendee is None:
                # we should not get here... tampering alert
                raise ValueError, "Tampering with the form!"

            for group in self.groups:
                applyChanges(group, attendee, data)

        else:
            # Create the attendee object in the attendees folder
            attendees = self.context.attendees
            del data['uid']  # need to remove uid before adding
            attendee = createContentInContainer(
                attendees,
                'netsight.conferenceregistration.attendee',
                checkConstraints=False,
                **data)

        # Add attendee to shopping cart

        self.addToCart(attendee)

        #        IStatusMessage(self.request).addStatusMessage(
        #                _(u"Thank you for your registration."),
        #                "info"
        #            )

        portal_url = getToolByName(
            self.context, 'portal_url').getPortalObject().absolute_url()
        return self.request.response.redirect(
            '%s/registrations/@@getpaid-cart' % portal_url)

    def addToCart(self, attendee):
        year = regutils.getConferenceYear()
        utility = component.getUtility(interfaces.IShoppingCartUtility)
        cart = utility.get(self.context, create=True)

        # Look up the price
        product_code = attendee.price_id
        prices = fetch_prices()
        if product_code in prices:
            cost = float(prices[product_code]['total_price'])
        else:
            cost = 311.49

        intids = component.getUtility(IIntIds)
        iid = intids.queryId(attendee)
        if iid is None:
            iid = intids.register(attendee)

        nitem = BPTEventLineItem()
        nitem.item_id = str(iid)  # archetypes uid
        nitem.uid = iid

        # Already in there, remove the old one
        if nitem.item_id in cart:
            del cart[nitem.item_id]

        nitem.name = "Plone Conference %s Ticket - %s" % (year,
                                                          attendee.Title())
        nitem.description = nitem.name  # description
        nitem.cost = cost
        nitem.quantity = 1
        nitem.product_code = product_code

        # add to cart
        cart[nitem.item_id] = nitem
        cart.last_item = nitem.item_id

        # send email with details to get registration back
        if cost != 0:
            email(attendee, self.context).sendemail()

        logging.debug("Added!", nitem.item_id)
 def getConferenceYear(self):
     return regutils.getConferenceYear()