From: Magnus Hagander Date: Sat, 24 Aug 2013 13:00:04 +0000 (+0200) Subject: Add basic sorting X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=ffc96c0782b8192e777f35b58521ae9462bcfa95;p=pgcommitfest2.git Add basic sorting --- 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 @@ -{%for f in form%} +{%for f in form%}{%if not f.is_hidden%} -{%endfor%} +{%endif%}{%endfor%} @@ -44,20 +44,22 @@
{{f.label}}
- + - - + + {%endifchanged%} +{%if grouping%} {%ifchanged p.topic%} {%endifchanged%} +{%endif%} 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):
Patch{%if p.is_open%}Patch{%if sortkey = 0%}
{%endif%}{%endif%}
Status Author ReviewersLatest activityLatest mail{%if p.is_open%}Latest activity{%if sortkey = 1%}
{%endif%}{%else%}Latest activity{%endif%}
{%if p.is_open%}Latest mail{%if sortkey = 2%}
{%endif%}{%else%}Latest mail{%endif%}
{{p.topic}}
{{p}} {{p.status|patchstatusstring}}