From 2ebe8a7f2d1049325ae74e5422efb54c45772108 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 6 Mar 2023 12:38:59 +0100 Subject: [PATCH] MT#55988 buildinfo: add clickable jenkins_url field Change-Id: I3a94aa1c93b03818c40b2cc6800b1507621f1687 --- buildinfo/admin.py | 7 ++++++- buildinfo/models.py | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/buildinfo/admin.py b/buildinfo/admin.py index f35c595..90a13f1 100644 --- a/buildinfo/admin.py +++ b/buildinfo/admin.py @@ -1,4 +1,4 @@ -# Copyright (C) 2022 The Sipwise Team - http://sipwise.com +# Copyright (C) 2022-2023 The Sipwise Team - http://sipwise.com # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . from django.contrib import admin +from django.utils.html import format_html from import_export import resources from import_export.admin import ImportExportModelAdmin @@ -33,3 +34,7 @@ class BuildInfoAdmin(ImportExportModelAdmin): "param_distribution", "builton", ) + readonly_fields = ("jenkins_url",) + + def jenkins_url(self, obj): + return format_html("{url}", url=obj.jenkins_url) diff --git a/buildinfo/models.py b/buildinfo/models.py index 20c9a85..f62ace0 100644 --- a/buildinfo/models.py +++ b/buildinfo/models.py @@ -16,6 +16,7 @@ from typing import Any from django.db import models +from .conf import settings from .utils import datetime from .utils import get_datetime @@ -45,6 +46,11 @@ class BuildInfo(models.Model): param_ppa = models.CharField(max_length=50, null=True, blank=True) objects = BuildInfoManager() + @property + def jenkins_url(self): + base_url = settings.JENKINS_URL + return f"{base_url}/jobs/{self.projectname}/{self.buildnumber}/" + def __str__(self): return ( f"{self.jobname}:{self.buildnumber}:"