Skip to content

Commit

Permalink
Fix tags search and hint while adding tags to test cases in TP
Browse files Browse the repository at this point in the history
How to reproduce:
- Open a Test Plan
- Go to Cases tab
- Select few test cases
- click Tag -> Add Tag button
- start typing tag name
- if there are tags which match the text they will be shown
  as a drop-down hint. This was previously raising an exception.

Also introduced a slight performance optimization by using
QuerySet.values() method to fetch only the field name we're interested
in, not everything.

Note: this commit makes use of the TestCaseTag class instead of the
TestTag class in order to convert ORM queries to child -> parent
relationship, instead of parent -> child one.

Updated JavaScript files to match the backend changes and model
field names.

Note:
Removal of tags bug is Nitrate#174 which is fixed in PR Nitrate#177

Signed-off-by: Mr. Senko <atodorov@mrsenko.com>
  • Loading branch information
atodorov committed May 12, 2017
1 parent ad55cb5 commit 8ca779b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions tcms/core/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from tcms.management.models import Component, TestBuild, Version
from tcms.management.models import Priority
from tcms.management.models import TestTag
from tcms.testcases.models import TestCase, TestCaseBug
from tcms.testcases.models import TestCase, TestCaseBug, TestCaseTag
from tcms.testcases.models import TestCaseCategory
from tcms.testcases.models import TestCaseStatus
from tcms.testcases.views import get_selected_testcases
Expand Down Expand Up @@ -121,13 +121,13 @@ def env_values(self):

def tags(self):
query = strip_parameters(request, self.internal_parameters)
tags = TestTag.objects
tags = TestCaseTag.objects
# Generate the string combination, because we are using
# case sensitive table
if query.get('name__startswith'):
seq = get_string_combinations(query['name__startswith'])
tags = tags.filter(eval(
'|'.join(["Q(name__startswith = '%s')" % item for item in seq])
'|'.join(["models.Q(tag__name__startswith = '%s')" % item for item in seq])
))
del query['name__startswith']

Expand All @@ -145,15 +145,15 @@ def versions(self):

return Version.objects.filter(product__id=self.product_id)

objects = Objects(request=request, product_id=request.GET['product_id'])
objects = Objects(request=request, product_id=request.GET.get('product_id'))
obj = getattr(objects, request.GET['info_type'], None)

if obj:
if request.GET.get('format') == 'ulli':
field = request.GET.get('field', 'name')
response_str = '<ul>'
for o in obj():
response_str += '<li>' + getattr(o, field, None) + '</li>'
for o in obj().values(field):
response_str += '<li>' + o.get(field, None) + '</li>'
response_str += '</ul>'
return HttpResponse(response_str)

Expand Down
4 changes: 2 additions & 2 deletions tcms/static/js/testplan_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2468,8 +2468,8 @@ function constructBatchTagProcessDialog(plan_id) {
'name__startswith': request.term,
'info_type': 'tags',
'format': 'ulli',
'testcase__plan__pk': plan_id,
'field': 'name'
'case__plan': plan_id,
'field': 'tag__name'
},
'success': function(data) {
var processedData = [];
Expand Down

0 comments on commit 8ca779b

Please sign in to comment.