mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
make admin_users table sortable
This commit is contained in:
parent
e007f14359
commit
5e911b4853
2 changed files with 78 additions and 25 deletions
|
@ -1147,21 +1147,30 @@ def admin_users():
|
||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
search = request.args.get('search', '')
|
search = request.args.get('search', '')
|
||||||
local_remote = request.args.get('local_remote', '')
|
local_remote = request.args.get('local_remote', '')
|
||||||
|
sort_by = request.args.get('sort_by', 'last_seen DESC')
|
||||||
|
last_seen = request.args.get('last_seen', 0, type=int)
|
||||||
|
|
||||||
|
sort_by_btn = request.args.get('sort_by_btn', '')
|
||||||
|
if sort_by_btn:
|
||||||
|
return redirect(url_for('admin.admin_users', page=page, search=search, local_remote=local_remote, sort_by=sort_by_btn, last_seen=last_seen))
|
||||||
|
|
||||||
users = User.query.filter_by(deleted=False)
|
users = User.query.filter_by(deleted=False)
|
||||||
if local_remote == 'local':
|
if local_remote == 'local':
|
||||||
users = users.filter_by(ap_id=None)
|
users = users.filter_by(ap_id=None)
|
||||||
if local_remote == 'remote':
|
elif local_remote == 'remote':
|
||||||
users = users.filter(User.ap_id != None)
|
users = users.filter(User.ap_id != None)
|
||||||
if search:
|
if search:
|
||||||
users = users.filter(User.email.ilike(f"%{search}%"))
|
users = users.filter(User.email.ilike(f"%{search}%"))
|
||||||
users = users.order_by(User.user_name).paginate(page=page, per_page=1000, error_out=False)
|
if last_seen > 0:
|
||||||
|
users = users.filter(User.last_seen > utcnow() - timedelta(days=last_seen))
|
||||||
|
users = users.order_by(text('"user".' + sort_by))
|
||||||
|
users = users.paginate(page=page, per_page=1000, error_out=False)
|
||||||
|
|
||||||
next_url = url_for('admin.admin_users', page=users.next_num) if users.has_next else None
|
next_url = url_for('admin.admin_users', page=users.next_num, search=search, local_remote=local_remote, sort_by=sort_by, last_seen=last_seen) if users.has_next else None
|
||||||
prev_url = url_for('admin.admin_users', page=users.prev_num) if users.has_prev and page != 1 else None
|
prev_url = url_for('admin.admin_users', page=users.prev_num, search=search, local_remote=local_remote, sort_by=sort_by, last_seen=last_seen) if users.has_prev and page != 1 else None
|
||||||
|
|
||||||
return render_template('admin/users.html', title=_('Users'), next_url=next_url, prev_url=prev_url, users=users,
|
return render_template('admin/users.html', title=_('Users'), next_url=next_url, prev_url=prev_url, users=users,
|
||||||
local_remote=local_remote, search=search,
|
local_remote=local_remote, search=search, sort_by=sort_by, last_seen=last_seen,
|
||||||
moderating_communities=moderating_communities(current_user.get_id()),
|
moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
menu_topics=menu_topics(),
|
menu_topics=menu_topics(),
|
||||||
|
|
|
@ -11,40 +11,84 @@
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<h1>{{ _('Users') }}</h1>
|
<h1>{{ _('Users') }}</h1>
|
||||||
<a class="btn btn-primary" href="{{ url_for('admin.admin_users_add') }}" style="float: right;">{{ _('Add local user') }}</a>
|
<a class="btn btn-primary" href="{{ url_for('admin.admin_users_add') }}" style="float: right;">{{ _('Add local user') }}</a>
|
||||||
<form method="get">
|
<form id="searchUsers" method="get">
|
||||||
<input type="search" name="search" value="{{ search }}">
|
<div>
|
||||||
<input type="radio" name="local_remote" value="local" id="local_remote_local" {{ 'checked' if local_remote == 'local' }}><label for="local_remote_local"> Local</label>
|
<input type="search" name="search" placeholder="{{ _('Search') }}" value="{{ search }}">
|
||||||
<input type="radio" name="local_remote" value="remote" id="local_remote_remote" {{ 'checked' if local_remote == 'remote' }}><label for="local_remote_remote"> Remote</label>
|
<input type="submit" name="submit_search" value="{{ _('Search') }}" class="btn btn-primary">
|
||||||
<input type="submit" name="submit" value="Search" class="btn btn-primary">
|
</div>
|
||||||
|
<div style="display:inline;">
|
||||||
|
<label for="local_remote">Local/Remote: </label>
|
||||||
|
<select name="local_remote" class="form-control-sm submit_on_change">
|
||||||
|
<option value="">All</option>
|
||||||
|
<option value="local" {{ 'selected' if local_remote == 'local' }}>Local</option>
|
||||||
|
<option value="remote" {{ 'selected' if local_remote == 'remote' }}>Remote</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div style="display:inline;">
|
||||||
|
<label for="last_seen">Active: </label>
|
||||||
|
<select name="last_seen" class="form-control-sm submit_on_change">
|
||||||
|
<option value="0">All</option>
|
||||||
|
<option value="7" {{ 'selected' if last_seen == 7 }}>7 days</option>
|
||||||
|
<option value="30" {{ 'selected' if last_seen == 30 }}>30 days</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="sort_by" value="{{ sort_by }}"></button>
|
||||||
</form>
|
</form>
|
||||||
<table class="table table-striped mt-1">
|
<table class="table table-striped mt-1">
|
||||||
<tr>
|
<tr>
|
||||||
<th title="{{ _('Display name.') }}">{{ _('Name') }}</th>
|
<th>
|
||||||
<th title="{{ _('Last seen.') }}">{{ _('Seen') }}</th>
|
<button form="searchUsers" name="sort_by_btn" value="user_name{{' DESC' if sort_by == 'user_name ASC' else ' ASC' }}" class="btn" title="{{ _('Display name.') }}">
|
||||||
<th title="{{ _('Attitude: Percentage of up votes vs. down votes the account made.') }}">{{ _('Attitude') }}</th>
|
{{ _('Name') }}
|
||||||
<th title="{{ _('Reputation: The Karma of the account. Total up votes minus down votes they got.') }}">{{ _('Reputation') }}</th>
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'user_name DESC' }}{{ 'fe fe-chevron-down' if sort_by == 'user_name ASC' }}"></span>
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
<th>{{ _('Banned') }}</th>
|
<th>{{ _('Banned') }}</th>
|
||||||
<th title="{{ _('How often a user has been reported.') }}">{{ _('Reports') }}</th>
|
<th>
|
||||||
|
<button form="searchUsers" name="sort_by_btn" value="reports{{' ASC' if sort_by == 'reports DESC' else ' DESC' }}" class="btn" title="{{ _('How often a user has been reported.') }}">
|
||||||
|
{{ _('Reports') }}
|
||||||
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'reports ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'reports DESC' }}"></span>
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<button form="searchUsers" name="sort_by_btn" value="attitude{{' ASC' if sort_by == 'attitude DESC' else ' DESC' }}" class="btn" title="{{ _('Attitude: Percentage of up votes vs. down votes the account made.') }}">
|
||||||
|
{{ _('Attitude') }}
|
||||||
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'attitude ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'attitude DESC' }}"></span>
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<button form="searchUsers" name="sort_by_btn" value="reputation{{' ASC' if sort_by == 'reputation DESC' else ' DESC' }}" class="btn" title="{{ _('Reputation: The Karma of the account. Total up votes minus down votes they got.') }}">
|
||||||
|
{{ _('Reputation') }}
|
||||||
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'reputation ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'reputation DESC' }}"></span>
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
<button form="searchUsers" name="sort_by_btn" value="last_seen{{' ASC' if sort_by == 'last_seen DESC' else ' DESC' }}" class="btn" title="{{ _('Last seen.') }}">
|
||||||
|
{{ _('Seen') }}
|
||||||
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'last_seen ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'last_seen DESC' }}"></span>
|
||||||
|
</button>
|
||||||
|
</th>
|
||||||
<th>{{ _('Actions') }}</th>
|
<th>{{ _('Actions') }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for user in users.items %}
|
{% for user in users.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ render_username(user, add_domain=False) }}<br />
|
<td>{{ render_username(user, add_domain=False) }}<br />
|
||||||
<a href="/u/{{ user.link() }}">{{ user.user_name }}</a>{% if not user.is_local() %}<wbr />@<a href="{{ user.ap_profile_id }}">{{ user.ap_domain }}</a>{% endif %}</td>
|
<a href="/u/{{ user.link() }}">{{ user.user_name }}</a>{% if not user.is_local() %}<wbr />@<a href="{{ user.ap_profile_id }}">{{ user.ap_domain }}</a>{% endif %}</td>
|
||||||
<td>{% if request.args.get('local_remote', '') == 'local' %}
|
|
||||||
{{ arrow.get(user.last_seen).humanize(locale=locale) }}
|
|
||||||
{% else %}
|
|
||||||
{{ user.last_seen }}
|
|
||||||
{% endif %}
|
|
||||||
</td>
|
|
||||||
<td>{% if user.attitude != 1 %}{{ (user.attitude * 100) | round | int }}%{% endif %}</td>
|
|
||||||
<td>{% if user.reputation %}R {{ user.reputation | round | int }}{% endif %}</td>
|
|
||||||
<td>{{ '<span class="red">Banned</span>'|safe if user.banned }}
|
<td>{{ '<span class="red">Banned</span>'|safe if user.banned }}
|
||||||
{{ '<span class="red">Banned posts</span>'|safe if user.ban_posts }}
|
{{ '<span class="red">Banned posts</span>'|safe if user.ban_posts }}
|
||||||
{{ '<span class="red">Banned comments</span>'|safe if user.ban_comments }}</td>
|
{{ '<span class="red">Banned comments</span>'|safe if user.ban_comments }}</td>
|
||||||
<td>{{ user.reports if user.reports > 0 }} </td>
|
<td>{{ user.reports if user.reports > 0 }} </td>
|
||||||
<td><a href="{{ url_for('admin.admin_user_edit', user_id=user.id) }}">Edit</a> |
|
<td>{% if user.attitude != 1 %}{{ (user.attitude * 100) | round | int }}%{% endif %}</td>
|
||||||
<a href="{{ url_for('admin.admin_user_delete', user_id=user.id) }}" class="confirm_first">Delete</a>
|
<td>{% if user.reputation %}R {{ user.reputation | round | int }}{% endif %}</td>
|
||||||
|
<td><span title="{{ user.last_seen }}">{{ arrow.get(user.last_seen).humanize(locale=locale) }}</span></td>
|
||||||
|
<td><a href="{{ url_for('admin.admin_user_edit', user_id=user.id) }}">Edit</a>,
|
||||||
|
<a href="{{ url_for('admin.admin_user_delete', user_id=user.id) }}" class="confirm_first">Delete</a>,
|
||||||
|
<br />
|
||||||
|
{% if user.banned %}
|
||||||
|
<a href="{{ url_for('user.unban_profile', actor=user.link()) }}" class="confirm_first">Ban</a>,
|
||||||
|
{% else %}
|
||||||
|
<a href="{{ url_for('user.ban_profile', actor=user.link()) }}" class="confirm_first">Ban</a>,
|
||||||
|
{% endif %}
|
||||||
|
<a href="{{ url_for('user.ban_purge_profile', actor=user.link()) }}" class="confirm_first">Purge</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue