def load_grid_state(self): """Loads the stored grid state - if any is stored. """ # get the key from the key generator generator = queryMultiAdapter((self.context, self, self.request), IGridStateStorageKeyGenerator) key = generator.get_key() # get the state (string) storage = IDictStorage(self) state = storage.get(key, None) if state: parsed_state = json.loads(state) # Do not persistently store grouping, since loading the group # initially would not work. if 'group' in parsed_state: del parsed_state['group'] # In some situations the sorting in the state is corrupt. Every # visible row should have a 'sortable' by default. column_state_by_id = dict( (col['id'], col) for col in parsed_state['columns']) for column in self.columns: if not isinstance(column, dict): continue name = column.get('sort_index', column.get('column', None)) if name not in column_state_by_id: continue col_state = column_state_by_id[name] if 'sortable' not in col_state: col_state['sortable'] = True state = json.dumps(parsed_state) if state: self.table_options.update({'gridstate': state}) else: return # if the sorting order is set in the state and is not set in the # request, we need to change it in the config using the state # config. if self.request.get('dir', _marker) == _marker and \ self.request.get('sort', _marker) == _marker and \ 'sort' in parsed_state: if 'field' in parsed_state['sort']: self.sort_on = parsed_state['sort']['field'] if parsed_state['sort']['direction'] == 'ASC': self.sort_order = 'asc' self.sort_reverse = False else: self.sort_order = 'reverse' self.sort_reverse = True
def load_grid_state(self): """Loads the stored grid state - if any is stored. """ # get the key from the key generator generator = queryMultiAdapter((self.context, self, self.request), IGridStateStorageKeyGenerator) key = generator.get_key() # get the state (string) storage = IDictStorage(self) state = storage.get(key, None) if state: parsed_state = json.loads(state) # Do not persistently store grouping, since loading the group # initially would not work. if 'group' in parsed_state: del parsed_state['group'] # In some situations the sorting in the state is corrupt. Every # visible row should have a 'sortable' by default. column_state_by_id = dict((col['id'], col) for col in parsed_state['columns']) for column in self.columns: if not isinstance(column, dict): continue name = column.get('sort_index', column.get('column', None)) if name not in column_state_by_id: continue col_state = column_state_by_id[name] if 'sortable' not in col_state: col_state['sortable'] = True state = json.dumps(parsed_state) if state: self.table_options.update({'gridstate': state}) else: return # if the sorting order is set in the state and is not set in the # request, we need to change it in the config using the state # config. if self.request.get('dir', _marker) == _marker and \ self.request.get('sort', _marker) == _marker and \ 'sort' in parsed_state: if 'field' in parsed_state['sort']: self.sort_on = parsed_state['sort']['field'] if parsed_state['sort']['direction'] == 'ASC': self.sort_order = 'asc' self.sort_reverse = False else: self.sort_order = 'reverse' self.sort_reverse = True
def get_grid_state(self, view_name): """Load tabbedview gridstate of the logged in users for the given view. """ tabbedview = self.context.restrictedTraverse( "@@tabbedview_view-{}".format(view_name), default=None) if not tabbedview: return None generator = queryMultiAdapter((self.context, tabbedview, self.request), IGridStateStorageKeyGenerator) key = generator.get_key() storage = IDictStorage(tabbedview) return json.loads(storage.get(key, '{}'))
def get_db_sync_stamp(self): storage = IDictStorage(DictStorageConfigurationContext()) timestamp = storage.get(DICTSTORAGE_SYNC_KEY) return timestamp