Esempio n. 1
0
def notify_order_state_update(sender, **kwargs):

    order = sender
    transition = kwargs['transition']

    extra_content = {
        'gas' : order.gas,
        'order' : order,
        'action' : transition.name,
        'state' : transition.destination.name,
    }

    #--- Transition name ---#

    recipients = []
    if transition.destination.name.lower() in ["open", "closed"]:
        recipients = [order.referrer_person.user]
    elif transition.destination.name.lower() in ["sent", "paid"]:
        recipients = list(order.supplier.referrers) + [order.referrer_person.user]
        recipients = unordered_uniq(recipients)

    log.debug("Transition to: %s" % transition.destination.name)
    log.debug("Recipients: %s" % zip(recipients, map(lambda x: x.email, recipients)))
    try:
        #FIXME
        notification.send(recipients, "order_state_update", 
            extra_content, on_site=True
        )
    except Exception as e:
        log.error("Send msg notify_order_state_update: %s (%s)" % (e.message, type(e)))
        pass
Esempio n. 2
0
    def updaters(self):
        """Returns User QuerySet of who has updated the resource."""
       
        self_updaters = unordered_uniq(
                self._default_history.filter(id=self.pk, history_type="~").values_list('history_user')
            )

        return User.objects.filter(pk__in=map(lambda x: x[0].pk, self_updaters))
Esempio n. 3
0
    def preferred_email_address(self):
        """The email address, where we should write if we would know more info on the resource.

        It is not necessarily bound to a person. 

        NOTE that it could be even a list of addresses following syntax in RFC 5322 and RFC 5321,
        or simply http://en.wikipedia.org/wiki/Email_address#Syntax :)

        Usually you SHOULD NOT NEED TO OVERRIDE IT in subclasses
        """
        if settings.EMAIL_DEBUG:
            return settings.EMAIL_DEBUG_ADDR
        else:
            return ", ".join(unordered_uniq(map(lambda x: x[0], self.preferred_email_contacts.values_list('value'))))
Esempio n. 4
0
def notify_order_state_update(sender, **kwargs):

    order = sender
    transition = kwargs['transition']

    extra_content = {
        'gas': order.gas,
        'order': order,
        'action': transition.name,
        'state': transition.destination.name,
        'site': Siteattr.get_site(),
        'protocol': 'http',
    }

    #--- Transition name ---#

    recipients = []

    try:
        if transition.destination.name.lower() in ["open", "closed"]:
            recipients = [order.referrer_person.user]
        elif transition.destination.name.lower() in ["sent", "paid"]:
            recipients = list(
                order.supplier.referrers) + [order.referrer_person.user]
            recipients = unordered_uniq(recipients)
    except AttributeError as e:
        #TODO Matteo: complete exception handling here
        raise exceptions.ReferrerIsNoneException()

    log.debug("Transition to: %s" % transition.destination.name)
    log.debug("Recipients: %s" %
              zip(recipients, map(lambda x: x.email, recipients)))
    try:
        notification.send(recipients, "order_state_update", extra_content)
    except Exception as e:
        log.error("Send msg notify_order_state_update: %s (%s)" %
                  (e.message, type(e)))
        pass
Esempio n. 5
0
def notify_order_state_update(sender, **kwargs):

    order = sender
    transition = kwargs['transition']

    extra_content = {
        'gas' : order.gas,
        'order' : order,
        'action' : transition.name,
        'state' : transition.destination.name,
        'site' : Siteattr.get_site(),
        'protocol' : 'http',
    }

    #--- Transition name ---#

    recipients = []

    try:
        if transition.destination.name.lower() in ["open", "closed"]:
            recipients = [order.referrer_person.user]
        elif transition.destination.name.lower() in ["sent", "paid"]:
            recipients = list(order.supplier.referrers) + [order.referrer_person.user]
            recipients = unordered_uniq(recipients)
    except AttributeError as e:
        #TODO Matteo: complete exception handling here
        raise exceptions.ReferrerIsNoneException()

    log.debug("Transition to: %s" % transition.destination.name)
    log.debug("Recipients: %s" % zip(recipients, map(lambda x: x.email, recipients)))
    try:
        notification.send(recipients, "order_state_update", 
            extra_content
        )
    except Exception as e:
        log.error("Send msg notify_order_state_update: %s (%s)" % (e.message, type(e)))
        pass
Esempio n. 6
0
 def certifications_list(self):
     #Value symbol, name and description
     #TODO: add PRIVATE
     return ", ".join(unordered_uniq(map(lambda x: x[0], self.certifications.values_list('description'))))
Esempio n. 7
0
 def preferred_fax_address(self):
     return ", ".join(unordered_uniq(map(lambda x: x[0], self.preferred_fax_contacts.values_list('value'))))
Esempio n. 8
0
 def phone_address(self):
     return ", ".join(unordered_uniq(map(lambda x: x[0], self.contacts.filter(flavour=const.PHONE).values_list('value'))))
Esempio n. 9
0
 def certifications_list(self):
     #Value symbol, name and description
     #TODO: add PRIVATE
     return ", ".join(unordered_uniq(map(lambda x: x[0], self.certifications.values_list('description'))))