]>
git.ipfire.org Git - ipfire.org.git/blob - src/backend/lists.py
9 class Lists(misc
.Object
):
13 Returns the base URL of a Mailman instance
15 return self
.settings
.get("mailman-url")
19 return self
.settings
.get("mailman-username")
23 return self
.settings
.get("mailman-password")
25 async def _request(self
, method
, url
, data
=None):
26 headers
, body
= {}, None
29 url
= urllib
.parse
.urljoin(self
.url
, url
)
31 # For GET requests, append query arguments
34 url
= "%s?%s" % (url
, urllib
.parse
.urlencode(data
))
36 # For POST/PUT encode all arguments as JSON
37 elif method
in ("POST", "PUT", "PATCH"):
39 "Content-Type" : "application/json",
42 body
= json
.dumps(data
)
44 # Send the request and wait for a response
45 res
= await self
.backend
.http_client
.fetch(url
, method
=method
,
46 headers
=headers
, body
=body
,
49 auth_username
=self
.username
, auth_password
=self
.password
,
52 # Decode JSON response
53 body
= json
.loads(res
.body
)
61 async def _get_lists(self
, *args
, **kwargs
):
65 response
= await self
._request
(*args
, **kwargs
)
68 for entry
in response
.get("entries", []):
69 list = List(self
.backend
, **entry
)
74 async def get_lists(self
):
76 Fetches all available lists
82 return await self
._get
_lists
("GET", "/api/3.1/lists", data
=data
)
84 async def get_subscribed_lists(self
, account
):
86 "subscriber" : account
.email
,
90 return await self
._get
_lists
("GET", "/api/3.1/members/find", data
=data
)
93 class List(misc
.Object
):
94 def init(self
, list_id
, **kwargs
):
95 self
.list_id
= list_id
97 # Store all other data
101 return "<List %s>" % self
.list_id
104 return self
.display_name
106 def __eq__(self
, other
):
107 if isinstance(other
, self
.__class
__):
108 return self
.list_id
== other
.list_id
110 return NotImplemented
112 def __lt__(self
, other
):
113 if isinstance(other
, self
.__class
__):
114 return self
.list_id
< other
.list_id
116 return NotImplemented
119 return self
.data
.get("member_count")
122 def display_name(self
):
123 return self
.data
.get("display_name")
126 def description(self
):
127 return self
.data
.get("description")
130 def archive_url(self
):
131 return "https://lists.ipfire.org/hyperkitty/list/%s/" % self
.list_id
133 async def subscribe(self
, account
):
136 async def unsubscribe(self
, account
):