From 9b804cd31af6d53cb03e1ec8556fb01409bad89b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 8 Oct 2020 21:48:11 +0200 Subject: [PATCH] Create list --- sympasoap/client.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/sympasoap/client.py b/sympasoap/client.py index e136c84..781d978 100644 --- a/sympasoap/client.py +++ b/sympasoap/client.py @@ -1,4 +1,5 @@ from zeep.client import Client as ZeepClient, Settings as ZeepSettings +from zeep.exceptions import Fault from sympasoap.lists import MailingList, MLUser @@ -62,6 +63,17 @@ SUBTOPICS = [ "society/religion", ] +TEMPLATES = [ + "confidential", + "discussion_list", + "hotline", + "html-news-letter", + "intranet_list", + "news-letter", + "private_working_group", + "public_web_forum", +] + class Client: def __init__(self, sympa_url: str): @@ -187,3 +199,15 @@ class Client: ml = MailingList(**kwargs) lists.append(ml) return lists + + def create_list(self, list_name: str, subject: str, template: str, description: str, topic: str, + use_custom_template: bool = False) -> bool: + if topic not in TOPICS and topic not in SUBTOPICS: + raise ValueError(f"Topic '{topic}' does not exist.") + if template not in TEMPLATES and not use_custom_template: + raise ValueError(f"Template '{template}' does not exist.") + try: + result = self.zeep.service.createList(list_name, subject, template, description, topic) + return result._raw_elements[0].text == "true" + except Fault: + raise Fault(f"An unknown error occured while creating the list {list_name}. Maybe the list already exists?")