Browse Source

added user list view

as a paginated resource \o/
php2python
Holger Frey 7 years ago
parent
commit
bd0b8fd0a2
  1. 4
      ordr2/templates/admin/admin_section.jinja2
  2. 90
      ordr2/templates/admin/user_list.jinja2
  3. 58
      ordr2/templates/macros.jinja2
  4. 12
      ordr2/views/admin.py

4
ordr2/templates/admin/admin_section.jinja2

@ -17,13 +17,13 @@
<div class="row-fluid">{{ macros.flash_messages() }}</div> <div class="row-fluid">{{ macros.flash_messages() }}</div>
<div class="row admin-options"> <div class="row admin-options">
<a href="<?php echo base_url(); ?>admin/users/view/"> <a href="{{ request.resource_url(context, 'users') }}">
<div class="span4 rounded-box"> <div class="span4 rounded-box">
<div class="option user"></div> <div class="option user"></div>
<h2>Mangage Users</h2> <h2>Mangage Users</h2>
</div> </div>
</a> </a>
<a href="<?php echo base_url(); ?>admin/consumables/view/"> <a href="{{ request.resource_url(context, 'consumables') }}">
<div class="span4 rounded-box"> <div class="span4 rounded-box">
<div class="option shop"></div> <div class="option shop"></div>
<h2>Manage Consumables</h2> <h2>Manage Consumables</h2>

90
ordr2/templates/admin/user_list.jinja2

@ -0,0 +1,90 @@
{% extends "ordr2:templates/layout.jinja2" %}
{% import 'ordr2:templates/macros.jinja2' as macros with context %}
{% block subtitle %} Admin | Users {% endblock subtitle %}
{% block content %}
<div class="content controls">
<div class="container-fluid controls">
<div class="row-fluid">
<div class="span2">
<div class="page-controls">
<h1>
Users
</h1>
</div>
{{ macros.filter_box('Role', 'role', roles) }}
</div>
<div class="span10">
<form action="{{ request.resource_url(context, 'actions') }}" method="POST">
<input type="hidden" name="csrf_token" value="{{get_csrf_token()}}">
<div class="page-controls">
<div class="input-append search">
<input type="search" name="search" size="30" placeholder="Search">
<label class="add-on">
<button type="submit" class="search" name="action" value="search">Search</button>
</label>
</div>
<div class="actions">
<div class="btn-group marking-needed">
<button rel="tooltip" data-original-title="Change Role" class="btn-flat group" name="action" type="submit" value="role"><i class="group"></i></button>
<button rel="tooltip" data-original-title="Delete" class="btn-flat delete" name="action" type="submit" value="delete"><i class="trash"></i></button>
</div>
<a href="#modal-display" rel="tooltip" data-original-title="Display Options" class="btn-flat single" data-toggle="modal"><i class="eye"></i></a>
</div>
</div>
{{ macros.flash_messages() }}
{% if users %}
<table class="table">
<thead>
<th class="center">
<input type="checkbox" value="all" name="mark_all" id="mark_all">
</th>
{{ macros.sortable_table_header('Username', 'user') }}
{{ macros.sortable_table_header('First Name', 'first') }}
{{ macros.sortable_table_header('Last Name', 'last') }}
{{ macros.sortable_table_header('Email', 'email') }}
{{ macros.sortable_table_header('Role', 'role') }}
<th>Actions</th>
</thead>
<tbody>
{% for user in users %}
<tr>
<td class="center">
<input type="checkbox" name="marked" value="{{ user.model.user_name }}">
</td>
<td>
<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>{{ user.model.first_name }} </td>
<td>{{ user.model.last_name }} </td>
<td>{{ user.model.email }} </td>
<td>{{ user.model.role.value.capitalize() }} </td>
<td>
<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>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{{ macros.pagination() }}
{% else %}
<div class="alert alert-block alert-error">
<h4 class="alert-heading">Oh snap! Nothing to display!</h4>
<p>Your query didn't return any data.</p>
</div>
{% endif %}
</form>
</div>
</div>
</div>
</div>
{% endblock content %}

58
ordr2/templates/macros.jinja2

@ -14,3 +14,61 @@
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
{%- endmacro %} {%- endmacro %}
{% macro filter_box(title, query_key, items) -%}
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">{{ title }}</li>
<li {% if not context.filters.get(query_key) %}class="active"{% endif %}>
<a href="{{ context.url( (query_key, None), (context.query_key_current_page, 1) ) }}">All</a>
</li>
{% for filter, display in items %}
<li {% if context.filters.get(query_key) == filter %}class="active"{% endif %}>
<a href="{{ context.url( (query_key, filter), (context.query_key_current_page, 1) ) }}">{{ display }}</a>
</li>
{% endfor %}
</ul>
</div>
{%- endmacro %}
{% macro sortable_table_header(title, sort_by) -%}
<th class="sortable blue header {% 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_sort = sort_by + '.' + new_direction %}
<a href="{{ context.url( (context.query_key_sorting, new_sort), (context.query_key_current_page, 1) ) }}">{{ title }}</a>
</th>
{%- endmacro %}
{% macro pagination_helper(page, text=None, css_class='') -%}
{% set is_active = 'active' if page == context.pages.current %}
{% set is_disabled = 'disabled' if not page %}
{% set url = context.url( (context.query_key_current_page, page) ) if page %}
<li class="{{ css_class }} {{ is_active }} {{ is_disabled }}">
<a href="{{ url }}" >{{ text if text else page }}</a>
</li>
{%- endmacro %}}
{% macro pagination() -%}
{% if context.pages and context.pages.last > 1 %}
<div class="pagination pagination-centered">
<ul>
{{ pagination_helper(context.pages.previous, '\u2190 Previous', 'prev') }}
{% if context.pages.first not in context.pages.window %}
{{ pagination_helper(None, '...') }}
{% endif %}
{% for page in context.pages.window %}
{{ pagination_helper(page) }}
{% endfor %}
{% if context.pages.last not in context.pages.window %}
{{ pagination_helper(None, '...') }}
{% endif %}
{{ pagination_helper(context.pages.next, 'Next \u2192', 'next') }}
</ul>
</div>
{% endif %}
{%- endmacro %}

12
ordr2/views/admin.py

@ -29,3 +29,15 @@ def admin_section(context, request):
processed.'''.format(request.resource_url(context, 'users')) processed.'''.format(request.resource_url(context, 'users'))
) )
return {} return {}
@view_config(
context='ordr2:resources.UserList',
permission='view',
renderer='ordr2:templates/admin/user_list.jinja2'
)
def user_list(context, request):
''' display the user list '''
users = context.items()
roles = [(role.name, role.value.capitalize()) for role in Role]
return {'users':users, 'roles':roles}