Example #1
0
def fix_bookings_email(ctx=None):
    """Add email attribute to booking records from the corresponding order.
    """
    portal = getSite()
    soup = get_bookings_soup(portal)
    data = soup.storage.data
    need_rebuild = False
    for item in data.values():
        update = False
        try:
            item.attrs['email']
        except KeyError:
            update = True
        if not update:
            continue

        order = get_order(portal, item.attrs['order_uid'])
        email = order.attrs.get('personal_data.email', 'n/a')

        item.attrs['email'] = email
        need_rebuild = True
        logging.info("Added email to booking {0}".format(item.attrs['uid']))
    if need_rebuild:
        soup.rebuild()
        logging.info("Rebuilt bookings catalog")
def fix_bookings_email(ctx=None):
    """Add email attribute to booking records from the corresponding order.
    """
    portal = getSite()
    soup = get_bookings_soup(portal)
    data = soup.storage.data
    need_rebuild = False
    for item in data.values():
        update = False
        try:
            item.attrs['email']
        except KeyError:
            update = True
        if not update:
            continue

        order = get_order(portal, item.attrs['order_uid'])
        email = order.attrs.get('personal_data.email', 'n/a')

        item.attrs['email'] = email
        need_rebuild = True
        logging.info(
            u"Added email to booking {0}".format(item.attrs['uid'])
        )
    if need_rebuild:
        soup.rebuild()
        logging.info("Rebuilt bookings catalog")
Example #3
0
def customers_vocab_for(user=None):
    """Customers vocabulary for given or currently authenticated user.
    """
    # XXX: expect context as argument
    context = getSite()
    order_uids = get_vendor_order_uids_for(context, user=user)
    res = set(get_order(context, uid).attrs['creator'] for uid in order_uids)
    vocab = []
    for creator in res:
        if not creator:
            # Development edge case: creator might be None
            continue
        customer = plone.api.user.get(userid=creator)
        if customer:
            # soft dep on bda.plone.shop
            first = customer.getProperty('firstname', '')
            last = customer.getProperty('lastname', '')
            # fallback
            full = customer.getProperty('fullname', '')
            name = (first or last) and '{0}, {1}'.format(first, last) or full
        else:
            name = creator
        title = name and '{0} ({1})'.format(creator, name) or creator
        vocab.append((creator, title))
    return vocab
 def id(self):
     uid = self.request.get('uid', None)
     try:
         order = get_order(self.context, uid)
     except ValueError:
         return None
     return order.attrs.get('ordernumber')
Example #5
0
 def id(self):
     uid = self.request.get('uid', None)
     try:
         order = get_order(self.context, uid)
     except ValueError:
         return None
     return order.attrs.get('ordernumber')
Example #6
0
def customers_vocab_for(user=None):
    """Customers vocabulary for given or currently authenticated user.
    """
    # XXX: expect context as argument
    context = getSite()
    order_uids = get_vendor_order_uids_for(context, user=user)
    res = set(get_order(context, uid).attrs['creator'] for uid in order_uids)
    vocab = []
    for creator in res:
        if not creator:
            # Development edge case: creator might be None
            continue
        customer = plone.api.user.get(userid=creator)

        email = None
        name = None
        if customer:
            # soft dep on bda.plone.shop
            first = safe_unicode(customer.getProperty('firstname', ''))
            last = safe_unicode(customer.getProperty('lastname', ''))
            email = safe_unicode(customer.getProperty('email', ''))
            # fallback
            full = safe_unicode(customer.getProperty('fullname', ''))
            name = u'{0}, {1}'.format(last, first) if (first or last) else full

        if email and name:
            title = u'{0} ({1}) - {2}'.format(name, creator, email)
        else:
            title = creator
        vocab.append((creator, title))

    # Sort the vocab by title, normalized like sortable_title
    vocab = sorted(vocab, key=lambda x: baseNormalize(x[1]).lower())

    return vocab
def customers_vocab_for(user=None):
    """Customers vocabulary for given or currently authenticated user.
    """
    # XXX: expect context as argument
    context = getSite()
    order_uids = get_vendor_order_uids_for(context, user=user)
    res = set(get_order(context, uid).attrs['creator'] for uid in order_uids)
    vocab = []
    for creator in res:
        if not creator:
            # Development edge case: creator might be None
            continue
        customer = plone.api.user.get(userid=creator)

        email = None
        name = None
        if customer:
            # soft dep on bda.plone.shop
            first = safe_unicode(customer.getProperty('firstname', ''))
            last = safe_unicode(customer.getProperty('lastname', ''))
            email = safe_unicode(customer.getProperty('email', ''))
            # fallback
            full = safe_unicode(customer.getProperty('fullname', ''))
            name = u'{0}, {1}'.format(last, first) if (first or last) else full

        if email and name:
            title = u'{0} ({1}) - {2}'.format(name, creator, email)
        else:
            title = creator
        vocab.append((creator, title))

    # Sort the vocab by title, normalized like sortable_title
    vocab = sorted(vocab, key=lambda x: baseNormalize(x[1]).lower())

    return vocab
