1

I am usng exchangelib in conjunction with Django 1.11 to manage Calendar items. Can anyone provide any guidance on the best way to pass emails to the required_attendees of CalendarItem in my views.py file?

required_attendees = [Attendee(mailbox=Mailbox(email_address='user1@example.com'),
response_type='Accept')]

The number of emails could be from zero to many, eg:

 required_attendees = [Attendee(mailbox=Mailbox(email_address='user1@example.com'),
response_type='Accept'),
Attendee(mailbox=Mailbox(email_address='user2@example.com'),
response_type='Accept')]

At the moment I am repeating code using IF statements based on the length of a list containing all the email addresses. It works but obviously is not the correct way to do it and is very inelegant code.

Any guidance will be greatly appreciated! Cheers

cr1
  • 199
  • 2
  • 16

1 Answers1

0

In Python, you would either create an intermediate list which you append to, or use a list comprehension. required_attendees also takes plain email addresses as strings. So you could do something like:

required_attendees = list(your_collection_of_email_addresses)

# or as a list comprehension:

required_attendees = [
    Attendee(mailbox=Mailbox(email_address=e), response_type='Accept')
    for e in your_list_of_email_addresses
]
Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63