def shorten_invite_url(invite, settings=django_settings):
    bitly_api = Bitly(login=settings.BITLY_LOGIN, apiKey=settings.BITLY_API_KEY)
    url = invite.get_absolute_url()
    results = bitly_api.shorten(longUrl=url)
    shortened_url = url 
    if results['statusCode'] != 'ERROR':
        shortened_url = results.get('results', {}).get(url, {}).get('shortUrl', None)
    return shortened_url
 def fulfill(self, alternate):
     bitly_api = BitlyAPI(login=settings.BITLY_LOGIN, apiKey=settings.BITLY_API_KEY)
     url = alternate.original_url.url
     results = bitly_api.shorten(longUrl=url)
     shortened_url = None 
     if results['statusCode'] != 'ERROR':
         shortened_url = results.get('results', {}).get(url, {}).get('shortUrl', None)
     alternate.url = shortened_url
     alternate.save()
     return alternate