Commit 61fbbff5 authored by Florian Fuchs's avatar Florian Fuchs

Added benste's fix for lp:802540 with some minor changes:

Domains can now be retrieved not only by their mail_host property but also
their web host (base_uri)
parents d6f18ff8 0a1490c2
......@@ -179,10 +179,19 @@ class Client:
response, content = self._connection.call('domains', data)
return _Domain(self._connection, response['location'])
def get_domain(self, email_host):
response, content = self._connection.call(
'domains/{0}'.format(email_host))
return _Domain(self._connection, content['self_link'])
def get_domain(self, email_host=None, web_host=None):
"""Get domain by its email_host or its web_host."""
if email_host is not None:
response, content = self._connection.call(
'domains/{0}'.format(email_host))
return _Domain(self._connection, content['self_link'])
if web_host is not None:
for domain in self.domains:
# note: `base_url` property will be renamed to `web_host`
# in Mailman3Alpha8
if domain.base_url == web_host:
return domain
return self.get_domain("no-domain")
def get_list(self, fqdn_listname):
response, content = self._connection.call(
......@@ -209,6 +218,8 @@ class _Domain:
response, content = self._connection.call(self._url)
self._info = content
# note: `base_url` property will be renamed to `web_host`
# in Mailman3Alpha8
@property
def base_url(self):
self._get_info()
......
......@@ -50,13 +50,21 @@ is returned.
>>> print example_dot_com.url_host
example.com
You can also get an existing domain independently.
You can also get an existing domain independently using its mail host.
>>> example = client.get_domain('example.com')
>>> example
<Domain "example.com">
>>> print example_dot_com.base_url
http://example.com
Additionally you can get an existing domain using its web host.
>>> example = client.get_domain(None,'example.com')
>>> example
<Domain "example.com">
>>> print example_dot_com.base_url
http://example.com
But you cannot retrieve a non-existent domain.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment