Add ability to do global searches
authorMagnus Hagander <magnus@hagander.net>
Mon, 14 Jul 2014 16:11:17 +0000 (18:11 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 14 Jul 2014 16:11:17 +0000 (18:11 +0200)
pgcommitfest/commitfest/models.py
pgcommitfest/commitfest/templates/home.html
pgcommitfest/commitfest/templates/patchsearch.html [new file with mode: 0644]
pgcommitfest/commitfest/views.py
pgcommitfest/urls.py

index 39e2d34dad8635b5b846c0335b47671c6723ebdc..284c3d5443842266b91356c0c34c0e7d744085bb 100644 (file)
@@ -168,6 +168,7 @@ class PatchOnCommitFest(models.Model):
 
        class Meta:
                unique_together = (('patch', 'commitfest',),)
+               ordering = ('-commitfest__startdate', )
 
 class PatchHistory(models.Model):
        patch = models.ForeignKey(Patch, blank=False, null=False)
index 522ae0ace81fb173c626d7d3e0c0fe6dac2ab830..461bc2873892dd29a2c0be84957ae62559e7d668 100644 (file)
@@ -10,4 +10,12 @@ The following commitfests exist in the system.
  <li><a href="/{{c.id}}/">{{c}}</a> ({{c.statusstring}})</li>
 {%endfor%}
 </ul>
+<br/>
+<h3>Commands</h3>
+<form method="GET" action="/search/" class="form-inline" role="form">
+  <div class="form-group">
+    <input type="text" class="form-control" id="searchterm" name="searchterm" placeholder="Global search">
+  </div>
+  <button type="submit" class="btn btn-default">Search</button>
+</form>
 {%endblock%}
diff --git a/pgcommitfest/commitfest/templates/patchsearch.html b/pgcommitfest/commitfest/templates/patchsearch.html
new file mode 100644 (file)
index 0000000..4db2949
--- /dev/null
@@ -0,0 +1,28 @@
+{%extends "base.html"%}
+{%load commitfest %}
+{%block contents%}
+
+<table class="table table-striped table-bordered table-hover table-condensed">
+ <thead>
+  <tr>
+   <th>Patch</th>
+   <th>Status</th>
+   <th>Author</th>
+  </tr>
+ </thead>
+ <tbody>
+{%for p in patches %}
+ {%with p.patchoncommitfest_set.all as cfs %}
+  <tr>
+   <td>{%with cfs|first as firstcf%}<a href="/{{firstcf.commitfest_id}}/{{p.id}}/">{{p}}</a>{%endwith%}</td>
+   <td>{%for c in cfs %}
+       <div style="margin-bottom: 3px;">{{c.commitfest}}: <span class="label label-default">{{c.statusstring}}</span></div>
+       {%endfor%}</td>
+   <td>{{p.author_names|default:''}}</td>
+  </tr>
+ {%endwith%}
+{%endfor%}
+ </tbody>
+</table>
+
+{%endblock%}
index a7d7498de67e09bcb9724f3ab35153e8f7eb6983..9abf91e3f1942080f04be421cc5cd187569e8899 100644 (file)
@@ -106,6 +106,20 @@ def commitfest(request, cfid):
                'openpatchids': [p.id for p in patches if p.is_open],
                }, context_instance=RequestContext(request))
 
+def global_search(request):
+       if not request.GET.has_key('searchterm'):
+               print request.GET.keys()
+               return HttpResponseRedirect('/')
+       searchterm = request.GET['searchterm']
+
+       patches = Patch.objects.select_related().filter(name__icontains=searchterm).order_by('created',)
+
+       print patches
+       return render_to_response('patchsearch.html', {
+               'patches': patches,
+               'title': 'Patch search results',
+               }, context_instance=RequestContext(request))
+
 def patch(request, cfid, patchid):
        cf = get_object_or_404(CommitFest, pk=cfid)
        patch = get_object_or_404(Patch.objects.select_related(), pk=patchid, commitfests=cf)
index b9e063c6324378d83bd4992db22a53e57b6520d9..fb32e6751bd3ed9d29da888cb61c1b8c1d1523c1 100644 (file)
@@ -18,6 +18,7 @@ urlpatterns = patterns('',
     url(r'^(\d+)/(\d+)/(comment|review)/', 'commitfest.views.comment'),
     url(r'^(\d+)/send_email/$', 'commitfest.views.send_email'),
     url(r'^(\d+)/\d+/send_email/$', 'commitfest.views.send_email'),
+    url(r'^search/$', 'commitfest.views.global_search'),
     url(r'^ajax/(\w+)/$', 'commitfest.ajax.main'),
 
     url(r'^selectable/', include('selectable.urls')),