def handle(self, *args, **options): try: sheet = Spreadsheet.objects.get(name=options["sheet"]) except Spreadsheet.DoesNotExist: self.stderr.write( f"Sheet {options['sheet']} does not exist in the torquedata database." ) return json_file = options["json_file"] template_file = options["template_file"] template_type = options["template_type"] if not json_file.exists(): self.stderr.write(f'Path "{json_file}" does not exist.') if not json_file.is_file(): self.stderr.write(f'Path "{json_file}" is not a file.') if not template_file.exists(): self.stderr.write(f'Path "{template_file}" does not exist.') if not template_file.is_file(): self.stderr.write(f'Path "{template_file}" is not a file.') template = Template( sheet=sheet, type=template_type, template_file=File(open(template_file, "r")), name=options["name"], ) template.save() toc = TableOfContents(sheet=sheet, name=options["name"], json_file=json_file, template=template) toc.save()
def theme_install_to_blog(installed_theme, blog): json_obj = json.loads(installed_theme.json) templates = json_obj["data"] kvs = json_obj["kv"] for t in templates: template = templates[t]["template"] table_obj = Template() for name in table_obj._meta.fields: if name not in ("id"): setattr(table_obj, name, template[name]) table_obj.theme = installed_theme table_obj.blog = blog table_obj.save() mappings = templates[t]["mapping"] for mapping in mappings: mapping_obj = TemplateMapping() for name in mapping_obj._meta.fields: if name not in ("id"): setattr(mapping_obj, name, mappings[mapping][name]) mapping_obj.template = table_obj mapping_obj.save() kv_index = {} kx = System() for kv in kvs: kv_current = kvs[kv] new_kv = kx.add_kv(**kv_current) kv_index[kv_current['id']] = new_kv.id for kv in kv_index: kv_current = kv new_kv_value = kv_index[kv] kv_to_change = KeyValue.get(KeyValue.id == new_kv_value) parent = kv_to_change.__dict__['_data']['parent'] if parent is None: continue kv_to_change.parent = kv_index[parent] kv_to_change.save() from core import cms # TODO: use purge_blog instead # for n in blog.pages(): cms.build_pages_fileinfos(blog.pages()) # for n in blog.index_templates: cms.build_indexes_fileinfos(blog.index_templates)