70 lines
2.9 KiB
Python
70 lines
2.9 KiB
Python
from django.core.management.base import BaseCommand
|
|
from django.db import connections
|
|
from establishment.management.commands.add_position import namedtuplefetchall
|
|
from main.models import SiteSettings
|
|
from location.models import Country
|
|
from tqdm import tqdm
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = '''Add add site settings from old db to new db.
|
|
Run after country migrate!!!'''
|
|
|
|
def site_sql(self):
|
|
with connections['legacy'].cursor() as cursor:
|
|
cursor.execute('''
|
|
select
|
|
id,
|
|
country_code_2,
|
|
pinterest_page_url,
|
|
twitter_page_url,
|
|
facebook_page_url,
|
|
contact_email,
|
|
config,
|
|
released,
|
|
instagram_page_url,
|
|
ad_config
|
|
from sites as s
|
|
''')
|
|
return namedtuplefetchall(cursor)
|
|
|
|
def add_site_settings(self):
|
|
objects=[]
|
|
for s in tqdm(self.site_sql(), desc='Add site settings'):
|
|
country = Country.objects.filter(code=s.code)
|
|
sites = SiteSettings.objects.filter(country=country)
|
|
if not sites.exists():
|
|
objects.append(
|
|
SiteSettings(
|
|
country=country,
|
|
pinterest_page_url=s.pinterest_page_url,
|
|
twitter_page_url=s.twitter_page_url,
|
|
facebook_page_url=s.facebook_page_url,
|
|
instagram_page_url=s.instagram_page_url,
|
|
contact_email=s.contact_email,
|
|
config=s.config,
|
|
ad_config=s.ad_config
|
|
)
|
|
)
|
|
SiteSettings.objects.bulk_create(objects)
|
|
self.stdout.write(self.style.WARNING(f'Add or get tag category objects.'))
|
|
|
|
# def add_category_tag(self):
|
|
# objects = []
|
|
# for c in tqdm(self.category_sql(), desc='Add category tags'):
|
|
# categories = TagCategory.objects.filter(index_name=c.category)
|
|
# if not categories.exists():
|
|
# objects.append(
|
|
# TagCategory(label={"en-GB": c.category},
|
|
# value_type=c.value_type,
|
|
# index_name=c.category,
|
|
# public=True
|
|
# )
|
|
# )
|
|
# else:
|
|
# categories.update(public=True)
|
|
# TagCategory.objects.bulk_create(objects)
|
|
# self.stdout.write(self.style.WARNING(f'Add or get tag category objects.'))
|
|
|
|
def handle(self, *args, **kwargs):
|
|
pass |