web/application.py
changeset 2650 18aec79ec3a3
parent 2613 5e19c2bb370e
child 2666 c6c832d32936
equal deleted inserted replaced
2649:5d4a943695d1 2650:18aec79ec3a3
    39         self.cleanup_anon_session_time = self.vreg.config['cleanup-anonymous-session-time'] or 120
    39         self.cleanup_anon_session_time = self.vreg.config['cleanup-anonymous-session-time'] or 120
    40         assert self.cleanup_anon_session_time > 0
    40         assert self.cleanup_anon_session_time > 0
    41         if self.session_time:
    41         if self.session_time:
    42             assert self.cleanup_session_time < self.session_time
    42             assert self.cleanup_session_time < self.session_time
    43             assert self.cleanup_anon_session_time < self.session_time
    43             assert self.cleanup_anon_session_time < self.session_time
    44         self.authmanager = self.vreg.select('components', 'authmanager')
    44         self.authmanager = self.vreg['components'].select('authmanager')
    45 
    45 
    46     def clean_sessions(self):
    46     def clean_sessions(self):
    47         """cleanup sessions which has not been unused since a given amount of
    47         """cleanup sessions which has not been unused since a given amount of
    48         time. Return the number of sessions which have been closed.
    48         time. Return the number of sessions which have been closed.
    49         """
    49         """
   110       identifier
   110       identifier
   111     """
   111     """
   112     SESSION_VAR = '__session'
   112     SESSION_VAR = '__session'
   113 
   113 
   114     def __init__(self, appli):
   114     def __init__(self, appli):
   115         self.session_manager = appli.vreg.select('components', 'sessionmanager')
   115         self.session_manager = appli.vreg['components'].select('sessionmanager')
   116         global SESSION_MANAGER
   116         global SESSION_MANAGER
   117         SESSION_MANAGER = self.session_manager
   117         SESSION_MANAGER = self.session_manager
   118         if not 'last_login_time' in appli.vreg.schema:
   118         if not 'last_login_time' in appli.vreg.schema:
   119             self._update_last_login_time = lambda x: None
   119             self._update_last_login_time = lambda x: None
   120 
   120 
   237         else:
   237         else:
   238             self._query_log = None
   238             self._query_log = None
   239             self.publish = self.main_publish
   239             self.publish = self.main_publish
   240         # instantiate session and url resolving helpers
   240         # instantiate session and url resolving helpers
   241         self.session_handler = session_handler_fact(self)
   241         self.session_handler = session_handler_fact(self)
   242         self.url_resolver = vreg.select('components', 'urlpublisher')
   242         self.url_resolver = vreg['components'].select('urlpublisher')
   243 
   243 
   244     def connect(self, req):
   244     def connect(self, req):
   245         """return a connection for a logged user object according to existing
   245         """return a connection for a logged user object according to existing
   246         sessions (i.e. a new connection may be created or an already existing
   246         sessions (i.e. a new connection may be created or an already existing
   247         one may be reused
   247         one may be reused
   273                 self._logfile_lock.release()
   273                 self._logfile_lock.release()
   274 
   274 
   275     @deprecated("use vreg.select('controllers', ...)")
   275     @deprecated("use vreg.select('controllers', ...)")
   276     def select_controller(self, oid, req):
   276     def select_controller(self, oid, req):
   277         try:
   277         try:
   278             return self.vreg.select('controllers', oid, req=req, appli=self)
   278             return self.vreg['controllers'].select(oid, req=req, appli=self)
   279         except NoSelectableObject:
   279         except NoSelectableObject:
   280             raise Unauthorized(req._('not authorized'))
   280             raise Unauthorized(req._('not authorized'))
   281 
   281 
   282     def main_publish(self, path, req):
   282     def main_publish(self, path, req):
   283         """method called by the main publisher to process <path>
   283         """method called by the main publisher to process <path>
   302         tstart = clock()
   302         tstart = clock()
   303         try:
   303         try:
   304             try:
   304             try:
   305                 ctrlid, rset = self.url_resolver.process(req, path)
   305                 ctrlid, rset = self.url_resolver.process(req, path)
   306                 try:
   306                 try:
   307                     controller = self.vreg.select('controllers', ctrlid, req,
   307                     controller = self.vreg['controllers'].select(ctrlid, req,
   308                                                   appli=self)
   308                                                                  appli=self)
   309                 except NoSelectableObject:
   309                 except NoSelectableObject:
   310                     raise Unauthorized(req._('not authorized'))
   310                     raise Unauthorized(req._('not authorized'))
   311                 req.update_search_state()
   311                 req.update_search_state()
   312                 result = controller.publish(rset=rset)
   312                 result = controller.publish(rset=rset)
   313                 if req.cnx is not None:
   313                 if req.cnx is not None:
   373         try:
   373         try:
   374             req.data['ex'] = ex
   374             req.data['ex'] = ex
   375             if tb:
   375             if tb:
   376                 req.data['excinfo'] = excinfo
   376                 req.data['excinfo'] = excinfo
   377             req.form['vid'] = 'error'
   377             req.form['vid'] = 'error'
   378             errview = self.vreg.select('views', 'error', req)
   378             errview = self.vreg['views'].select('error', req)
   379             template = self.main_template_id(req)
   379             template = self.main_template_id(req)
   380             content = self.vreg.main_template(req, template, view=errview)
   380             content = self.vreg['views'].main_template(req, template, view=errview)
   381         except:
   381         except:
   382             content = self.vreg.main_template(req, 'error-template')
   382             content = self.vreg['views'].main_template(req, 'error-template')
   383         raise StatusResponse(500, content)
   383         raise StatusResponse(500, content)
   384 
   384 
   385     def need_login_content(self, req):
   385     def need_login_content(self, req):
   386         return self.vreg.main_template(req, 'login')
   386         return self.vreg['views'].main_template(req, 'login')
   387 
   387 
   388     def loggedout_content(self, req):
   388     def loggedout_content(self, req):
   389         return self.vreg.main_template(req, 'loggedout')
   389         return self.vreg['views'].main_template(req, 'loggedout')
   390 
   390 
   391     def notfound_content(self, req):
   391     def notfound_content(self, req):
   392         req.form['vid'] = '404'
   392         req.form['vid'] = '404'
   393         view = self.vreg.select('views', '404', req)
   393         view = self.vreg['views'].select('404', req)
   394         template = self.main_template_id(req)
   394         template = self.main_template_id(req)
   395         return self.vreg.main_template(req, template, view=view)
   395         return self.vreg['views'].main_template(req, template, view=view)
   396 
   396 
   397     def main_template_id(self, req):
   397     def main_template_id(self, req):
   398         template = req.form.get('__template', req.property_value('ui.main-template'))
   398         template = req.form.get('__template', req.property_value('ui.main-template'))
   399         if template not in self.vreg.registry('views'):
   399         if template not in self.vreg['views']:
   400             template = 'main-template'
   400             template = 'main-template'
   401         return template
   401         return template
   402 
   402 
   403 
   403 
   404 set_log_methods(CubicWebPublisher, LOGGER)
   404 set_log_methods(CubicWebPublisher, LOGGER)