Commit a107bb2e by Zia Fazal

Fixed management command to handle a scenario when dns is changed

parent 782f2f29
...@@ -59,26 +59,33 @@ class Command(BaseCommand): ...@@ -59,26 +59,33 @@ class Command(BaseCommand):
""" """
Create Sites, SiteThemes, SiteConfigurations, and Courses (if requested) Create Sites, SiteThemes, SiteConfigurations, and Courses (if requested)
""" """
site, _ = Site.objects.get_or_create( logger.info('Creating or updating %s Partner', partner_code)
domain=site_domain, partner, _ = Partner.objects.get_or_create(
defaults={"name": theme_dir_name} short_code=partner_code,
defaults={
"name": partner_code
}
) )
logger.info('Finding if site already exists for %s partner', partner_code)
try:
site_config = SiteConfiguration.objects.get(partner=partner)
site_id = site_config.site.id
logger.info('Site already exists for %s partner with site id %s', partner_code, site_id)
except SiteConfiguration.DoesNotExist:
site_id = None
logger.info('Creating or updating site %s ', site_domain)
site = Site(id=site_id, domain=site_domain, name=theme_dir_name)
site.save()
logger.info('Creating %s SiteTheme', site_domain) logger.info('Creating %s SiteTheme', site_domain)
SiteTheme.objects.get_or_create( SiteTheme.objects.get_or_create(
site=site, site=site,
theme_dir_name=theme_dir_name theme_dir_name=theme_dir_name
) )
logger.info('Creating %s Partner', site_domain) logger.info('Creating or updating %s SiteConfiguration', site_domain)
partner, _ = Partner.objects.get_or_create(
short_code=partner_code,
defaults={
"name": partner_code
}
)
logger.info('Creating %s SiteConfiguration', site_domain)
SiteConfiguration.objects.get_or_create( SiteConfiguration.objects.get_or_create(
site=site, site=site,
partner=partner, partner=partner,
......
...@@ -160,3 +160,12 @@ class TestCreateSitesAndPartners(TestCase): ...@@ -160,3 +160,12 @@ class TestCreateSitesAndPartners(TestCase):
) )
# if we run command with same dns then it will not duplicates the sites and partners. # if we run command with same dns then it will not duplicates the sites and partners.
self._assert_sites_data_is_valid() self._assert_sites_data_is_valid()
self.dns_name = "new-dns"
call_command(
"create_sites_and_partners",
"--dns-name", self.dns_name,
"--theme-path", self.theme_path
)
# if we run command with same partner but different dns then it should update sites.
self._assert_sites_data_is_valid()
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