Retrieve websites associated to a domain
This commit is contained in:
parent
6980522d81
commit
81fa9b57fd
|
@ -6,7 +6,7 @@ from django.http import Http404
|
||||||
from django.urls.exceptions import NoReverseMatch
|
from django.urls.exceptions import NoReverseMatch
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from .models import Domain, DatabaseService, MailService, SaasService, UserAccount
|
from .models import Domain, DatabaseService, MailService, SaasService, UserAccount, WebSite
|
||||||
|
|
||||||
|
|
||||||
DOMAINS_PATH = 'domains/'
|
DOMAINS_PATH = 'domains/'
|
||||||
|
@ -25,6 +25,7 @@ API_PATHS = {
|
||||||
'mailbox-list': 'mailboxes/',
|
'mailbox-list': 'mailboxes/',
|
||||||
'mailinglist-list': 'lists/',
|
'mailinglist-list': 'lists/',
|
||||||
'saas-list': 'saas/',
|
'saas-list': 'saas/',
|
||||||
|
'website-list': 'websites/',
|
||||||
|
|
||||||
# other
|
# other
|
||||||
'bill-list': 'bills/',
|
'bill-list': 'bills/',
|
||||||
|
@ -118,6 +119,8 @@ class Orchestra(object):
|
||||||
|
|
||||||
def retrieve_domain_list(self):
|
def retrieve_domain_list(self):
|
||||||
output = self.retrieve_service_list(Domain.api_name)
|
output = self.retrieve_service_list(Domain.api_name)
|
||||||
|
websites = self.retrieve_website_list()
|
||||||
|
|
||||||
domains = []
|
domains = []
|
||||||
for domain_json in output:
|
for domain_json in output:
|
||||||
# filter querystring
|
# filter querystring
|
||||||
|
@ -126,6 +129,10 @@ class Orchestra(object):
|
||||||
# retrieve services associated to a domain
|
# retrieve services associated to a domain
|
||||||
domain_json['mails'] = self.retrieve_service_list(
|
domain_json['mails'] = self.retrieve_service_list(
|
||||||
MailService.api_name, querystring)
|
MailService.api_name, querystring)
|
||||||
|
|
||||||
|
# retrieve websites (as they cannot be filtered by domain on the API we should do it here)
|
||||||
|
domain_json['websites'] = self.filter_websites_by_domain(websites, domain_json['id'])
|
||||||
|
|
||||||
# TODO(@slamora): databases and sass are not related to a domain, so cannot be filtered
|
# TODO(@slamora): databases and sass are not related to a domain, so cannot be filtered
|
||||||
# domain_json['databases'] = self.retrieve_service_list(DatabaseService.api_name, querystring)
|
# domain_json['databases'] = self.retrieve_service_list(DatabaseService.api_name, querystring)
|
||||||
# domain_json['saas'] = self.retrieve_service_list(SaasService.api_name, querystring)
|
# domain_json['saas'] = self.retrieve_service_list(SaasService.api_name, querystring)
|
||||||
|
@ -143,6 +150,19 @@ class Orchestra(object):
|
||||||
|
|
||||||
return domains
|
return domains
|
||||||
|
|
||||||
|
def retrieve_website_list(self):
|
||||||
|
output = self.retrieve_service_list(WebSite.api_name)
|
||||||
|
return [WebSite.new_from_json(website_data) for website_data in output]
|
||||||
|
|
||||||
|
def filter_websites_by_domain(self, websites, domain_id):
|
||||||
|
matching = []
|
||||||
|
for website in websites:
|
||||||
|
web_domains = [web_domain.id for web_domain in website.domains]
|
||||||
|
if domain_id in web_domains:
|
||||||
|
matching.append(website)
|
||||||
|
|
||||||
|
return matching
|
||||||
|
|
||||||
def verify_credentials(self):
|
def verify_credentials(self):
|
||||||
"""
|
"""
|
||||||
Returns:
|
Returns:
|
||||||
|
|
|
@ -162,6 +162,7 @@ class Domain(OrchestraModel):
|
||||||
"records": [],
|
"records": [],
|
||||||
"mails": [],
|
"mails": [],
|
||||||
"usage": {},
|
"usage": {},
|
||||||
|
"websites": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in a new issue