From 6264b3856adc9ce42642dab1e13f38499789c968 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Sat, 14 Sep 2019 21:57:47 +0300 Subject: [PATCH] Show TC Executions card when viewing a bug. Refs #699 - [db] add db_index=True to LinkReference.url field - modify TC Executions card to show bugs only when specified. When viewing the Bug page showing the same info again doesn't give us any more additional information but occupies screen space. --- tcms/bugs/migrations/0001_initial.py | 2 ++ tcms/bugs/models.py | 10 ++++++++-- tcms/bugs/static/bugs/js/get.js | 3 +++ tcms/bugs/templates/bugs/get.html | 5 +++++ tcms/bugs/views.py | 11 ++++++++++- .../0003_add_db_index_to_url_field.py | 18 ++++++++++++++++++ tcms/core/contrib/linkreference/models.py | 2 +- tcms/core/models/base.py | 2 +- tcms/templates/include/tc_executions.html | 6 ++++-- tcms/testcases/templates/testcases/get.html | 2 +- 10 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 tcms/core/contrib/linkreference/migrations/0003_add_db_index_to_url_field.py diff --git a/tcms/bugs/migrations/0001_initial.py b/tcms/bugs/migrations/0001_initial.py index 81cc82cba8..a1e2861d6a 100644 --- a/tcms/bugs/migrations/0001_initial.py +++ b/tcms/bugs/migrations/0001_initial.py @@ -2,6 +2,7 @@ from django.conf import settings from django.db import migrations, models +import tcms.core.models.base class Migration(migrations.Migration): @@ -43,5 +44,6 @@ class Migration(migrations.Migration): ('version', models.ForeignKey(on_delete=models.deletion.CASCADE, to='management.Version')), ], + bases=(models.Model, tcms.core.models.base.UrlMixin), ), ] diff --git a/tcms/bugs/models.py b/tcms/bugs/models.py index ed9b8b2775..cb7b5cdb3c 100644 --- a/tcms/bugs/models.py +++ b/tcms/bugs/models.py @@ -2,11 +2,14 @@ # Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html -from django.conf import settings from django.db import models +from django.conf import settings +from django.urls import reverse +from tcms.core.models.base import UrlMixin -class Bug(models.Model): + +class Bug(models.Model, UrlMixin): summary = models.CharField(max_length=255, db_index=True) created_at = models.DateTimeField(auto_now_add=True, db_index=True) @@ -31,3 +34,6 @@ class Bug(models.Model): def __str__(self): return "BUG-%d: %s " % (self.pk, self.summary) + + def _get_absolute_url(self): + return reverse('bugs-get', args=[self.pk, ]) diff --git a/tcms/bugs/static/bugs/js/get.js b/tcms/bugs/static/bugs/js/get.js index a5990857ef..9b15cc53fb 100644 --- a/tcms/bugs/static/bugs/js/get.js +++ b/tcms/bugs/static/bugs/js/get.js @@ -4,4 +4,7 @@ $(document).ready(function() { // bind everything in tags table tagsCard('Bug', object_id, {bugs: object_id}, perm_remove_tag); + + // executions tree view + treeViewBind(); }); diff --git a/tcms/bugs/templates/bugs/get.html b/tcms/bugs/templates/bugs/get.html index a11ba8ffbb..313154d336 100644 --- a/tcms/bugs/templates/bugs/get.html +++ b/tcms/bugs/templates/bugs/get.html @@ -117,7 +117,12 @@

+ +
+
+ {% include 'include/tc_executions.html' %} +
{% get_comment_list for object as comments %} diff --git a/tcms/bugs/views.py b/tcms/bugs/views.py index 147602d3ad..0ae8355af4 100644 --- a/tcms/bugs/views.py +++ b/tcms/bugs/views.py @@ -8,14 +8,15 @@ from django.http import HttpResponseRedirect from django.shortcuts import render from django.utils.decorators import method_decorator -from django.utils.translation import ugettext_lazy as _ from django.views.generic import DetailView from django.views.generic.base import TemplateView from django.views.generic.base import View from tcms.bugs.models import Bug +from tcms.testruns.models import TestExecution from tcms.bugs.forms import NewBugForm, BugCommentForm from tcms.core.helpers.comments import add_comment +from tcms.core.contrib.linkreference.models import LinkReference class Get(DetailView): # pylint: disable=missing-permission-required @@ -27,6 +28,14 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['comment_form'] = BugCommentForm() context['comment_form'].populate(self.object.pk) + + context['executions'] = TestExecution.objects.filter( + pk__in=LinkReference.objects.filter( + is_defect=True, + url=self.object.get_full_url(), + ).values('execution') + ) + return context diff --git a/tcms/core/contrib/linkreference/migrations/0003_add_db_index_to_url_field.py b/tcms/core/contrib/linkreference/migrations/0003_add_db_index_to_url_field.py new file mode 100644 index 0000000000..84f32452b2 --- /dev/null +++ b/tcms/core/contrib/linkreference/migrations/0003_add_db_index_to_url_field.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.5 on 2019-09-14 18:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('linkreference', '0002_update_fields'), + ] + + operations = [ + migrations.AlterField( + model_name='linkreference', + name='url', + field=models.URLField(db_index=True), + ), + ] diff --git a/tcms/core/contrib/linkreference/models.py b/tcms/core/contrib/linkreference/models.py index 5ebde4478f..fbff47f248 100755 --- a/tcms/core/contrib/linkreference/models.py +++ b/tcms/core/contrib/linkreference/models.py @@ -7,7 +7,7 @@ class LinkReference(models.Model): execution = models.ForeignKey('testruns.TestExecution', on_delete=models.CASCADE) name = models.CharField(max_length=64, blank=True, default='') - url = models.URLField() + url = models.URLField(db_index=True) created_on = models.DateTimeField(auto_now_add=True, db_index=True) is_defect = models.BooleanField(default=False, db_index=True) diff --git a/tcms/core/models/base.py b/tcms/core/models/base.py index d6c5ee1a7b..5665e314cf 100644 --- a/tcms/core/models/base.py +++ b/tcms/core/models/base.py @@ -11,4 +11,4 @@ class UrlMixin: # pylint: disable=too-few-public-methods def get_full_url(self): site = Site.objects.get(pk=settings.SITE_ID) host_link = request_host_link(None, site.domain) - return '{}/{}'.format(host_link, self._get_absolute_url().strip('/')) + return '{}/{}/'.format(host_link, self._get_absolute_url().strip('/')) diff --git a/tcms/templates/include/tc_executions.html b/tcms/templates/include/tc_executions.html index 9a515d167b..8bfb647bd0 100644 --- a/tcms/templates/include/tc_executions.html +++ b/tcms/templates/include/tc_executions.html @@ -40,7 +40,7 @@

- +
@@ -58,7 +58,7 @@

{{ execution.status.name }}

- {% if bugs %} + {% if show_bugs and bugs %}
{{ bugs|length }} @@ -82,6 +82,7 @@

+ {% if show_bugs %} {% for bug in bugs %}
@@ -114,6 +115,7 @@

{% endfor %} + {% endif %} {% for comment in execution_comments %} diff --git a/tcms/testcases/templates/testcases/get.html b/tcms/testcases/templates/testcases/get.html index 572074bab9..75fcbcd03a 100644 --- a/tcms/testcases/templates/testcases/get.html +++ b/tcms/testcases/templates/testcases/get.html @@ -125,7 +125,7 @@

- {% include 'include/tc_executions.html' %} + {% include 'include/tc_executions.html' with show_bugs=True %}