Browse Source

added showing and hiding of column tables

php2python
Holger Frey 7 years ago
parent
commit
c754b23daa
  1. 12
      ordr2/resources/admin.py
  2. 55
      ordr2/templates/admin/user_list.jinja2
  3. 19
      ordr2/templates/macros.jinja2
  4. 19
      ordr2/views/admin.py

12
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 .base import BaseResource, PaginationResourceMixin
from ordr2.models import User, Role from ordr2.models import User, Role
@ -8,7 +8,10 @@ from ordr2.models import User, Role
class UserAccount(BaseResource): class UserAccount(BaseResource):
def __acl__(self): def __acl__(self):
return [ (Allow, 'role:admin', 'view') ] return [
(Allow, 'role:admin', 'view'),
DENY_ALL
]
class UserList(BaseResource, PaginationResourceMixin): class UserList(BaseResource, PaginationResourceMixin):
@ -18,7 +21,10 @@ class UserList(BaseResource, PaginationResourceMixin):
default_items_per_page = 12 default_items_per_page = 12
def __acl__(self): def __acl__(self):
return [ (Allow, 'role:admin', 'view') ] return [
(Allow, 'role:admin', 'view'),
DENY_ALL
]
def prepare_filtered_query(self, dbsession, filter_params): def prepare_filtered_query(self, dbsession, filter_params):

55
ordr2/templates/admin/user_list.jinja2

@ -39,6 +39,7 @@
{{ macros.flash_messages() }} {{ macros.flash_messages() }}
{% if users %} {% if users %}
{{ macros.show_or_hide_columns('users') }}
<table class="table"> <table class="table">
<thead> <thead>
@ -59,13 +60,13 @@
<td class="center"> <td class="center">
<input type="checkbox" name="marked" value="{{ user.model.user_name }}"> <input type="checkbox" name="marked" value="{{ user.model.user_name }}">
</td> </td>
<td> <td class="column-user">
<a href="{{ request.resource_url(request.root, 'orders', query={'user': user.model.user_name}) }}" title="click to view all orders from user">{{ user.model.user_name }}</a> <a href="{{ request.resource_url(request.root, 'orders', query={'user': user.model.user_name}) }}" title="click to view all orders from user">{{ user.model.user_name }}</a>
</td> </td>
<td>{{ user.model.first_name }} </td> <td class="column-first">{{ user.model.first_name }} </td>
<td>{{ user.model.last_name }} </td> <td class="column-last">{{ user.model.last_name }} </td>
<td>{{ user.model.email }} </td> <td class="column-email">{{ user.model.email }} </td>
<td>{{ user.model.role.value.capitalize() }} </td> <td class="column-role">{{ user.model.role.value.capitalize() }} </td>
<td> <td>
<a href="{{ request.resource_url(user, 'edit') }}" class="action edit" title="Edit User">edit</a> <a href="{{ request.resource_url(user, 'edit') }}" class="action edit" title="Edit User">edit</a>
<a href="{{ request.resource_url(user, 'delete') }}" class="action delete" title="Delete User">delete</a> <a href="{{ request.resource_url(user, 'delete') }}" class="action delete" title="Delete User">delete</a>
@ -86,5 +87,49 @@
</div> </div>
</div> </div>
</div> </div>
<div id="modal-display" class="modal hide fade">
<form action="{{ request.resource_url(context, 'changeview', query=context.query_params()) }}" method="POST" class="checkslist">
<input type="hidden" name="csrf_token" value="{{get_csrf_token()}}">
{% set display = request.session.get('display', dict()) %}
{% set settings = display.get('users', dict()) %}
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal">×</a>
<h3>Display Options</h3>
</div>
<div class="modal-body">
<p class="help-block"><span class="label notice">Notice</span> If the displayed information is too cluttered, deselect some fields below. This will temporaly remove them from your view and should help you stay on top of things.</p>
<div class="checklist">
<fieldset class="left">
<label class="checkbox">
<input type="checkbox" checked="checked" value="user" name="display" disabled="disabled" >
Username
</label>
<label class="checkbox">
<input type="checkbox" {{ 'checked="checked"' if settings.get('first') }} value="first" name="display">
First Name
</label>
<label class="checkbox">
<input type="checkbox" {{ 'checked="checked"' if settings.get('last') }} value="last" name="display">
Last Name
</label>
</fieldset>
<fieldset class="right">
<label class="checkbox">
<input type="checkbox" {{ 'checked="checked"' if settings.get('email') }} value="email" name="display">
Email
</label>
<label class="checkbox">
<input type="checkbox" checked="checked" value="role" name="display" disabled="disabled" >
Role
</label>
</fieldset>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="submit">Apply Changes</button>
<a data-dismiss="modal" class="btn" href="#">Close</a>
</div>
</form>
</div>
</div> </div>
{% endblock content %} {% endblock content %}

19
ordr2/templates/macros.jinja2

@ -33,8 +33,23 @@
{%- endmacro %} {%- endmacro %}
{% macro sortable_table_header(title, sort_by) -%} {% macro show_or_hide_columns(name) -%}
<th class="sortable blue header {% if sort_by == context.sorting.field %} active {{ 'headerSortUp' if context.sorting.direction == 'asc' else 'headerSortDown' }} {% endif %} "> {% set display = request.session.get('display', dict()) %}
{% set section = display.get(name, None) %}
{% if section %}
<style type="text/css">
{% for column, show in section.items() %}
{% if not show %}
.column-{{ column }} { display: none; }
{% endif %}
{% endfor %}
</style>
{% endif %}
{%- endmacro %}
{% macro sortable_table_header(title, sort_by, column_class=None) -%}
{% set column_class = column_class or 'column-' + sort_by %}
<th class="sortable blue header {{ column_class }} {% if sort_by == context.sorting.field %} active {{ 'headerSortUp' if context.sorting.direction == 'asc' else 'headerSortDown' }} {% endif %} ">
{% set new_direction = 'desc' if context.sorting.direction == 'asc' else 'asc' %} {% set new_direction = 'desc' if context.sorting.direction == 'asc' else 'asc' %}
{% set new_sort = sort_by + '.' + new_direction %} {% set new_sort = sort_by + '.' + new_direction %}
<a href="{{ context.url( (context.query_key_sorting, new_sort), (context.query_key_current_page, 1) ) }}">{{ title }}</a> <a href="{{ context.url( (context.query_key_sorting, new_sort), (context.query_key_current_page, 1) ) }}">{{ title }}</a>

19
ordr2/views/admin.py

@ -43,3 +43,22 @@ def user_list(context, request):
users = context.items() users = context.items()
roles = [(role.value.lower(), role.value.capitalize()) for role in Role] roles = [(role.value.lower(), role.value.capitalize()) for role in Role]
return {'users':users, 'roles':roles} 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())