|synopsis:||export the email addresses for your users in one of many formats|
Most Django sites include a registered user base. There are times when you would like to import these e-mail addresses into other systems (generic mail program, Gmail, Google Docs invites, give edit permissions, LinkedIn Group pre-approved listing, etc.). The export_emails command extension gives you this ability. Exported users can be filtered by Group name association.
# Export all the addresses in the '"First Last" <email@example.com>;' format. $ ./manage.py export_emails > addresses.txt
# Export users from the group 'Attendees' in the linked in pre-approve Group csv format. $ ./manage.py export_emails -g Attendees -f linkedin pycon08.csv
# Create a csv file importable by Gmail or Google Docs $ ./manage.py export_emails --format=google google.csv
This is the default basic text format. Each entry is on its own line in the format:
"First Last" <firstname.lastname@example.org>;
This can be used with all known mail programs (that I know about anyway).
A CSV (comma separated value) format which Google applications can import. This can be used to import directly into Gmail, a Gmail mailing group, Google Docs invite (to read), Google Docs grant edit permissions, Google Calendar invites, etc.
Only two columns are supplied. One for the person’s name and one for the email address. This is also nice for importing into spreadsheets.
A CSV (comma separated value) format which Outlook can parse and import. Supplies all the columns that Outlook ‘requires’, but only the name and email address are supplied.
A vCard format which Apple Address Book can parse and import.
There are a couple of settings keys which can be configured in settings.py. Below the default values are shown:
EXPORT_EMAILS_ORDER_BY = ['last_name', 'first_name', 'username', 'email'] EXPORT_EMAILS_FIELDS = ['last_name', 'first_name', 'username', 'email'] EXPORT_EMAILS_FULL_NAME_FUNC = None
Specifies the order_by(…) clause on the query being done into the database to retrieve the users. This determines the order of the output.
Specifies which fields will be selected from the database. This is most useful in combination with EXPORT_EMAILS_FULL_NAME_FUNC to select other fields you might want to use inside the custom function or when using a custom User model which does not have fields like ‘first_name’ and ‘last_name’.
A function to use to create a full name based on the database fields selected by EXPORT_EMAILS_FULL_NAME_FUNC. The default implementation can be looked up in https://github.com/django-extensions/django-extensions/blob/master/django_extensions/management/commands/export_emails.py#L23