Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to select or deselect columns to be displayed in lists #410

Merged
merged 6 commits into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changelog

**Fixed**

- #410 Unable to select or deselect columns to be displayed in lists
- #409 In Add Analyses view, analyses id are displayed instead of Analysis Request IDs
- #378 Fix GeneXpert interface does not import results for multiple analyses
- #416 Fix inconsistencies with sorting criterias in lists
Expand Down
46 changes: 23 additions & 23 deletions bika/lims/browser/bika_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,7 @@ def _process_request(self):
# and modify self.columns[]['toggle'] to match.
toggle_cols = self.get_toggle_cols()
for col in self.columns.keys():
if col in toggle_cols:
self.columns[col]['toggle'] = True
else:
self.columns[col]['toggle'] = False
self.columns[col]['toggle'] = col in toggle_cols
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


def _set_sorting_criteria(self):
"""
Expand Down Expand Up @@ -822,25 +819,28 @@ def get_columns_indexes(self):
return indexes

def get_toggle_cols(self):
_form = self.request.form
toggles = {}
try:
default_toggles = _form.get("toggle_cols", "{}")
_key = self.form_id + "_toggle_cols"
form_toggles = _form.get(_key, default_toggles)
toggles = json.loads(form_toggles)
except (ValueError, TypeError):
pass
finally:
if not toggles:
toggles = {}
cookie_key = "%s%s" % (self.context.portal_type, self.form_id)
toggle_cols = toggles.get(
cookie_key, [col for col in self.columns.keys()
if col in self.review_state['columns'] and
('toggle' not in self.columns[col] or
self.columns[col]['toggle'] is True)])
return toggle_cols
"""
Returns the list of column ids to be displayed for the current list.
:return: list of column ids to be displayed
:rtype: list of str
"""
# Get the toggle configuration from the cookie
cookie_toggle = self.request.get('toggle_cols', '{}')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be that value in self.request.cookies?

Reminder: We have to consolidate all the different places in the system where cookies get set, because these cookies make caching by Varnish impossible.

cookie_toggle = json.loads(cookie_toggle)

# Load the toggling configuration for the current list
list_toggle_key = "%s%s" % (self.context.portal_type, self.form_id)
list_toggle = cookie_toggle.get(list_toggle_key, [])

# If there is no stored configuration re toggle for the current list
# in the cookie (or if there is no cookie for toggle config), use the
# default configuration based on the initial column settings
if not list_toggle:
columns_ids = self.review_state['columns']
list_toggle = [col_id for col_id in columns_ids if
self.columns[col_id].get('toggle', True) is True]

return list_toggle

def GET_url(self, include_current=True, **kwargs):
url = self.request['URL'].split("?")[0]
Expand Down