def customers_vocab_for(user=None):
    """Customers vocabulary for given or currently authenticated user.
    """
    # XXX: expect context as argument
    context = getSite()
    order_uids = get_vendor_order_uids_for(context, user=user)
    res = set(get_order(context, uid).attrs['creator'] for uid in order_uids)
    vocab = []
    for creator in res:
        if not creator:
            # Development edge case: creator might be None
            continue
        customer = plone.api.user.get(userid=creator)
        if customer:
            # soft dep on bda.plone.shop
            first = customer.getProperty('firstname', '')
            last = customer.getProperty('lastname', '')
            # fallback
            full = customer.getProperty('fullname', '')
            name = (first or last) and '{0}, {1}'.format(first, last) or full
        else:
            name = creator
        title = name and '{0} ({1})'.format(creator, name) or creator
        vocab.append((creator, title))
    return vocab
 def _get_ordervalue(self, colname, record):
     """
     helper method to get the values which are saved on the order and not
     on the booking itself.
     """
     order = get_order(self.context, record.attrs.get('order_uid'))
     value = order.attrs.get(colname, '')
     return value
Example #10
0
 def _get_ordervalue(self, colname, record):
     """
     helper method to get the values which are saved on the order and not
     on the booking itself.
     """
     order = get_order(self.context, record.attrs.get('order_uid'))
     value = order.attrs.get(colname, '')
     return value
 def _sendmail(self, notifier, uid, tpl, subject):
     order = get_order(self.context, uid)
     data = {}
     for key in TEMPLATE.defaults:
         if key in order.attrs:
             data[key] = order.attrs[key]
     body = TEMPLATE(tpl, data)
     notifier.send(subject, body, order.attrs['personal_data.email'])
Example #12
0
 def id(self):
     uid = self.request.get('uid', None)
     payment = Payments(self.context).get('dibs')
     payment.succeed(self.request, uid)
     
     try:
         order = get_order(self.context, uid)
     except ValueError:
         return None
     return order.attrs.get('ordernumber')
Example #13
0
def notify_payment_success(event):
    """Send notification mail after payment succeed.
    """
    order = get_order(event.context, event.order_uid)
    templates = dict()
    templates.update(get_order_templates(event.context))
    templates['item_listing_callback'] = create_mail_listing
    templates['order_total_callback'] = create_order_total
    templates['payment_text_callback'] = create_payment_text
    templates['global_text_callback'] = create_global_text
    do_notify(event.context, order, templates)
Example #14
0
 def __call__(self):
     transition = self.request['transition']
     uid = self.request['uid']
     order = get_order(self.context, uid)
     vendor_uid = self.request.form.get('vendor', '')
     if vendor_uid:
         vendor_uids = [vendor_uid]
         vendor = get_vendor_by_uid(self.context, vendor_uid)
         user = plone.api.user.get_current()
         if not user.checkPermission(permissions.ModifyOrders, vendor):
             raise Unauthorized
     else:
         vendor_uids = get_vendor_uids_for()
         if not vendor_uids:
             raise Unauthorized
     transitions = OrderTransitions(self.context)
     order = transitions.do_transition(uid, vendor_uids, transition)
     return self.dropdown(self.context, self.request, order).render()
Example #15
0
def save_contact(event):
    """``bda.plone.checkout.interfaces.ICheckoutDone`` subscriber for storing
    order contact to soup.
    """
    order = get_order(event.context, event.uid)
    lookup_contact(event.context, extract_contact(order))
