예제 #1
0
def actionkit_push(user, profile):
    location = profile.location or null_location()
    # EGJ TODO: what if profile.location is None?
    # i think the localpower system allows that
    # currently just setting empty strings (per line above)
    
    actionkit = get_client()
    ak_user = actionkit.User.save_or_create(dict(
            email=user.email,
            first_name=user.first_name,
            last_name=user.last_name,
            zip=location.zipcode,
            region=location.county,
            state=location.st,
            state_name=location.state,
            city=location.name
            ))

    try:
        page_name = settings.ACTIONKIT_PAGE_NAME
    except AttributeError:
        return ak_user

    history = actionkit.User.subscription_history({'id': ak_user['id']})
    ever_been_subscribed = False
    for entry in history:
        if entry.get("page_name") == page_name:
            ever_been_subscribed = True
            break
    if not ever_been_subscribed:
        result = actionkit.act(dict(
                page=page_name,
                email=user.email))

    return ak_user
예제 #2
0
        result = actionkit.act(dict(
                page=page_name,
                email=user.email))

    return ak_user

def user_post_save(sender, instance, created, **kwargs):
    user = instance
    profile = user.get_profile()
    ak_user = actionkit_push(user, profile)
models.signals.post_save.connect(user_post_save, sender=User)

def profile_post_save(sender, instance, created, **kwargs):
    profile = instance
    user = profile.user
    ak_user = actionkit_push(user, profile)
models.signals.post_save.connect(profile_post_save, sender=Profile)

# EGJ TODO: test profile post-save signal

# Verify that the ActionKit API settings are correct 
# and successfully connect to the server
actionkit = get_client()
import xmlrpclib
try:
    actionkit.version()
except xmlrpclib.ProtocolError:
    print ("Your ActionKit API settings are incorrect; please double-check them "
           "and try again.")
    raise