diff options
author | Magnus Hagander | 2013-08-24 13:00:04 +0000 |
---|---|---|
committer | Magnus Hagander | 2013-08-24 13:00:04 +0000 |
commit | ffc96c0782b8192e777f35b58521ae9462bcfa95 (patch) | |
tree | dd2e7e798bb5164372268c9b1703115bce512259 | |
parent | 79958df61b4b80d1c3826fd296babf6a96cdd431 (diff) |
Add basic sorting
-rw-r--r-- | pgcommitfest/commitfest/forms.py | 3 | ||||
-rw-r--r-- | pgcommitfest/commitfest/static/commitfest/js/commitfest.js | 7 | ||||
-rw-r--r-- | pgcommitfest/commitfest/templates/commitfest.html | 12 | ||||
-rw-r--r-- | pgcommitfest/commitfest/views.py | 21 |
4 files changed, 35 insertions, 8 deletions
diff --git a/pgcommitfest/commitfest/forms.py b/pgcommitfest/commitfest/forms.py index 78219c3..b2ba48e 100644 --- a/pgcommitfest/commitfest/forms.py +++ b/pgcommitfest/commitfest/forms.py @@ -15,10 +15,13 @@ class CommitFestFilterForm(forms.Form): status = forms.ChoiceField(required=False) author = forms.ChoiceField(required=False) reviewer = forms.ChoiceField(required=False) + sortkey = forms.IntegerField(required=False) def __init__(self, cf, *args, **kwargs): super(CommitFestFilterForm, self).__init__(*args, **kwargs) + self.fields['sortkey'].widget = forms.HiddenInput() + c = [(-1, '* All')] + list(PatchOnCommitFest._STATUS_CHOICES) self.fields['status'] = forms.ChoiceField(choices=c, required=False) diff --git a/pgcommitfest/commitfest/static/commitfest/js/commitfest.js b/pgcommitfest/commitfest/static/commitfest/js/commitfest.js index 8f84d8b..c594433 100644 --- a/pgcommitfest/commitfest/static/commitfest/js/commitfest.js +++ b/pgcommitfest/commitfest/static/commitfest/js/commitfest.js @@ -109,3 +109,10 @@ function doAttachThread(cfid, patchid, msgid) { return false; }); } + +function sortpatches(sortby) { + $('#id_sortkey').val(sortby); + $('#filterform').submit(); + + return false; +} diff --git a/pgcommitfest/commitfest/templates/commitfest.html b/pgcommitfest/commitfest/templates/commitfest.html index 90a9855..5d121f8 100644 --- a/pgcommitfest/commitfest/templates/commitfest.html +++ b/pgcommitfest/commitfest/templates/commitfest.html @@ -12,9 +12,9 @@ <table class="table table-condensed"> <thead> <tr> -{%for f in form%} +{%for f in form%}{%if not f.is_hidden%} <td>{{f.label}}</td> -{%endfor%} +{%endif%}{%endfor%} <td></td> </tr> </thead> @@ -44,20 +44,22 @@ <table class="table table-striped table-bordered table-hover table-condensed"> <thead> <tr> - <th>Patch</th> + <th>{%if p.is_open%}<a href="#" style="color:#333333;" onclick="return sortpatches(0);">Patch</a>{%if sortkey = 0%}<div style="float:right;"><i class="icon-arrow-down"></i></div>{%endif%}{%endif%}</th> <th>Status</th> <th>Author</th> <th>Reviewers</th> - <th>Latest activity</th> - <th>Latest mail</th> + <th>{%if p.is_open%}<a href="#" style="color:#333333;" onclick="return sortpatches(1);">Latest activity</a>{%if sortkey = 1%}<div style="float:right;"><i class="icon-arrow-down"></i></div>{%endif%}{%else%}Latest activity{%endif%}</th> + <th>{%if p.is_open%}<a href="#" style="color:#333333;" onclick="return sortpatches(2);">Latest mail</a>{%if sortkey = 2%}<div style="float:right;"><i class="icon-arrow-down"></i></div>{%endif%}{%else%}Latest mail{%endif%}</th> </tr> </thead> <tbody> {%endifchanged%} +{%if grouping%} {%ifchanged p.topic%} <tr><th colspan="6">{{p.topic}}</th></tr> {%endifchanged%} +{%endif%} <tr> <td><a href="{{p.id}}/">{{p}}</a></td> <td><span class="label">{{p.status|patchstatusstring}}</span></td> diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index da779c8..cec486e 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -50,9 +50,22 @@ def commitfest(request, cfid): if request.GET.has_key('text') and request.GET['text'] != '': q = q & Q(name__icontains=request.GET['text']) - # Not sure if this is correct? has_filter = len(q.children) > 0 - if not has_filter and request.GET: + + # Figure out custom ordering + ordering = ['-is_open', 'topic__topic', 'created',] + if request.GET.has_key('sortkey'): + sortkey=int(request.GET['sortkey']) + if sortkey==1: + ordering = ['-is_open', 'modified', 'created',] + elif sortkey==2: + ordering = ['-is_open', 'lastmail', 'created',] + else: + sortkey=0 + else: + sortkey = 0 + + if not has_filter and sortkey==0 and request.GET: # Redirect to get rid of the ugly url return HttpResponseRedirect('/%s/' % cf.id) @@ -61,7 +74,7 @@ def commitfest(request, cfid): 'author_names':"SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_authors cpa ON cpa.user_id=auth_user.id WHERE cpa.patch_id=commitfest_patch.id", 'reviewer_names':"SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_reviewers cpr ON cpr.user_id=auth_user.id WHERE cpr.patch_id=commitfest_patch.id", 'is_open':'commitfest_patchoncommitfest.status IN (%s)' % ','.join([str(x) for x in PatchOnCommitFest.OPEN_STATUSES]), - }).order_by('-is_open', 'topic__topic', 'created') + }).order_by(*ordering) # Generates a fairly expensive query, which we shouldn't do unless # the user is logged in. XXX: Figure out how to avoid doing that.. @@ -73,6 +86,8 @@ def commitfest(request, cfid): 'patches': patches, 'has_filter': has_filter, 'title': 'Commitfest %s' % cf.name, + 'grouping': sortkey==0, + 'sortkey': sortkey, }, context_instance=RequestContext(request)) def patch(request, cfid, patchid): |