Create list

This commit is contained in:
Yohann D'ANELLO 2020-10-08 21:48:11 +02:00
parent 3f46bf74d8
commit 9b804cd31a
1 changed files with 24 additions and 0 deletions

View File

@ -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?")