comparison libervia/server/pages.py @ 1165:6424d3684d1e

pages: locale handling: language/locale can be set using C.KEY_LANG in url query (e.g. [url]?lang=fr), it is set for the whole session.
author Goffi <goffi@goffi.org>
date Wed, 10 Apr 2019 21:06:34 +0200
parents 64952ba7affe
children 7d2e098ea3f4
comparison
equal deleted inserted replaced
1164:ef3adc3f2078 1165:6424d3684d1e
1135 request.setResponseCode(code) 1135 request.setResponseCode(code)
1136 if no_body: 1136 if no_body:
1137 request.finish() 1137 request.finish()
1138 else: 1138 else:
1139 template = u"error/" + unicode(code) + ".html" 1139 template = u"error/" + unicode(code) + ".html"
1140 template_data = request.template_data
1141 session_data = self.host.getSessionData(request, session_iface.ISATSession)
1142 if session_data.locale is not None:
1143 template_data[u'locale'] = session_data.locale
1140 if self.vhost_root.site_name: 1144 if self.vhost_root.site_name:
1141 request.template_data[u'site'] = self.vhost_root.site_name 1145 template_data[u'site'] = self.vhost_root.site_name
1142 1146
1143 rendered = self.host.renderer.render( 1147 rendered = self.host.renderer.render(
1144 template, 1148 template,
1145 error_code=code, 1149 error_code=code,
1146 **request.template_data 1150 **template_data
1147 ) 1151 )
1148 1152
1149 self.writeData(rendered, request) 1153 self.writeData(rendered, request)
1150 raise failure.Failure(exceptions.CancelError(u"error page is used")) 1154 raise failure.Failure(exceptions.CancelError(u"error page is used"))
1151 1155
1212 1216
1213 # if confirm variable is set in case of successfuly data post 1217 # if confirm variable is set in case of successfuly data post
1214 session_data = self.host.getSessionData(request, session_iface.ISATSession) 1218 session_data = self.host.getSessionData(request, session_iface.ISATSession)
1215 if session_data.popPageFlag(self, C.FLAG_CONFIRM): 1219 if session_data.popPageFlag(self, C.FLAG_CONFIRM):
1216 template_data[u"confirm"] = True 1220 template_data[u"confirm"] = True
1221 if session_data.locale is not None:
1222 template_data[u'locale'] = session_data.locale
1217 if self.vhost_root.site_name: 1223 if self.vhost_root.site_name:
1218 template_data[u'site'] = self.vhost_root.site_name 1224 template_data[u'site'] = self.vhost_root.site_name
1219 1225
1220 return self.host.renderer.render( 1226 return self.host.renderer.render(
1221 self.template, 1227 self.template,
1411 if not self.dynamic: 1417 if not self.dynamic:
1412 raise exceptions.InternalError( 1418 raise exceptions.InternalError(
1413 _(u"renderPartial must only be used with dynamic pages") 1419 _(u"renderPartial must only be used with dynamic pages")
1414 ) 1420 )
1415 session_data = self.host.getSessionData(request, session_iface.ISATSession) 1421 session_data = self.host.getSessionData(request, session_iface.ISATSession)
1422 if session_data.locale is not None:
1423 template_data[u'locale'] = session_data.locale
1416 if self.vhost_root.site_name: 1424 if self.vhost_root.site_name:
1417 template_data[u'site'] = self.vhost_root.site_name 1425 template_data[u'site'] = self.vhost_root.site_name
1418 1426
1419 return self.host.renderer.render( 1427 return self.host.renderer.render(
1420 template, 1428 template,
1462 # XXX: here is the code which need to be executed once 1470 # XXX: here is the code which need to be executed once
1463 # at the beginning of the request hanling 1471 # at the beginning of the request hanling
1464 if request.postpath and not request.postpath[-1]: 1472 if request.postpath and not request.postpath[-1]:
1465 # we don't differenciate URLs finishing with '/' or not 1473 # we don't differenciate URLs finishing with '/' or not
1466 del request.postpath[-1] 1474 del request.postpath[-1]
1475
1476 if C.KEY_LANG in request.args:
1477 try:
1478 session_data.locale = request.args.pop(C.KEY_LANG)[0]
1479 except IndexError:
1480 log.warning(u"empty lang received")
1481
1467 1482
1468 d = defer.Deferred() 1483 d = defer.Deferred()
1469 d.addCallback(self._checkAccess, request) 1484 d.addCallback(self._checkAccess, request)
1470 1485
1471 if self.redirect is not None: 1486 if self.redirect is not None: