add support for all kinds of categories (#63943)
This commit is contained in:
parent
1bcdb14e91
commit
f94ab37d1f
4
README
4
README
|
@ -13,7 +13,9 @@ Expected directory layout
|
||||||
|
|
||||||
* blocks: list of w.c.s. blocks (XML files)
|
* blocks: list of w.c.s. blocks (XML files)
|
||||||
* carddefs: list of w.c.s. cards (XML files)
|
* carddefs: list of w.c.s. cards (XML files)
|
||||||
* category: list of w.c.s. categories (XML files)
|
* category, carddef_category, workflow_category, block_category, mail_template_category,
|
||||||
|
data_source_category: list of w.c.s. categories, for their respective objects
|
||||||
|
(XML files)
|
||||||
* datasources: list of w.c.s. data sources (XML files)
|
* datasources: list of w.c.s. data sources (XML files)
|
||||||
* forms: list of w.c.s. forms (XML files)
|
* forms: list of w.c.s. forms (XML files)
|
||||||
* workflows: list of w.c.s. workflows (XML files)
|
* workflows: list of w.c.s. workflows (XML files)
|
||||||
|
|
|
@ -3,7 +3,14 @@ import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
from wcs.blocks import BlockDef
|
from wcs.blocks import BlockDef
|
||||||
from wcs.carddef import CardDef
|
from wcs.carddef import CardDef
|
||||||
from wcs.categories import Category
|
from wcs.categories import (
|
||||||
|
Category,
|
||||||
|
CardDefCategory,
|
||||||
|
WorkflowCategory,
|
||||||
|
BlockCategory,
|
||||||
|
MailTemplateCategory,
|
||||||
|
DataSourceCategory,
|
||||||
|
)
|
||||||
from wcs.data_sources import NamedDataSource
|
from wcs.data_sources import NamedDataSource
|
||||||
from wcs.formdef import FormDef
|
from wcs.formdef import FormDef
|
||||||
from wcs.mail_templates import MailTemplate
|
from wcs.mail_templates import MailTemplate
|
||||||
|
@ -41,20 +48,31 @@ class Cmd(Command):
|
||||||
self.import_formdefs()
|
self.import_formdefs()
|
||||||
|
|
||||||
def import_categories(self):
|
def import_categories(self):
|
||||||
if not os.path.exists(os.path.join(self.directory, 'category')):
|
for category_klass in (
|
||||||
return
|
Category,
|
||||||
for filename in os.listdir(os.path.join(self.directory, 'category')):
|
CardDefCategory,
|
||||||
category = Category.import_from_xml(open(os.path.join(self.directory, 'category', filename)))
|
WorkflowCategory,
|
||||||
try:
|
BlockCategory,
|
||||||
existing_category = Category.get_by_urlname(category.url_name)
|
MailTemplateCategory,
|
||||||
except KeyError:
|
DataSourceCategory,
|
||||||
category.store()
|
):
|
||||||
except Exception as e:
|
dirname = category_klass.xml_root_node
|
||||||
raise Exception('failed to load existing category %r' % filename) from e
|
if not os.path.exists(os.path.join(self.directory, dirname)):
|
||||||
else:
|
continue
|
||||||
# replace
|
for filename in os.listdir(os.path.join(self.directory, dirname)):
|
||||||
category.id = existing_category.id
|
category = category_klass.import_from_xml(
|
||||||
category.store()
|
open(os.path.join(self.directory, dirname, filename))
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
existing_category = category_klass.get_by_urlname(category.url_name)
|
||||||
|
except KeyError:
|
||||||
|
category.store()
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception('failed to load existing category %r' % filename) from e
|
||||||
|
else:
|
||||||
|
# replace
|
||||||
|
category.id = existing_category.id
|
||||||
|
category.store()
|
||||||
|
|
||||||
def import_datasources(self):
|
def import_datasources(self):
|
||||||
if not os.path.exists(os.path.join(self.directory, 'datasources')):
|
if not os.path.exists(os.path.join(self.directory, 'datasources')):
|
||||||
|
|
Loading…
Reference in New Issue