Skip to content

Commit 895b895

Browse files
committed
Add sorting to liaison list view. Fixes ietf-tools#383
- Legacy-Id: 2543
1 parent a9cab1e commit 895b895

5 files changed

Lines changed: 55 additions & 3 deletions

File tree

ietf/liaisons/views.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,22 @@ def liaison_list(request):
9696
approval_codes = IETFHM.get_all_can_approve_codes(person)
9797
can_approve = LiaisonDetail.objects.filter(approval__isnull=False, approval__approved=False, from_raw_code__in=approval_codes).count()
9898

99-
public_liaisons = LiaisonDetail.objects.filter(Q(approval__isnull=True)|Q(approval__approved=True)).order_by("-submitted_date")
99+
order = request.GET.get('order_by', 'submitted_date')
100+
plain_order = order
101+
reverse_order = order.startswith('-')
102+
if reverse_order:
103+
plain_order = order[1:]
104+
if plain_order not in ('submitted_date', 'deadline_date', 'title', 'to_body', 'from_raw_body'):
105+
order = 'submitted_date'
106+
reverse_order = True
107+
plain_order = 'submitted_date'
108+
elif plain_order in ('submitted_date', 'deadline_date'):
109+
# Reverse order for date fields, humans find it more natural
110+
if reverse_order:
111+
order = plain_order
112+
else:
113+
order = '-%s' % plain_order
114+
public_liaisons = LiaisonDetail.objects.filter(Q(approval__isnull=True)|Q(approval__approved=True)).order_by(order)
100115

101116
return object_list(request, public_liaisons,
102117
allow_empty=True,
@@ -105,7 +120,8 @@ def liaison_list(request):
105120
'can_approve': can_approve,
106121
'can_edit': can_edit,
107122
'can_send_incoming': can_send_incoming,
108-
'can_send_outgoing': can_send_outgoing},
123+
'can_send_outgoing': can_send_outgoing,
124+
plain_order: not reverse_order and '-' or None},
109125
)
110126

111127

ietf/templates/liaisons/liaisondetail_list.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{% block title %}Liaison Statements{% endblock %}
44

55
{% block pagehead %}
6+
<link rel="stylesheet" type="text/css" href="/css/liaisons.css"></link>
67
<link rel="alternate" type="application/atom+xml" href="/feed/liaison/recent/" />
78
{% endblock %}
89

@@ -23,7 +24,23 @@ <h1>Liaison Statements</h1>
2324
{% endblock %}
2425

2526
<table class="ietf-table" width="100%">
26-
<tr><th width="9%">Date</th><th width="20%">From</th><th width="20%">To</th><th width="50%">Title</th></tr>
27+
<tr>
28+
<th width="9%" class="orderField orderField{{ submitted_date|yesno:"Active,Inactive,Reversed" }}">
29+
<a href="?order_by={{ submitted_date|default_if_none:"" }}submitted_date">Date</a>
30+
</th>
31+
<th width="15%" class="orderField orderField{{ from_raw_body|yesno:"Active,Inactive,Reversed" }}">
32+
<a href="?order_by={{ from_raw_body|default_if_none:"" }}from_raw_body">From</a>
33+
</th>
34+
<th width="15%" class="orderField orderField{{ to_body|yesno:"Active,Inactive,Reversed" }}">
35+
<a href="?order_by={{ to_body|default_if_none:"" }}to_body">To</a>
36+
</th>
37+
<th width="9%" class="orderField orderField{{ deadline_date|yesno:"Active,Inactive,Reversed" }}">
38+
<a href="?order_by={{ deadline_date|default_if_none:"" }}deadline_date">Deadline</a>
39+
</th>
40+
<th width="50%" class="orderField orderField{{ title|yesno:"Active,Inactive,Reversed" }}">
41+
<a href="?order_by={{ title|default_if_none:"" }}title">Title</a>
42+
</th>
43+
</tr>
2744

2845
{% for liaison in object_list %}
2946
<tr class="{% cycle oddrow,evenrow %}">
@@ -40,6 +57,9 @@ <h1>Liaison Statements</h1>
4057
{{ liaison.to_body|escape }}
4158
{% endif %}
4259
</td>
60+
<td>
61+
{{ liaison.deadline_date|default:"--" }}
62+
</td>
4363
<td>
4464
{% if liaison.by_secretariat %}
4565
{% for file in liaison.uploads_set.all %}

static/css/liaisons.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,19 @@ span.fieldRequired {
9393
font-size: 1.2em;
9494
background-color: #ffdd88;
9595
}
96+
97+
th.orderField a {
98+
text-decoration: none;
99+
color: white;
100+
display: block;
101+
}
102+
103+
th.orderFieldReversed a {
104+
background: #2647A0 url(/images/arrow-down.gif) no-repeat left center;
105+
padding-left: 20px;
106+
}
107+
108+
th.orderFieldActive a {
109+
background: #2647A0 url(/images/arrow-up.gif) no-repeat left center;
110+
padding-left: 20px;
111+
}

static/images/arrow-down.gif

80 Bytes
Loading

static/images/arrow-up.gif

79 Bytes
Loading

0 commit comments

Comments
 (0)