MT#55988 buildinfo: filter by duration in secs

Change-Id: Ic35a8b42b51b06dffb9219dc1eee98355a382f87
master
Victor Seva 2 years ago
parent 036ec4983f
commit a47db4b2ee

@ -12,6 +12,8 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
import re
from django.contrib import admin
from django.utils.html import format_html
from import_export import resources
@ -25,16 +27,34 @@ class BuildInfoResource(resources.ModelResource):
model = models.BuildInfo
class DurationListFilter(admin.SimpleListFilter):
title = "duration"
parameter_name = "range"
def lookups(self, request, model_admin):
vals = [120, 60, 30, 15]
return [(f"{val}s", f"higher than {val} secs") for val in vals]
def queryset(self, request, queryset):
if self.value():
matched = re.match(r"(\d+)s", self.value())
if matched:
value = int(matched.group(1)) * 1000
return queryset.filter(duration__gte=value)
@admin.register(models.BuildInfo)
class BuildInfoAdmin(ImportExportModelAdmin):
resource_class = BuildInfoResource
list_filter = (
DurationListFilter,
"param_release",
"projectname",
"param_distribution",
"builton",
)
readonly_fields = ("jenkins_url",)
readonly_fields = ["jenkins_url"]
ordering = ["-duration"]
def jenkins_url(self, obj):
return format_html("<a href='{url}'>{url}</a>", url=obj.jenkins_url)

Loading…
Cancel
Save