本文整理汇总了Python中c2cgeoportal_commons.models.DBSession.execute方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.execute方法的具体用法?Python DBSession.execute怎么用?Python DBSession.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2cgeoportal_commons.models.DBSession
的用法示例。
在下文中一共展示了DBSession.execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import execute [as 别名]
class Import:
def __init__(self, options):
self.options = options
self.imported = set()
settings = get_config("config.yaml")
package = settings["package"]
self.fts_languages = settings["fulltextsearch"]["languages"]
self.languages = settings["available_locale_names"]
# must be done only once we have loaded the project config
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import FullTextSearch, Interface, Theme, Role
self.session = DBSession()
self.session.execute(FullTextSearch.__table__.delete().where(FullTextSearch.from_theme == True)) # noqa
self._ = {}
for lang in self.languages:
self._[lang] = translation(
"{}-client".format(package), os.path.join(package, "locale/"), [lang])
query = self.session.query(Interface)
if options.interfaces is not None:
query = query.filter(
Interface.name.in_(options.interfaces)
)
self.interfaces = query.all()
self.public_theme = {}
self.public_group = {}
for interface in self.interfaces:
self.public_theme[interface.id] = []
self.public_group[interface.id] = []
for theme in self.session.query(Theme).filter_by(public=True).all():
self._add_theme(theme)
for role in self.session.query(Role).all():
for theme in self.session.query(Theme).all():
self._add_theme(theme, role)
transaction.commit()
def _add_fts(self, item, interface, action, role):
from c2cgeoportal_commons.models.main import FullTextSearch
key = (
item.name if self.options.name else item.id,
interface.id,
role.id if role is not None else None
)
if key not in self.imported:
self.imported.add(key)
for lang in self.languages:
fts = FullTextSearch()
fts.label = self._[lang].gettext(item.name)
fts.role = role
fts.interface = interface
fts.lang = lang
fts.public = role is None
fts.ts = func.to_tsvector(self.fts_languages[lang], fts.label)
fts.actions = [{
"action": action,
"data": item.name,
}]
fts.from_theme = True
self.session.add(fts)
def _add_theme(self, theme, role=None):
fill = False
for interface in self.interfaces:
if interface in theme.interfaces:
for child in theme.children:
fill = self._add_block(child, interface, role) or fill
if fill and self.options.themes:
if role is None:
self.public_theme[interface.id].append(theme.id)
if role is None or theme.id not in self.public_theme[interface.id]:
self._add_fts(theme, interface, "add_theme", role)
def _add_block(self, group, interface, role):
return self._add_group(group, interface, self.options.blocks, role)
def _add_folder(self, group, interface, role):
return self._add_group(group, interface, self.options.folders, role)
def _add_group(self, group, interface, export, role):
from c2cgeoportal_commons.models.main import LayerGroup
fill = False
for child in group.children:
if isinstance(child, LayerGroup):
fill = self._add_folder(child, interface, role) or fill
else:
fill = self._add_layer(child, interface, role) or fill
#.........这里部分代码省略.........