From patchwork Sat Sep 29 21:26:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 976716 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42N1pZ51kWz9s1x for ; Sun, 30 Sep 2018 07:27:18 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="jqLrJE2O"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42N1pZ2SJszF3Cm for ; Sun, 30 Sep 2018 07:27:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="jqLrJE2O"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.9; helo=relay002.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="jqLrJE2O"; dkim-atps=neutral Received: from relay002.mxroute.com (relay002.mxroute.com [185.234.75.9]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42N1p30ynNzF3Cw for ; Sun, 30 Sep 2018 07:26:50 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay002.mxroute.com (Postfix) with ESMTP id 639263F2AB for ; Sat, 29 Sep 2018 21:26:17 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 4068E3F0F4 for ; Sat, 29 Sep 2018 21:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=vUS/RkjgLwvvTKdgS+HZiioK+0nAyDoroJq4EjDfurk=; b=jqLrJE2ODQVQ6iPCtYQ+JgraHB TDbAGnmkZDHOQ0RhNpVLp4t1foujrlP/Uy1kbC/w9h/AkpVCMrHPLmM3k9JzUUlEbqVXXnXeykb7M 5b+Z4IYylOxmtD6qnrv5fSeHoSjFJa9EJwMY+5jESpxsPo6xq4tVzNqPYSepeVuy+xjgqGLMtINnG hz/Iwv8LQ7wrt2kav9aKNuLyScBiPQFe5E3eOdEYVbYgfHawr1Z9ZaK8q1470T6xzvmsAskmDHs8k ZaXhC2w0xDkxfH/jde0812ySx3I5uRVdKcx8bI4pAfgnPhN/LAT4h+Mll6uBP/PDXujgcfEoueQZO Ux884L9w==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 1/4] filters: Return dictionaries Date: Sat, 29 Sep 2018 22:26:07 +0100 Message-Id: <20180929212610.29905-1-stephen@that.guru> X-Mailer: git-send-email 2.17.1 X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This makes it a little easier to figure out what filters are active and will be used in a future patch. Signed-off-by: Stephen Finucane --- v2: - Return ordered dictionaries instead of dictionaries --- patchwork/filters.py | 13 ++++++++----- patchwork/templates/patchwork/filters.html | 2 +- patchwork/views/__init__.py | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/patchwork/filters.py b/patchwork/filters.py index 6cfe41c9..dd7b00db 100644 --- a/patchwork/filters.py +++ b/patchwork/filters.py @@ -3,6 +3,8 @@ # # SPDX-License-Identifier: GPL-2.0-or-later +import collections + from django.contrib.auth.models import User from django.utils.html import escape from django.utils.safestring import mark_safe @@ -443,7 +445,7 @@ class Filters: self.project = project def filter_conditions(self): - kwargs = {} + kwargs = collections.OrderedDict() for f in self._filters: if f.applied: kwargs.update(f.kwargs()) @@ -456,11 +458,11 @@ class Filters: return queryset.filter(**kwargs) def params(self): - return [(f.param, f.key()) for f in self._filters - if f.key() is not None] + return collections.OrderedDict([ + (f.param, f.key()) for f in self._filters if f.key() is not None]) def querystring(self, remove=None): - params = dict(self.params()) + params = self.params() for (k, v) in self.values.items(): if k not in params: @@ -481,7 +483,8 @@ class Filters: return self.querystring(filter) def applied_filters(self): - return [x for x in self._filters if x.applied] + return collections.OrderedDict([ + (x.param, x) for x in self._filters if x.applied]) def available_filters(self): return self._filters diff --git a/patchwork/templates/patchwork/filters.html b/patchwork/templates/patchwork/filters.html index 5331ac85..e760310b 100644 --- a/patchwork/templates/patchwork/filters.html +++ b/patchwork/templates/patchwork/filters.html @@ -130,7 +130,7 @@ $(document).ready(function() {
Show patches with: {% if filters.applied_filters %} - {% for filter in filters.applied_filters %} + {% for filter in filters.applied_filters.values %} {{ filter.name }} = {{ filter.condition }} {% if not filter.forced %} X-Patchwork-Id: 976717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42N1q05cNwz9s1x for ; Sun, 30 Sep 2018 07:27:40 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="Ve3U+z4e"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42N1q03kwtzF3Dk for ; Sun, 30 Sep 2018 07:27:40 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="Ve3U+z4e"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.9; helo=relay002.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="Ve3U+z4e"; dkim-atps=neutral Received: from relay002.mxroute.com (relay002.mxroute.com [185.234.75.9]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42N1p319DbzF3D6 for ; Sun, 30 Sep 2018 07:26:50 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay002.mxroute.com (Postfix) with ESMTP id F41133F2A9; Sat, 29 Sep 2018 21:26:17 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id BF6B03F0F4; Sat, 29 Sep 2018 21:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lPkIYDGkA2fyr9rdlmgVCc91Fquzu+A5DXicAOQFK2U=; b=Ve3U+z4ehFKyDfozZVVcxyMyrz wYC05HT5yjMsBjq22KuWFu5fMtiu060SpYJQbkoUtSBCORBG3g/uk4T1mbwwhmewysuNfLWVm+n0a H3fsvCVUMU8/hBbQERJrDPYnAQe2HrJrJ+MfKEgbfN+QG3ak3jCihXev/Eah+olf24ovCae2M6yYi TjXhpOssScvfBR+4nle6L9CSgEjKw627/HdfE54iCBWWw3NFfxhIaaO6H1oUOFoo+MxwrIGZi3pwZ dBj0IZq2GIA0yPN/DZQK6mYC641zbSMC0TLkDR4F9zxrghTBgDDRxIDNqhjhQA/xdOTqN2cc6fvCN xS+UkNaA==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 2/4] filters: Pre-populate delegate, submitter filters Date: Sat, 29 Sep 2018 22:26:08 +0100 Message-Id: <20180929212610.29905-2-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929212610.29905-1-stephen@that.guru> References: <20180929212610.29905-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Monjalon MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This appears to have got lost in the transition to 'selectize.js'. In brief, this will ensure that a previously selected delegate or submitter is still enabled post-filtering. For more information, see [1]. [1] https://stackoverflow.com/a/45124779 Signed-off-by: Stephen Finucane Cc: Thomas Monjalon Closes: #78 --- v2: - Handle non-specific searches --- patchwork/templates/patchwork/filters.html | 71 +++++++++------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/patchwork/templates/patchwork/filters.html b/patchwork/templates/patchwork/filters.html index e760310b..9b0c4cb2 100644 --- a/patchwork/templates/patchwork/filters.html +++ b/patchwork/templates/patchwork/filters.html @@ -16,8 +16,6 @@ function filter_click() form.style['display'] = 'block'; filterform_displayed = true; } - - } Selectize.define('enter_key_submit', function (options) { @@ -39,9 +37,6 @@ Selectize.define('enter_key_submit', function (options) { $(document).ready(function() { $('#submitter_input').selectize({ - valueField: 'pk', - labelField: 'name', - searchField: ['name', 'email'], plugins: ['enter_key_submit'], maxItems: 1, persist: false, @@ -52,43 +47,37 @@ $(document).ready(function() { this.$input.closest('form').submit(); }, this); }, - render: { - option: function(item, escape) { - if (item.name) - return '
' + escape(item.name) + ' <' + - escape(item.email) + '>' + '
'; - return '
' + escape(item.email) + '
'; +{% if "submitter" in filters.applied_filters %} +{% with submitter_filter=filters.applied_filters.submitter %} + options: [ + { + value: "{{ submitter_filter.key }}", + text: "{{ submitter_filter.condition }}", }, - item: function(item, escape) { - if (item.name) - return '
' + escape(item.name) + '
'; - return '
' + escape(item.email) + '
'; - } - }, + ], + items: ["{{ submitter_filter.key }}"], +{% endwith %} +{% endif %} load: function(query, callback) { if (query.length < 4) return callback(); req = $.ajax({ - url: '{% url 'api-submitters' %}?q=' + - encodeURIComponent(query) + '&l=10', + url: "{% url 'api-submitters' %}", + data: {q: query, l: 10}, error: function() { callback(); }, success: function(res) { - callback(res); + callback($.map(res, function (obj) { + return {value: obj.pk, text: `${obj.name} <${obj.email}>`}; + })); } }); } }); -}); - -$(document).ready(function() { $('#delegate_input').selectize({ - valueField: 'pk', - labelField: 'name', - searchField: ['name'], plugins: ['enter_key_submit'], maxItems: 1, persist: false, @@ -99,26 +88,28 @@ $(document).ready(function() { this.$input.closest('form').submit(); }, this); }, - render: { - option: function(item, escape) { - if (item.email) - return '
' + escape(item.name) + ' <' + - escape(item.email) + '>' + '
'; - return '
' + escape(item.name) + '
'; +{% if "delegate" in filters.applied_filters %} +{% with delegate_filter=filters.applied_filters.delegate %} + options: [ + { + value: "{{ delegate_filter.key }}", + text: "{{ delegate_filter.condition }}", }, - item: function(item, escape) { - return '
' + escape(item.name) + '
'; - } - }, + ], + items: ["{{ delegate_filter.key }}"], +{% endwith %} +{% endif %} load: function(query, callback) { req = $.ajax({ - url: '{% url 'api-delegates' %}?q=' + - encodeURIComponent(query) + '&l=10', + url: "{% url 'api-delegates' %}", + data: {q: query, l: 10}, error: function() { callback(); }, success: function(res) { - callback(res); + callback($.map(res, function (obj) { + return {value: obj.pk, text: obj.name}; + })); } }); } @@ -167,5 +158,3 @@ $(document).ready(function() {
- - From patchwork Sat Sep 29 21:26:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 976719 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42N1qp3p78z9s1x for ; Sun, 30 Sep 2018 07:28:22 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="OdTSEOll"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42N1qp2C3kzF3D6 for ; Sun, 30 Sep 2018 07:28:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="OdTSEOll"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.7; helo=relay-direct7.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="OdTSEOll"; dkim-atps=neutral Received: from relay-direct7.mxroute.com (relay-direct7.mxroute.com [185.234.75.7]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42N1p41kKrzF3Cl for ; Sun, 30 Sep 2018 07:26:51 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay-direct7.mxroute.com (Postfix) with ESMTP id 97E903F368 for ; Sat, 29 Sep 2018 21:26:18 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id 7D5683F0F4 for ; Sat, 29 Sep 2018 21:26:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ov5vRaxwCvtJjYqu58reiB+cAPhBSuXoPGFQMrfcKKk=; b=OdTSEOllDI+UimW1DlWwIvrij7 n9Y+iQ9Jpmyzw1pzwx5RQa4Wm8f/Z+Q4l23DTojOrIOKvcWOaueftWcIXf2iOdsiTFtoM9h0cWvRh 2rYWvGWlLWXBzu5czN3lGnSNC2fPO2vAHyXWZMl33cBB9xi1DmqiEXGtU7AxQ8vA4j/GvWNJA/lJ3 SDpS4mYHm/bWG5+OQx9athxcVACe0250Ejxr9IkMIotubbwpugHntRlyfSVCTsU4z+ODha9UhqRVl xuyixscOQhbe2TbOoww8eC7wfLi1x3cpEMqJv61CncppN49XSL991NV4/c1ykwSPyTwOYJTIeYMKP 8N+VXrZw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 3/4] filters: Rework code Date: Sat, 29 Sep 2018 22:26:09 +0100 Message-Id: <20180929212610.29905-3-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929212610.29905-1-stephen@that.guru> References: <20180929212610.29905-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Make extensive use of properties, remove dead code, add documentation and generally clean this whole thing up. Signed-off-by: Stephen Finucane --- patchwork/filters.py | 372 ++++++++++++++++-------------- patchwork/templatetags/listurl.py | 4 +- patchwork/views/__init__.py | 2 +- patchwork/views/bundle.py | 2 +- 4 files changed, 208 insertions(+), 172 deletions(-) diff --git a/patchwork/filters.py b/patchwork/filters.py index dd7b00db..99003072 100644 --- a/patchwork/filters.py +++ b/patchwork/filters.py @@ -17,25 +17,42 @@ from patchwork.models import State class Filter(object): + #: The 'name' of the filter, to be displayed in the filter UI. + name = None + #: The querystring parameter to filter on. + param = None def __init__(self, filters): self.filters = filters self.applied = False - self.forced = False - - def name(self): - """The 'name' of the filter, to be displayed in the filter UI""" - return self.name + @property def condition(self): """The current condition of the filter, to be displayed in the filter UI""" - return self.key + raise NotImplementedError + @property def key(self): """The key for this filter, to appear in the querystring. A key of None will remove the param=key pair from the querystring.""" - return None + raise NotImplementedError + + @key.setter + def key(self, key): + raise NotImplementedError + + @property + def url_without_me(self): + return self.filters.querystring_without_filter(self) + + @property + def kwargs(self): + raise NotImplementedError + + @property + def form(self): + raise NotImplementedError def set_status(self, *kwargs): """Views can call this to force a specific filter status. For example, @@ -43,42 +60,37 @@ class Filter(object): that user's delegated patches""" pass - def _set_key(self, key): - raise NotImplementedError - def parse(self, values): if self.param not in values: return - self._set_key(values[self.param]) - - def url_without_me(self): - return self.filters.querystring_without_filter(self) - - def form_function(self): - return 'function(form) { return "unimplemented" }' - - def form(self): - if self.forced: - return mark_safe('%s' % ( - self.param, self.condition())) - return self._form() - - def kwargs(self): - return {} + self.key = values[self.param] def __str__(self): - return '%s: %s' % (self.name, self.kwargs()) + return '%s: %s' % (self.name, self.kwargs) class SeriesFilter(Filter): - param = 'series' name = 'Series' + param = 'series' def __init__(self, filters): super(SeriesFilter, self).__init__(filters) self.series = None - def _set_key(self, key): + @property + def condition(self): + if self.series: + return self.series.name + return '' + + @property + def key(self): + if self.series: + return self.series.id + return + + @key.setter + def key(self, key): self.series = None key = key.strip() @@ -92,36 +104,43 @@ class SeriesFilter(Filter): self.applied = True + @property def kwargs(self): if self.series: return {'series': self.series} return {} - def condition(self): - if self.series: - return self.series.name - return '' - - def _form(self): + @property + def form(self): return mark_safe(('')) - def key(self): - if self.series: - return self.series.id - return - class SubmitterFilter(Filter): + name = 'Submitter' param = 'submitter' def __init__(self, filters): super(SubmitterFilter, self).__init__(filters) - self.name = 'Submitter' self.person = None self.person_match = None - def _set_key(self, key): + @property + def condition(self): + if self.person: + return self.person.name + elif self.person_match: + return self.person_match + return '' + + @property + def key(self): + if self.person: + return self.person.id + return self.person_match + + @key.setter + def key(self, key): self.person = None self.person_match = None @@ -144,6 +163,7 @@ class SubmitterFilter(Filter): self.person_match = key self.applied = True + @property def kwargs(self): if self.person: user = self.person.user @@ -156,35 +176,41 @@ class SubmitterFilter(Filter): return {} - def condition(self): - if self.person: - return self.person.name - elif self.person_match: - return self.person_match - return '' - - def _form(self): + @property + def form(self): return mark_safe(('')) - def key(self): - if self.person: - return self.person.id - return self.person_match - class StateFilter(Filter): + name = 'State' param = 'state' any_key = '*' action_req_str = 'Action Required' def __init__(self, filters): super(StateFilter, self).__init__(filters) - self.name = 'State' self.state = None + # The state filter is enabled by default (to hide patches that don't + # require action) self.applied = True - def _set_key(self, key): + @property + def condition(self): + if self.state: + return self.state.name + return self.action_req_str + + @property + def key(self): + if self.state is not None: + return self.state.id + if not self.applied: + return '*' + return None + + @key.setter + def key(self, key): self.state = None if key == self.any_key: @@ -198,27 +224,25 @@ class StateFilter(Filter): self.applied = True + @property + def url_without_me(self): + # Because the filter is enabled by default, we need to add something to + # the querystring if we disable it + qs = self.filters.querystring_without_filter(self) + if qs != '?': + qs += '&' + return qs + '%s=%s' % (self.param, self.any_key) + + @property def kwargs(self): if self.state is not None: return {'state': self.state} - else: - return {'state__in': - State.objects.filter(action_required=True) - .values('pk').query} - - def condition(self): - if self.state: - return self.state.name - return self.action_req_str - def key(self): - if self.state is not None: - return self.state.id - if not self.applied: - return '*' - return None + return {'state__in': State.objects.filter( + action_required=True).values('pk').query} - def _form(self): + @property + def form(self): out = '' return mark_safe(out) - def form_function(self): - return 'function(form) { return form.x.value }' - - def url_without_me(self): - qs = self.filters.querystring_without_filter(self) - if qs != '?': - qs += '&' - return qs + '%s=%s' % (self.param, self.any_key) - class SearchFilter(Filter): + name = 'Search' param = 'q' def __init__(self, filters): super(SearchFilter, self).__init__(filters) - self.name = 'Search' - self.param = 'q' self.search = None - def _set_key(self, key): + @property + def condition(self): + return self.search + + @property + def key(self): + return self.search + + @key.setter + def key(self, key): key = key.strip() if not key: return @@ -269,46 +292,53 @@ class SearchFilter(Filter): self.search = key self.applied = True + @property def kwargs(self): return {'name__icontains': self.search} - def condition(self): - return self.search - - def key(self): - return self.search - - def _form(self): + @property + def form(self): value = '' if self.search: value = escape(self.search) return mark_safe('' % (self.param, value)) - def form_function(self): - return mark_safe('function(form) { return form.x.value }') - class ArchiveFilter(Filter): + name = 'Archived' param = 'archive' + param_map = { + True: 'true', + False: '', + None: 'both' + } + description_map = { + True: 'Yes', + False: 'No', + None: 'Both' + } def __init__(self, filters): super(ArchiveFilter, self).__init__(filters) - self.name = 'Archived' self.archive_state = False + # The archive filter is enabled by default (to hide archived patches) self.applied = True - self.param_map = { - True: 'true', - False: '', - None: 'both' - } - self.description_map = { - True: 'Yes', - False: 'No', - None: 'Both' - } - - def _set_key(self, key): + + @property + def condition(self): + return self.description_map[self.archive_state] + + @property + def key(self): + # NOTE(stephenfin): this is a shortcut to ensure we don't both + # including the 'archive' querystring filter for the default case + if self.archive_state is False: + return None + return self.param_map[self.archive_state] + + @key.setter + def key(self, key): self.archive_state = False self.applied = True for (k, v) in self.param_map.items(): @@ -317,22 +347,23 @@ class ArchiveFilter(Filter): if self.archive_state is None: self.applied = False + @property + def url_without_me(self): + # As with StateFilter, because this filter is enabled by default, + # disabling it will actually add something to the querystring + qs = self.filters.querystring_without_filter(self) + if qs != '?': + qs += '&' + return qs + 'archive=both' + + @property def kwargs(self): if self.archive_state is None: return {} return {'archived': self.archive_state} - def condition(self): - return self.description_map[self.archive_state] - - def key(self): - # NOTE(stephenfin): this is a shortcut to ensure we don't both - # including the 'archive' querystring filter for the default case - if self.archive_state is False: - return None - return self.param_map[self.archive_state] - - def _form(self): + @property + def form(self): s = '' for b in [False, True, None]: label = self.description_map[b] @@ -350,24 +381,34 @@ class ArchiveFilter(Filter): } return mark_safe(s) - def url_without_me(self): - qs = self.filters.querystring_without_filter(self) - if qs != '?': - qs += '&' - return qs + 'archive=both' - class DelegateFilter(Filter): + name = 'Delegate' param = 'delegate' - AnyDelegate = 1 + ANY_DELEGATE = object() def __init__(self, filters): super(DelegateFilter, self).__init__(filters) - self.name = 'Delegate' self.delegate = None self.delegate_match = None + self.forced = False + + @property + def condition(self): + if self.delegate: + return str(self.delegate) + elif self.delegate_match: + return self.delegate_match + return '' - def _set_key(self, key): + @property + def key(self): + if self.delegate: + return self.delegate.id + return self.delegate_match + + @key.setter + def key(self, key): self.delegate = None self.delegate_match = None @@ -390,79 +431,81 @@ class DelegateFilter(Filter): self.delegate_match = key self.applied = True + @property def kwargs(self): if self.delegate: return {'delegate': self.delegate} if self.delegate_match: return {'delegate__username__icontains': self.delegate_match} + return {} - def condition(self): - if self.delegate: - return str(self.delegate) - elif self.delegate_match: - return self.delegate_match - return '' + @property + def form(self): + if self.forced: + return mark_safe('%s' % ( + self.param, self.condition)) - def _form(self): return mark_safe('') - def key(self): - if self.delegate: - return self.delegate.id - return self.delegate_match - def set_status(self, *args, **kwargs): if 'delegate' in kwargs: self.applied = self.forced = True self.delegate = kwargs['delegate'] - if self.AnyDelegate in args: + + if self.ANY_DELEGATE in args: self.applied = False self.forced = True -filterclasses = [SeriesFilter, - SubmitterFilter, - StateFilter, - SearchFilter, - ArchiveFilter, - DelegateFilter] +FILTERS = [ + SeriesFilter, + SubmitterFilter, + StateFilter, + SearchFilter, + ArchiveFilter, + DelegateFilter +] class Filters: def __init__(self, request): - self._filters = [c(self) for c in filterclasses] + self._filters = [c(self) for c in FILTERS] self.values = request.GET - self.project = None for f in self._filters: f.parse(self.values) - def set_project(self, project): - self.project = project + @property + def params(self): + return collections.OrderedDict([ + (f.param, f.key) for f in self._filters if f.key is not None]) + + @property + def applied_filters(self): + return collections.OrderedDict([ + (x.param, x) for x in self._filters if x.applied]) + + @property + def available_filters(self): + return self._filters - def filter_conditions(self): + def apply(self, queryset): kwargs = collections.OrderedDict() for f in self._filters: if f.applied: - kwargs.update(f.kwargs()) - return kwargs + kwargs.update(f.kwargs) - def apply(self, queryset): - kwargs = self.filter_conditions() if not kwargs: return queryset - return queryset.filter(**kwargs) - def params(self): - return collections.OrderedDict([ - (f.param, f.key()) for f in self._filters if f.key() is not None]) + return queryset.filter(**kwargs) def querystring(self, remove=None): - params = self.params() + params = self.params for (k, v) in self.values.items(): if k not in params: @@ -482,13 +525,6 @@ class Filters: def querystring_without_filter(self, filter): return self.querystring(filter) - def applied_filters(self): - return collections.OrderedDict([ - (x.param, x) for x in self._filters if x.applied]) - - def available_filters(self): - return self._filters - def set_status(self, filterclass, *args, **kwargs): for f in self._filters: if isinstance(f, filterclass): diff --git a/patchwork/templatetags/listurl.py b/patchwork/templatetags/listurl.py index 62ccd96b..3d5388d2 100644 --- a/patchwork/templatetags/listurl.py +++ b/patchwork/templatetags/listurl.py @@ -10,13 +10,13 @@ from django.urls import NoReverseMatch from django.utils.encoding import smart_str from django.utils.html import escape -from patchwork.filters import filterclasses +from patchwork.filters import FILTERS register = template.Library() # params to preserve across views -list_params = [c.param for c in filterclasses] + ['order', 'page'] +list_params = [c.param for c in FILTERS] + ['order', 'page'] class ListURLNode(template.defaulttags.URLNode): diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py index cce00d67..178b3d41 100644 --- a/patchwork/views/__init__.py +++ b/patchwork/views/__init__.py @@ -180,7 +180,7 @@ def generic_list(request, project, view, view_args=None, filter_settings=None, # pagination - params = filters.params() + params = filters.params for param in ['order', 'page']: data = {} if request.method == 'GET': diff --git a/patchwork/views/bundle.py b/patchwork/views/bundle.py index 1068c6a9..3e227f4c 100644 --- a/patchwork/views/bundle.py +++ b/patchwork/views/bundle.py @@ -77,7 +77,7 @@ def bundle_list(request, project_id=None): def bundle_detail(request, username, bundlename): bundle = get_object_or_404(Bundle, owner__username=username, name=bundlename) - filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)] + filter_settings = [(DelegateFilter, DelegateFilter.ANY_DELEGATE)] is_owner = request.user == bundle.owner From patchwork Sat Sep 29 21:26:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 976718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42N1qP61QSz9s1x for ; Sun, 30 Sep 2018 07:28:01 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="WDZaGoxb"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42N1qP4S39zF3Dk for ; Sun, 30 Sep 2018 07:28:01 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="WDZaGoxb"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=that.guru (client-ip=185.234.75.7; helo=relay-direct7.mxroute.com; envelope-from=stephen@that.guru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=that.guru Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="WDZaGoxb"; dkim-atps=neutral Received: from relay-direct7.mxroute.com (relay-direct7.mxroute.com [185.234.75.7]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42N1p41kHjzF3Cg for ; Sun, 30 Sep 2018 07:26:51 +1000 (AEST) Received: from filter002.mxroute.com (unknown [185.133.192.179]) by relay-direct7.mxroute.com (Postfix) with ESMTP id DC4FF3F369 for ; Sat, 29 Sep 2018 21:26:18 +0000 (UTC) Received: from one.mxroute.com (one.mxroute.com [195.201.59.211]) by filter002.mxroute.com (Postfix) with ESMTPS id C5B733F0F4 for ; Sat, 29 Sep 2018 21:26:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=TkXW+Pn4eaT8sPD1Hpaa4Ubq3GpDDkkrsn8X6Qbe7aQ=; b=WDZaGoxbqSRHXkhpScSYmJ2Yah tVUOa6ZqltAVmmwy/i1QBllp8bfIYIAxoQ0F0u29eyM4sz2fBa1e6EgR3nveYVqTI0irhqLKWxSTy o13sycMvxrQoXxQ6hvk7EgbGu/s61L1EhKvhKW2TnlEje5/sx7c3Yo/jpWNtTNfZ99jHxc2SEPTvZ BxrMzCzdFvbzogCH53zK3ordit4W84DIw2MIyts3TMkS1X8h6EARd6C7XBfVJEyQZOh3ZGM75TBP+ eh6iSLRc8es07BkCBwFGH+1RGopm6TgcrN8AHSH3yUseJ62cGlvyo8aziocS5+BiI5zx8ARdXv7Ez WCakUa3w==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v2 4/4] templates: Don't show forced filters Date: Sat, 29 Sep 2018 22:26:10 +0100 Message-Id: <20180929212610.29905-4-stephen@that.guru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180929212610.29905-1-stephen@that.guru> References: <20180929212610.29905-1-stephen@that.guru> X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" No point in showing a filter that you can't change. Signed-off-by: Stephen Finucane --- patchwork/templates/patchwork/filters.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/patchwork/templates/patchwork/filters.html b/patchwork/templates/patchwork/filters.html index 9b0c4cb2..41ed2c26 100644 --- a/patchwork/templates/patchwork/filters.html +++ b/patchwork/templates/patchwork/filters.html @@ -143,12 +143,14 @@ $(document).ready(function() {