Created
March 7, 2014 09:46
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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