Example #16
0
    def get_csv(self):
        context = self.context

        # prepare csv writer
        sio = StringIO()
        ex = csv.writer(sio, dialect='excel-colon', quoting=csv.QUOTE_MINIMAL)
        # exported column keys as first line
        ex.writerow(ORDER_EXPORT_ATTRS + COMPUTED_ORDER_EXPORT_ATTRS.keys() +
                    BOOKING_EXPORT_ATTRS +
                    COMPUTED_BOOKING_EXPORT_ATTRS.keys())

        bookings_soup = get_bookings_soup(context)

        # First, filter by allowed vendor areas
        vendor_uids = get_vendor_uids_for()
        query_b = Any('vendor_uid', vendor_uids)

        # Second, query for the buyable
        query_cat = {}
        query_cat['object_provides'] = IBuyable.__identifier__
        query_cat['path'] = '/'.join(context.getPhysicalPath())
        cat = getToolByName(context, 'portal_catalog')
        res = cat(**query_cat)
        buyable_uids = [IUUID(it.getObject()) for it in res]

        query_b = query_b & Any('buyable_uid', buyable_uids)

        all_orders = {}
        for booking in bookings_soup.query(query_b):
            booking_attrs = []
            # booking export attrs
            for attr_name in BOOKING_EXPORT_ATTRS:
                val = self.export_val(booking, attr_name)
                booking_attrs.append(val)
            # computed booking export attrs
            for attr_name in COMPUTED_BOOKING_EXPORT_ATTRS:
                cb = COMPUTED_BOOKING_EXPORT_ATTRS[attr_name]
                val = cb(context, booking)
                val = cleanup_for_csv(val)
                booking_attrs.append(val)

            # create order_attrs, if it doesn't exist
            order_uid = booking.attrs.get('order_uid')
            if order_uid not in all_orders:
                order = get_order(context, order_uid)
                order_data = OrderData(context,
                                       order=order,
                                       vendor_uids=vendor_uids)
                order_attrs = []
                # order export attrs
                for attr_name in ORDER_EXPORT_ATTRS:
                    val = self.export_val(order, attr_name)
                    order_attrs.append(val)
                # computed order export attrs
                for attr_name in COMPUTED_ORDER_EXPORT_ATTRS:
                    cb = COMPUTED_ORDER_EXPORT_ATTRS[attr_name]
                    val = cb(self.context, order_data)
                    val = cleanup_for_csv(val)
                    order_attrs.append(val)
                all_orders[order_uid] = order_attrs

            ex.writerow(all_orders[order_uid] + booking_attrs)

            # TODO: also set for contextual exports? i'd say no.
            # booking.attrs['exported'] = True
            # bookings_soup.reindex(booking)

        ret = sio.getvalue()
        sio.close()
        return ret
Example #17
0
    def get_csv(self):
        context = self.context

        # prepare csv writer
        sio = StringIO()
        ex = csv.writer(sio, dialect='excel-colon', quoting=csv.QUOTE_MINIMAL)
        # exported column keys as first line
        ex.writerow(ORDER_EXPORT_ATTRS +
                    list(COMPUTED_ORDER_EXPORT_ATTRS.keys()) +
                    BOOKING_EXPORT_ATTRS +
                    list(COMPUTED_BOOKING_EXPORT_ATTRS.keys()))

        bookings_soup = get_bookings_soup(context)

        # First, filter by allowed vendor areas
        vendor_uids = get_vendor_uids_for()
        query_b = Any('vendor_uid', vendor_uids)

        # Second, query for the buyable
        query_cat = {}
        query_cat['object_provides'] = IBuyable.__identifier__
        query_cat['path'] = '/'.join(context.getPhysicalPath())
        cat = getToolByName(context, 'portal_catalog')
        res = cat(**query_cat)
        buyable_uids = [IUUID(it.getObject()) for it in res]

        query_b = query_b & Any('buyable_uid', buyable_uids)

        all_orders = {}
        for booking in bookings_soup.query(query_b):
            booking_attrs = []
            # booking export attrs
            for attr_name in BOOKING_EXPORT_ATTRS:
                val = self.export_val(booking, attr_name)
                booking_attrs.append(val)
            # computed booking export attrs
            for attr_name in COMPUTED_BOOKING_EXPORT_ATTRS:
                cb = COMPUTED_BOOKING_EXPORT_ATTRS[attr_name]
                val = cb(context, booking)
                val = cleanup_for_csv(val)
                booking_attrs.append(val)

            # create order_attrs, if it doesn't exist
            order_uid = booking.attrs.get('order_uid')
            if order_uid not in all_orders:
                order = get_order(context, order_uid)
                order_data = OrderData(context,
                                       order=order,
                                       vendor_uids=vendor_uids)
                order_attrs = []
                # order export attrs
                for attr_name in ORDER_EXPORT_ATTRS:
                    val = self.export_val(order, attr_name)
                    order_attrs.append(val)
                # computed order export attrs
                for attr_name in COMPUTED_ORDER_EXPORT_ATTRS:
                    cb = COMPUTED_ORDER_EXPORT_ATTRS[attr_name]
                    val = cb(self.context, order_data)
                    val = cleanup_for_csv(val)
                    order_attrs.append(val)
                all_orders[order_uid] = order_attrs

            ex.writerow(all_orders[order_uid] + booking_attrs)

            # TODO: also set for contextual exports? i'd say no.
            # booking.attrs['exported'] = True
            # bookings_soup.reindex(booking)

        ret = sio.getvalue()
        sio.close()
        return ret
Example #18
0
 def _do_transition_for_order(self, uid, transition, vendor_uids):
     order = get_order(self.context, uid)
     transitions = OrderTransitions(self.context, vendor_uids=vendor_uids)
     order = transitions.do_transition(uid, transition)
     return order
Example #19
0
def save_contact(event):
    """``bda.plone.checkout.interfaces.ICheckoutDone`` subscriber for storing
    order contact to soup.
    """
    order = get_order(event.context, event.uid)
    lookup_contact(event.context, extract_contact(order))
Example #20
0
 def _do_transition_for_order(self, uid, transition, vendor_uids):
     order = get_order(self.context, uid)
     transitions = OrderTransitions(self.context, vendor_uids=vendor_uids)
     order = transitions.do_transition(uid, transition)
     return order