web/request.py
changeset 10274 1f84295bfe95
parent 10215 96085e379066
child 10275 d6131c5045be
equal deleted inserted replaced
10273:ef74abcf369d 10274:1f84295bfe95
   153         self.set_user_language(None)
   153         self.set_user_language(None)
   154         #: dictionary that may be used to store request data that has to be
   154         #: dictionary that may be used to store request data that has to be
   155         #: shared among various components used to publish the request (views,
   155         #: shared among various components used to publish the request (views,
   156         #: controller, application...)
   156         #: controller, application...)
   157         self.data = {}
   157         self.data = {}
   158         #:  search state: 'normal' or 'linksearch' (eg searching for an object
   158         self._search_state = None
   159         #:  to create a relation with another)
       
   160         self.search_state = ('normal',)
       
   161         #: page id, set by htmlheader template
   159         #: page id, set by htmlheader template
   162         self.pageid = None
   160         self.pageid = None
   163         self._set_pageid()
   161         self._set_pageid()
   164 
   162 
   165     def _set_pageid(self):
   163     def _set_pageid(self):
   352             del self._msg
   350             del self._msg
   353         if hasattr(self, '_msgid'):
   351         if hasattr(self, '_msgid'):
   354             self.session.data.pop(self._msgid, u'')
   352             self.session.data.pop(self._msgid, u'')
   355             del self._msgid
   353             del self._msgid
   356 
   354 
       
   355     def _load_search_state(self, searchstate):
       
   356         if searchstate is None or searchstate == 'normal':
       
   357             self._search_state = (searchstate or 'normal',)
       
   358         else:
       
   359             self._search_state = ('linksearch', searchstate.split(':'))
       
   360             assert len(self._search_state[-1]) == 4, 'invalid searchstate'
       
   361 
       
   362     @property
       
   363     def search_state(self):
       
   364         """search state: 'normal' or 'linksearch' (eg searching for an object
       
   365         to create a relation with another)"""
       
   366         if self._search_state is None:
       
   367             searchstate = self.session.data.get('search_state', 'normal')
       
   368             self._load_search_state(searchstate)
       
   369         return self._search_state
       
   370 
   357     def update_search_state(self):
   371     def update_search_state(self):
   358         """update the current search state"""
   372         """update the current search state if needed"""
   359         searchstate = self.form.get('__mode')
   373         searchstate = self.form.get('__mode')
   360         if not searchstate:
   374         if searchstate:
   361             searchstate = self.session.data.get('search_state', 'normal')
   375             self.set_search_state(searchstate)
   362         self.set_search_state(searchstate)
       
   363 
   376 
   364     def set_search_state(self, searchstate):
   377     def set_search_state(self, searchstate):
   365         """set a new search state"""
   378         """set a new search state"""
   366         if searchstate is None or searchstate == 'normal':
       
   367             self.search_state = (searchstate or 'normal',)
       
   368         else:
       
   369             self.search_state = ('linksearch', searchstate.split(':'))
       
   370             assert len(self.search_state[-1]) == 4
       
   371         self.session.data['search_state'] = searchstate
   379         self.session.data['search_state'] = searchstate
       
   380         self._load_search_state(searchstate)
   372 
   381 
   373     def match_search_state(self, rset):
   382     def match_search_state(self, rset):
   374         """when searching an entity to create a relation, return True if entities in
   383         """when searching an entity to create a relation, return True if entities in
   375         the given rset may be used as relation end
   384         the given rset may be used as relation end
   376         """
   385         """
   383                 return False
   392                 return False
   384         return True
   393         return True
   385 
   394 
   386     def update_breadcrumbs(self):
   395     def update_breadcrumbs(self):
   387         """stores the last visisted page in session data"""
   396         """stores the last visisted page in session data"""
   388         searchstate = self.session.data.get('search_state')
   397         searchstate = self.search_state[0]
   389         if searchstate == 'normal':
   398         if searchstate == 'normal':
   390             breadcrumbs = self.session.data.get('breadcrumbs')
   399             breadcrumbs = self.session.data.get('breadcrumbs')
   391             if breadcrumbs is None:
   400             if breadcrumbs is None:
   392                 breadcrumbs = SizeConstrainedList(10)
   401                 breadcrumbs = SizeConstrainedList(10)
   393                 self.session.data['breadcrumbs'] = breadcrumbs
   402                 self.session.data['breadcrumbs'] = breadcrumbs