def contact_form_listener(sender, object=None, formdata=None, form=None, **kwargs): if 'newsletter' not in formdata: email = formdata.get('email', None) if Subscription.email_is_subscribed(email): subscribed = True else: subscribed = False else: subscribed = formdata['newsletter'] log.debug('Updating newletter subscription for %s to %s', object, subscribed) update_subscription(object, subscribed)
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() log.debug("Subscription now: %s" % sub) if subscribe: result = _("Subscribed: %(email)s") else: 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() log.debug("Subscription now: %s" % sub) if subscribe: result = _("Subscribed: %(email)s") else: result = _("Unsubscribed: %(email)s") return result % { 'email' : email }
def is_subscribed(contact): return Subscription.email_is_subscribed(contact.email)