def create_poll(self, initiator, title, initiator_email=None, description=None, location=None, type='TEXT', hidden=False, options=[], ): """Creates a new poll. :param initiator: Name of the initiator. :param initiator_email: E-Mail of the initiator. Doodle uses this to attach a poll to an account. :param description: The description shown. :param location: Optional location. Must be given if description isn't. :param type: One of ``'TEXT'`` or ``'DATE'``. :param hidden: Hide participant names. :param options: An array of strings or ``Option``s. When ``'DATE'`` is chosen for ``type``, must be ``Option`` with date or date_time set. """ assert type in ('TEXT', 'DATE') assert location or description E = ElementMaker(namespace=self.doodle_ns) poll = etree.Element('poll', nsmap={None: self.doodle_ns}) poll.append(E.type(type)) poll.append(E.hidden('true' if hidden else 'false')) poll.append(E.levels('2')) poll.append(E.title(title)) if description: poll.append(E.description(description)) if location: poll.append(E.location(location)) initiator_elem = E.initiator(E.name(initiator)) if initiator_email: initiator_elem.append(E.eMailAddress(initiator_email)) poll.append(initiator_elem) opts = E.options() for opt in options: if isinstance(opt, basestring): opt = Option(opt) opts.append(opt.to_node()) poll.append(opts) r = self.session.post( self.base_url + '/polls', data=etree.tostring(poll), headers={'Content-type': 'application/xml'}, ) r.raise_for_status() return r.headers['Content-Location'], r.headers['X-DoodleKey']