From c754b23daa2a4c8791a71ed6243253e835e2794e Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Sat, 30 Sep 2017 11:56:38 +0200 Subject: [PATCH] added showing and hiding of column tables --- ordr2/resources/admin.py | 12 ++++-- ordr2/templates/admin/user_list.jinja2 | 55 +++++++++++++++++++++++--- ordr2/templates/macros.jinja2 | 19 ++++++++- ordr2/views/admin.py | 19 +++++++++ 4 files changed, 95 insertions(+), 10 deletions(-) diff --git a/ordr2/resources/admin.py b/ordr2/resources/admin.py index a41b850..fc25c2f 100644 --- a/ordr2/resources/admin.py +++ b/ordr2/resources/admin.py @@ -1,4 +1,4 @@ -from pyramid.security import Allow, Authenticated, Deny, Everyone +from pyramid.security import Allow, Authenticated, Deny, DENY_ALL, Everyone from .base import BaseResource, PaginationResourceMixin from ordr2.models import User, Role @@ -8,7 +8,10 @@ from ordr2.models import User, Role class UserAccount(BaseResource): def __acl__(self): - return [ (Allow, 'role:admin', 'view') ] + return [ + (Allow, 'role:admin', 'view'), + DENY_ALL + ] class UserList(BaseResource, PaginationResourceMixin): @@ -18,7 +21,10 @@ class UserList(BaseResource, PaginationResourceMixin): default_items_per_page = 12 def __acl__(self): - return [ (Allow, 'role:admin', 'view') ] + return [ + (Allow, 'role:admin', 'view'), + DENY_ALL + ] def prepare_filtered_query(self, dbsession, filter_params): diff --git a/ordr2/templates/admin/user_list.jinja2 b/ordr2/templates/admin/user_list.jinja2 index 5582222..de0ffd8 100644 --- a/ordr2/templates/admin/user_list.jinja2 +++ b/ordr2/templates/admin/user_list.jinja2 @@ -39,6 +39,7 @@ {{ macros.flash_messages() }} {% if users %} + {{ macros.show_or_hide_columns('users') }} @@ -59,13 +60,13 @@ - - - - - + + + +
+ {{ user.model.user_name }} {{ user.model.first_name }} {{ user.model.last_name }} {{ user.model.email }} {{ user.model.role.value.capitalize() }} {{ user.model.first_name }} {{ user.model.last_name }} {{ user.model.email }} {{ user.model.role.value.capitalize() }} edit delete @@ -86,5 +87,49 @@ + {% endblock content %} diff --git a/ordr2/templates/macros.jinja2 b/ordr2/templates/macros.jinja2 index 95f5943..5a2e10f 100644 --- a/ordr2/templates/macros.jinja2 +++ b/ordr2/templates/macros.jinja2 @@ -33,8 +33,23 @@ {%- endmacro %} -{% macro sortable_table_header(title, sort_by) -%} - +{% macro show_or_hide_columns(name) -%} + {% set display = request.session.get('display', dict()) %} + {% set section = display.get(name, None) %} + {% if section %} + + {% endif %} +{%- endmacro %} + +{% macro sortable_table_header(title, sort_by, column_class=None) -%} + {% set column_class = column_class or 'column-' + sort_by %} + {% set new_direction = 'desc' if context.sorting.direction == 'asc' else 'asc' %} {% set new_sort = sort_by + '.' + new_direction %} {{ title }} diff --git a/ordr2/views/admin.py b/ordr2/views/admin.py index dd26e31..436f499 100644 --- a/ordr2/views/admin.py +++ b/ordr2/views/admin.py @@ -43,3 +43,22 @@ def user_list(context, request): users = context.items() roles = [(role.value.lower(), role.value.capitalize()) for role in Role] return {'users':users, 'roles':roles} + + +@view_config( + context='ordr2:resources.UserList', + name = 'changeview', + permission='view', + request_method='POST' + ) +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 + return HTTPFound(context.url())