Browse Source

refactored column display selection

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

18
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,12 +8,14 @@ class UserLogIn(object): @@ -8,12 +8,14 @@ class UserLogIn(object):
@subscriber(UserLogIn)
@subscriber(NewRequest)
def set_display_defaults(event):
defaults = {
'users': {
'first': True,
'last': True,
'email': True,
if event.request.user and 'display' not in event.request.session:
defaults = {
'users': {
'first': True,
'last': True,
'email': True,
}
}
}
event.request.session['display'] = defaults
event.request.session['display'] = defaults

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())