def update_contact(contact, subscribe, attributes={}):
    email = contact.email
    current = Subscription.email_is_subscribed(email)
    attributesChanged = False
    sub = None
    if attributes:
        (sub, created) = Subscription.objects.get_or_create(email=email)
        if created:
            attributesChanged = True
        else:
            oldAttr = [(a.name, a.value) for a in sub.attributes.all()]
            oldAttr.sort()
        sub.update_attributes(attributes)
        newAttr = [(a.name, a.value) for a in sub.attributes.all()]
        newAttr.sort()
        if (not created):
            attributesChanged = (oldAttr != newAttr)
    if (current == subscribe):
        if subscribe:
            if attributesChanged:
                result = _('Updated subscription for %(email)s.')
            else:
                result = _('Already subscribed %(email)s.')
        else:
            result = _('Already removed %(email)s.')
    else:
        if (not sub):
            (sub, created) = Subscription.objects.get_or_create(email=email)
        sub.subscribed = subscribe
        sub.save()
        if subscribe:
            mailman_add(contact)
            result = _('Subscribed: %(email)s')
        else:
            mailman_remove(contact)
            result = _('Unsubscribed: %(email)s')
    return (result % {'email': email})
def update_contact(contact, subscribe, attributes={}):
    email = contact.email
    current = Subscription.email_is_subscribed(email)
    attributesChanged = False
    sub = None
    if attributes:
        (sub, created) = Subscription.objects.get_or_create(email=email)
        if created:
            attributesChanged = True
        else:
            oldAttr = [(a.name, a.value) for a in sub.attributes.all()]
            oldAttr.sort()
        sub.update_attributes(attributes)
        newAttr = [(a.name, a.value) for a in sub.attributes.all()]
        newAttr.sort()
        if (not created):
            attributesChanged = (oldAttr != newAttr)
    if (current == subscribe):
        if subscribe:
            if attributesChanged:
                result = _('Updated subscription for %(email)s.')
            else:
                result = _('Already subscribed %(email)s.')
        else:
            result = _('Already removed %(email)s.')
    else:
        if (not sub):
            (sub, created) = Subscription.objects.get_or_create(email=email)
        sub.subscribed = subscribe
        sub.save()
        if subscribe:
            mailman_add(contact)
            result = _('Subscribed: %(email)s')
        else:
            mailman_remove(contact)
            result = _('Unsubscribed: %(email)s')
    return (result % {'email': email})