Browse Source

refactored column display selection

php2python
Holger Frey 7 years ago
parent
commit
fe6e13aa09
  1. 4
      ordr2/events.py
  2. 12
      ordr2/views/__init__.py
  3. 11
      ordr2/views/admin.py

4
ordr2/events.py

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
from pyramid.events import subscriber
from pyramid.events import NewRequest, subscriber
class UserLogIn(object):
@ -8,7 +8,9 @@ class UserLogIn(object): @@ -8,7 +8,9 @@ class UserLogIn(object):
@subscriber(UserLogIn)
@subscriber(NewRequest)
def set_display_defaults(event):
if event.request.user and 'display' not in event.request.session:
defaults = {
'users': {
'first': True,

12
ordr2/views/__init__.py

@ -10,6 +10,18 @@ def flash(request, channel, message, description='', dismissable=True): @@ -10,6 +10,18 @@ def flash(request, channel, message, description='', dismissable=True):
request.session.flash(msg, channel, allow_duplicate=False)
def update_column_display(request, section):
''' update the session values for wich columns to display '''
if section not in request.session['display']:
return
display_keys = request.session['display'][section].keys()
display = dict.fromkeys(display_keys, False)
for column in request.POST.values():
if column in display:
display[column] = True
request.session['display'][section] = display
def includeme(config):
''' adding request helpers and static views '''
config.add_request_method(flash, 'flash')

11
ordr2/views/admin.py

@ -8,6 +8,8 @@ from pyramid.view import view_config @@ -8,6 +8,8 @@ from pyramid.view import view_config
from ordr2.models import User, Role
from ordr2.schemas.account import UserSchema
from . import update_column_display
# user log in and log out
@view_config(
@ -53,14 +55,7 @@ def user_list(context, request): @@ -53,14 +55,7 @@ def user_list(context, request):
)
def change_column_view(context, request):
''' changes the columns to display '''
display = {
'first': False,
'last': False,
'email': False
}
columns = [col for key, col in request.POST.items() if key == 'display']
display.update({ column: True for column in columns })
request.session['display']['users'] = display
update_column_display(request, 'users')
return HTTPFound(context.url())