mcottondesign

Loving Open-Souce One Anonymous Function at a Time.

Making profile pages more sane

We encourage our merchants to include a facebook page with their profiles so that users can share that page when they check-in, check-out, unlock a deal, or redeem a deal. But some people didn't understand what that means and we had all sorts of crazy input. Instead of explaining the steps they'll need to get us the correct URL, we'll just take whatever they mashed out on their keyboard and fix it.

Django has some weird points, but it mostly has awesome ones. I needed to clean up our database and the interactive console was perfect.

python manage.py shell

and then you can something like this

# get all the businesses from the modal
b = Business.objects.all()


# loop through the all the profiles
for p in b:      
    p.facebook_link = p.facebook_link.replace('http://www.facebook.com','')
    p.facebook_link = p.facebook_link.replace('/facebook.com','/')
    p.facebook_link = p.facebook_link.replace('https://www.facebook.com','')
    p.facebook_link = p.facebook_link.replace('//','/')
    p.save()

On the signup form we do some JavaScript to parse out some of the non-sense

$('#facebook').blur(function() {
     $(this).val($(this).val().replace(/^.*\//,''))
})

$('#twitter').blur(function() {
     $(this).val($(this).val().replace(/^[@]/,''))
})