本文整理汇总了Python中lmkp.models.meta.DBSession.scalar方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.scalar方法的具体用法?Python DBSession.scalar怎么用?Python DBSession.scalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lmkp.models.meta.DBSession
的用法示例。
在下文中一共展示了DBSession.scalar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_parameters
# 需要导入模块: from lmkp.models.meta import DBSession [as 别名]
# 或者: from lmkp.models.meta.DBSession import scalar [as 别名]
def _handle_parameters(self):
response = self.request.response
# Make sure the _LOCATION_ cookie is correctly set: The old version GUI
# version used to store the map center and the zoom level which is not
# understood by new GUI (which stores the map extent as 4 coordinates)
if '_LOCATION_' in self.request.cookies:
c = urllib.unquote(self.request.cookies['_LOCATION_'])
if len(c.split('|')) == 3:
response.delete_cookie('_LOCATION_')
# Check if language (_LOCALE_) is set
if self.request is not None:
if '_LOCALE_' in self.request.params:
response.set_cookie('_LOCALE_', self.request.params.get(
'_LOCALE_'), timedelta(days=90))
elif '_LOCALE_' in self.request.cookies:
pass
# Check if profile (_PROFILE_) is set
if self.request is not None:
if '_PROFILE_' in self.request.params:
# Set the profile cookie
profile_code = self.request.params.get('_PROFILE_')
response.set_cookie(
'_PROFILE_', profile_code, timedelta(days=90))
# Update _LOCATION_ from cookies to profile geometry bbox
# retrieved from database
profile_db = DBSession.query(Profile).\
filter(Profile.code == profile_code).\
first()
if profile_db is not None:
# Calculate and transform bounding box
bbox = DBSession.scalar(geofunctions.envelope(
geofunctions.transform(
profile_db.geometry, '900913')).wkt)
geojson = utils.from_wkt(bbox)
coords = geojson['coordinates'][0]
p1 = coords[0]
p2 = coords[2]
l = '%s,%s' % (','.join([str(x) for x in p1]),
','.join([str(x) for x in p2]))
response.set_cookie(
'_LOCATION_', urllib.quote(l), timedelta(days=90))
elif '_PROFILE_' in self.request.cookies:
# Profile already set, leave it
pass
else:
# If no profile is set, set the default profile
response.set_cookie('_PROFILE_', get_default_profile(
self.request), timedelta(days=90))