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)
|
||||
* 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)
|
||||
* forms: list of w.c.s. forms (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.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.formdef import FormDef
|
||||
from wcs.mail_templates import MailTemplate
|
||||
|
@ -41,12 +48,23 @@ class Cmd(Command):
|
|||
self.import_formdefs()
|
||||
|
||||
def import_categories(self):
|
||||
if not os.path.exists(os.path.join(self.directory, 'category')):
|
||||
return
|
||||
for filename in os.listdir(os.path.join(self.directory, 'category')):
|
||||
category = Category.import_from_xml(open(os.path.join(self.directory, 'category', filename)))
|
||||
for category_klass in (
|
||||
Category,
|
||||
CardDefCategory,
|
||||
WorkflowCategory,
|
||||
BlockCategory,
|
||||
MailTemplateCategory,
|
||||
DataSourceCategory,
|
||||
):
|
||||
dirname = category_klass.xml_root_node
|
||||
if not os.path.exists(os.path.join(self.directory, dirname)):
|
||||
continue
|
||||
for filename in os.listdir(os.path.join(self.directory, dirname)):
|
||||
category = category_klass.import_from_xml(
|
||||
open(os.path.join(self.directory, dirname, filename))
|
||||
)
|
||||
try:
|
||||
existing_category = Category.get_by_urlname(category.url_name)
|
||||
existing_category = category_klass.get_by_urlname(category.url_name)
|
||||
except KeyError:
|
||||
category.store()
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue