Skip to content

Instantly share code, notes, and snippets.

@codingisacopingstrategy
Created March 7, 2014 09:46
Show Gist options
  • Save codingisacopingstrategy/9408593 to your computer and use it in GitHub Desktop.
Save codingisacopingstrategy/9408593 to your computer and use it in GitHub Desktop.
Export django users as vcards (to run in the django shell, requires vObject library)
import vobject
from django.contrib.auth.models import User
def vcard(user):
j = vobject.vCard()
o = j.add('fn')
o.value = user.get_full_name()
o = j.add('n')
o.value = vobject.vcard.Name( family=user.last_name, given=user.first_name )
j.add('email')
j.email.value = user.email
j.email.type_param = 'INTERNET'
j.email.type_param = 'HOME'
o = j.add('note')
o.value = 'Graphisme MA ERG'
return j.serialize()
for u in User.objects.all():
if u.email and u.last_name:
print vcard(u),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment