Skip to content

Commit

Permalink
sorting table
Browse files Browse the repository at this point in the history
  • Loading branch information
cormachallinanderilinx committed Oct 15, 2024
1 parent e3ce22b commit 022b4a7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
24 changes: 18 additions & 6 deletions ckanext/iati/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,31 @@ def get_publisher_obj_extra_fields_pub_ids(group_dict):
extras['publisher_iati_id'] = group_dict.get('publisher_iati_id', '')
return extras

def get_user_search_extras(user):
extras = {}
if not user:
return extras
def _user_last_activity(user):
q = model.Session.query(model.Activity)
q = q.filter(model.Activity.user_id == user[0].id)
q = q.order_by(model.Activity.timestamp.desc())

last_activity = q.first()
if last_activity:
extras['last_activity'] = last_activity.timestamp.strftime("%d %b %Y")
return last_activity.timestamp.strftime("%d %b %Y")
else:
extras['last_activity'] = ''
return ''

def _user_publishers(user):
# Group = IATI Publisher
publisher = model.Group
query = model.Session.query(publisher) \
.join(model.Member, (publisher.id == model.Member.group_id)) \
.filter(model.Member.table_id == user[0].id)
return query.all()

def get_user_search_extras(user):
extras = {}
if not user:
return extras
extras['publishers'] = _user_publishers(user)
extras['last_activity'] = _user_last_activity(user)
return extras

def is_route_active(menu_item):
Expand Down
31 changes: 29 additions & 2 deletions ckanext/iati/theme/templates/user/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,37 @@
<h1 class="page-heading">
{% block page_heading %}{{ _('Users') }}{% endblock %}
</h1>

{% block search_sortby %}
{% if sorting %}
<div class="form-select form-group control-order-by">
<label for="field-order-by">{{ _('Order by') }}</label>
<select id="field-order-by" name="sort" class="form-control">
{% for label, value in sorting %}
{% if label and value %}
<option value="{{ value }}"{% if sorting_selected == value %} selected="selected"{% endif %}>{{ label }}</option>
{% endif %}
{% endfor %}
</select>
{% block search_sortby_button %}
<button class="btn btn-default js-hide" type="submit">{{ _('Go') }}</button>
{% endblock %}
</div>
{% endif %}
{% endblock %}

{% block users_list %}
<form method="post" action="{{ url_for('users.delete_selected_users') }}">
<table class="table table-hover table-bordered table-striped table-sorted" data-module="table-sorter">
<thead>
<tr>
<th title="Sort by name">Name</th>
<th title="Sort by name">Full Names</th>
<th title="Sort by name">Username</th>
<th title="Sort by email">Email</th>
<th title="Sort by created">Date Created</th>
<th title="Sort by number of datasets">Datasets Created</th>
<th title="Sort by last activity">Last Activity</th>
<th>Last Activity</th>
<th>Publishers</th>
{% if c.userobj and 'sysadmin' %}
<th>Select to delete</th>
{% endif %}
Expand All @@ -41,6 +61,13 @@ <h1 class="page-heading">
<td>{{ h.render_datetime(user.created) }}</td>
<td>{{ h.SI_number_span(user.number_created_packages) }}</td>
<td>{{ extra_fields.last_activity }}</td>
<td>
{% for publisher in extra_fields.publishers %}
{% if publisher %}
<li><a href="{{ h.url_for('publisher.read', id=publisher.name) }}">{{ h.normalize_publisher_name(publisher.title) }} ({{ publisher.state }})</a></li>
{% endif %}
{% endfor %}
</td>
{% if c.userobj and 'sysadmin' %}
<td><input type="checkbox" name="selected_users" value="{{ user[0].id }}"></td>
{% endif %}
Expand Down

0 comments on commit 022b4a7

Please sign in to comment.