Skip to content

Commit

Permalink
Show TC Executions card when viewing a bug. Refs #699
Browse files Browse the repository at this point in the history
- [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.
  • Loading branch information
atodorov committed Sep 19, 2019
1 parent 76a0d51 commit 6264b38
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 8 deletions.
2 changes: 2 additions & 0 deletions tcms/bugs/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.conf import settings
from django.db import migrations, models
import tcms.core.models.base


class Migration(migrations.Migration):
Expand Down Expand Up @@ -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),
),
]
10 changes: 8 additions & 2 deletions tcms/bugs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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, ])
3 changes: 3 additions & 0 deletions tcms/bugs/static/bugs/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
5 changes: 5 additions & 0 deletions tcms/bugs/templates/bugs/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ <h2 class="card-pf-title">
</div>
</div>
</div>
</div>

<div class="row row-cards-pf">
<div class="col-xs-12 col-sm-12 col-md-12">
{% include 'include/tc_executions.html' %}
</div>
</div>

{% get_comment_list for object as comments %}
Expand Down
11 changes: 10 additions & 1 deletion tcms/bugs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 1 addition & 1 deletion tcms/core/contrib/linkreference/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tcms/core/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('/'))
6 changes: 4 additions & 2 deletions tcms/templates/include/tc_executions.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2 class="card-pf-title">
<div class="list-group-item-header">
<div class="list-view-pf-main-info">
<div class="list-view-pf-left">
<span class="fa {% if execution_comments or bugs %}fa-angle-right{% else %}fa-exclamation{% endif %}"></span>
<span class="fa {% if execution_comments or show_bugs and bugs %}fa-angle-right{% else %}fa-exclamation{% endif %}"></span>
</div>

<div class="list-view-pf-body">
Expand All @@ -58,7 +58,7 @@ <h2 class="card-pf-title">
<span class="{{ execution.status.icon }}"></span>
<strong>{{ execution.status.name }}</strong>
</div>
{% if bugs %}
{% if show_bugs and bugs %}
<div class="list-view-pf-additional-info-item">
<span class="fa fa-bug"></span>
<strong>{{ bugs|length }}</strong>
Expand All @@ -82,6 +82,7 @@ <h2 class="card-pf-title">
</div>
</div>
</div> <!-- / caserun header -->
{% if show_bugs %}
{% for bug in bugs %}
<div class="list-group-item-container container-fluid">
<div class="list-group-item">
Expand Down Expand Up @@ -114,6 +115,7 @@ <h2 class="card-pf-title">
</div>
</div> <!-- /bug -->
{% endfor %}
{% endif %}

{% for comment in execution_comments %}
<!-- comments -->
Expand Down
2 changes: 1 addition & 1 deletion tcms/testcases/templates/testcases/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2 class="card-pf-title" style="text-align: left">

<div class="row row-cards-pf">
<div class="col-xs-12 col-sm-12 col-md-12">
{% include 'include/tc_executions.html' %}
{% include 'include/tc_executions.html' with show_bugs=True %}
</div>
</div>

Expand Down

0 comments on commit 6264b38

Please sign in to comment.