本文整理汇总了Python中c2cgeoportal_commons.models.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2cgeoportal_commons.models.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: teardown_method
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def teardown_method(self, _):
testing.tearDown()
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.static import Shorturl
import transaction
DBSession.query(Shorturl).delete()
transaction.commit()
示例2: get_ogcserver_byname
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def get_ogcserver_byname(self, name):
try:
result = DBSession.query(OGCServer).filter(OGCServer.name == name).one()
DBSession.expunge(result)
return result
except NoResultFound: # pragma nocover
log.error("OGSServer '{}' does not exists (existing: {}).".format(
name, ",".join([t[0] for t in DBSession.query(OGCServer.name).all()])))
raise
示例3: teardown_method
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def teardown_method(self, _):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.static import User
DBSession.query(User).filter(User.username == "__test_user1").delete()
transaction.commit()
pyramid.security.remember = None
pyramid.security.remember = self.old_remember
示例4: teardown_method
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def teardown_method(self, _):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import Role, LayerWMS, RestrictionArea, \
Interface, OGCServer
from c2cgeoportal_commons.models.static import User
DBSession.query(User).filter(User.username == "__test_user1").delete()
ra = DBSession.query(RestrictionArea).filter(
RestrictionArea.name == "__test_ra1"
).one()
ra.roles = []
ra.layers = []
DBSession.delete(ra)
r = DBSession.query(Role).filter(Role.name == "__test_role1").one()
DBSession.delete(r)
for layer in DBSession.query(LayerWMS).filter(
LayerWMS.name.in_(["testpoint_group_name", "testpoint_protected_2_name"])
).all():
DBSession.delete(layer)
DBSession.query(Interface).filter(
Interface.name == "main"
).delete()
DBSession.query(OGCServer).delete()
transaction.commit()
示例5: teardown_method
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def teardown_method(self, _):
import transaction
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import Role
from c2cgeoportal_commons.models.static import User
transaction.commit()
DBSession.query(User).filter_by(username="__test_user").delete()
DBSession.query(Role).filter_by(name="__test_role").delete()
transaction.commit()
示例6: teardown_method
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def teardown_method(self, _):
testing.tearDown()
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import TreeItem, Interface, OGCServer
for item in DBSession.query(TreeItem).all():
DBSession.delete(item)
DBSession.query(OGCServer).delete()
DBSession.query(Interface).filter(
Interface.name == "main"
).delete()
transaction.commit()
示例7: teardown_method
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def teardown_method(self, _):
testing.tearDown()
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import TreeItem, Interface, Metadata
for t in DBSession.query(Metadata).all():
DBSession.delete(t)
for item in DBSession.query(TreeItem).all():
DBSession.delete(item)
DBSession.query(Interface).filter(
Interface.name == "desktop"
).delete()
transaction.commit()
示例8: _import_layer_wmts
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def _import_layer_wmts(self, layer, messages):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import OGCServer
layers = [d.value for d in layer.metadatas if d.name == "queryLayers"]
if len(layers) == 0:
layers = [d.value for d in layer.metadatas if d.name == "wmsLayer"]
server = [d.value for d in layer.metadatas if d.name == "ogcServer"]
if len(server) >= 1 and len(layers) >= 1:
for wms_layer in layers:
try:
db_server = DBSession.query(OGCServer).filter(OGCServer.name == server[0]).one()
self._import_layer_attributes(
db_server.url_wfs or db_server.url, wms_layer,
layer.item_type, layer.name, messages
)
except NoResultFound:
print(colorize(
"ERROR! the OGC server '{}' from the WMTS layer '{}' does not exist.".format(
server[0], layer.name
),
RED
))
if os.environ.get("IGNORE_I18N_ERRORS", "FALSE") != "TRUE":
raise
示例9: test_group_update
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def test_group_update(self):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import LayerGroup
layer_group_3 = DBSession.query(LayerGroup).filter(LayerGroup.name == "__test_layer_group_3").one()
layer_group_3.children = layer_group_3.children[:-1]
transaction.commit()
entry = self._create_entry_obj(params={
"version": "2",
"group": "__test_layer_group_3",
"catalogue": "true",
})
themes = entry.themes()
self.assertEqual(self._get_filtered_errors(themes), set())
self.assertEqual(
self._only_name(themes["group"]),
{
"name": "__test_layer_group_3",
# order is important
"children": [{
"name": "__test_layer_wmts"
}, {
"name": "__test_layer_internal_wms"
}]
}
)
示例10: test_private
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def test_private(self):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.static import User
entry = self._create_entry_obj(params={
"version": "2"
}, user=DBSession.query(User).filter_by(username=u"__test_user").one())
themes = entry.themes()
self.assertEquals(themes["errors"], [])
self.assertEquals(
[self._only_name(t) for t in themes["themes"]],
[{
"name": u"__test_theme",
"children": [{
"name": u"__test_layer_group",
"children": [{
"name": u"__test_layer_wms"
}, {
"name": u"__test_layer_wms_private"
}, {
"name": u"__test_layer_wmts"
}, {
"name": u"__test_layer_wmts_private"
}]
}]
}]
)
示例11: get_private_layers
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def get_private_layers(ogc_server_ids):
q = DBSession.query(LayerWMS) \
.filter(LayerWMS.public.is_(False)) \
.join(LayerWMS.ogc_server) \
.filter(OGCServer.id.in_(ogc_server_ids))
results = q.all()
DBSession.expunge_all()
return {r.id: r for r in results}
示例12: main
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def main():
parser = argparse.ArgumentParser(
description="Create and populate the database tables."
)
parser.add_argument(
'-i', '--iniconfig',
default='geoportal/production.ini',
help='project .ini config file'
)
parser.add_argument(
'-n', '--app-name',
default="app",
help='The application name (optional, default is "app")'
)
options = parser.parse_args()
# read the configuration
fileConfig(options.iniconfig, defaults=os.environ)
get_app(options.iniconfig, options.app_name, options=os.environ)
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import Interface, OGCServer, Theme, LayerGroup, LayerWMS
session = DBSession()
interfaces = session.query(Interface).all()
ogc_server = session.query(OGCServer).filter(OGCServer.name == "source for image/png").one()
layer_borders = LayerWMS("Borders", "borders")
layer_borders.interfaces = interfaces
layer_borders.ogc_server = ogc_server
layer_density = LayerWMS("Density", "density")
layer_density.interfaces = interfaces
layer_density.ogc_server = ogc_server
group = LayerGroup("Demo")
group.children = [layer_borders, layer_density]
theme = Theme("Demo")
theme.children = [group]
theme.interfaces = interfaces
session.add(theme)
transaction.commit()
示例13: _create_getcap_request
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def _create_getcap_request(username=None):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.static import User
request = create_dummy_request()
request.user = None if username is None else \
DBSession.query(User).filter_by(username=username).one()
return request
示例14: default_user_validator
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def default_user_validator(request, username, password):
"""
Validate the username/password. This is c2cgeoportal's
default user validator.
Return none if we are anonymous, the string to remember otherwise.
"""
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.static import User
user = DBSession.query(User).filter_by(username=username).first()
return username if user and user.validate_password(password) else None
示例15: _get_layers_query
# 需要导入模块: from c2cgeoportal_commons.models import DBSession [as 别名]
# 或者: from c2cgeoportal_commons.models.DBSession import query [as 别名]
def _get_layers_query(role_id, what):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import Layer, RestrictionArea, Role
q = DBSession.query(what)
q = q.join(Layer.restrictionareas)
q = q.join(RestrictionArea.roles)
q = q.filter(Role.id == role_id)
return q