Permalink
Browse files

sorting for cases of suites now working more efficiently

  • Loading branch information...
camd committed Apr 10, 2013
1 parent 076fec6 commit e8a9e1faa7d664e9c2d973d6de9f24b0da0e6f7e
@@ -1,16 +1,14 @@
{{#items}}
<article class="selectitem" data-title="{{ name }}" data-product-id="{{ product_id }}">
- <input type="checkbox" name="bulk-select" value="{{ id }}" class="bulk-value" id="bulk-select-{{ id }}" {{ checked }}>
+ <input type="checkbox" name="bulk-select" value="{{ case_id }}" class="bulk-value" id="bulk-select-{{ case_id }}" {{ checked }}>
<div class="listitem itemhead bulk-item">
- <label for="bulk-select-{{ id }}" class="bulk-type" title="select or drag">bulk select {{ case_id }}</label>
+ <label for="bulk-select-{{ case_id }}" class="bulk-type" title="select or drag">bulk select {{ case_id }}</label>
<div class="name-tags">
<h5 class="title" title="{{ name }}">{{ name }}</h5>
<ul class="tags">
- {{#versions}}
- {{#tags}}
- <li><a href="#{{ name|slugify }}" title="filter by {{ name }}" class="filter-link tag" data-type="tag">{{ name }}</a></li>
- {{/tags}}
- {{/versions}}
+ {{#tags}}
+ <li><a href="#{{ name|slugify }}" title="filter by {{ name }}" class="filter-link tag" data-type="tag">{{ name }}</a></li>
+ {{/tags}}
</ul>
</div>
@@ -307,15 +307,16 @@ class SuiteSelectionResource(BaseSelectionResource):
class Meta:
queryset = Suite.objects.all().select_related(
"created_by",
- ).annotate(order=Max("runsuites__order")).order_by("order")
+ ).annotate(order=Max("runsuites__order"))
list_allowed_methods = ['get']
- fields = ["id", "name", "created_by"]
+ fields = ["id", "name", "created_by", "runsuites"]
filtering = {
"product": ALL_WITH_RELATIONS,
"runs": ALL_WITH_RELATIONS,
"created_by": ALL_WITH_RELATIONS,
}
+ ordering = ["runs"]
def dehydrate(self, bundle):
@@ -324,54 +324,51 @@ class CaseSelectionResource(BaseSelectionResource):
for selecting cases.
"""
- product = fields.ForeignKey(ProductResource, "product")
- versions = fields.ToManyField(
- 'moztrap.model.library.api.CaseVersionSelectionResource',
- # filter for only the latest of the caseversions
- lambda bundle: CaseVersion.objects.filter(
- case=bundle.obj,
- latest=True
- ),
- related_name="versions",
- full=True,
- null=True,
- )
- suites = fields.ToManyField(SuiteResource, "suites", null=True)
+ case = fields.ForeignKey(CaseResource, "case")
+ productversion = fields.ForeignKey(
+ ProductVersionResource, "productversion")
+ tags = fields.ToManyField(TagResource, "tags", full=True)
+ created_by = fields.ForeignKey(UserResource, "created_by", full=True, null=True)
class Meta:
- # versions=None exclude is just in case a ``case`` exists with no
- # case versions.
- queryset = Case.objects.filter(versions__latest=True).select_related(
- "product",
- "created_by",
- ).prefetch_related(
- "versions",
- "versions__tags",
- "suites",
- ).annotate(
- order=Max("suitecases__order"),
- version_count=NotDeletedCount("versions"),
- ).exclude(version_count=0).order_by("order")
-
+ queryset = CaseVersion.objects.filter(latest=True).select_related(
+ "case",
+ "productversion",
+ "created_by",
+ ).prefetch_related(
+ "tags",
+ "tags__product",
+ "case__suitecases",
+ )
list_allowed_methods = ['get']
- fields = ["id", "versions", "created_by", "version_count"]
+ fields = ["id", "name", "latest", "created_by"]
filtering = {
- "product": ALL_WITH_RELATIONS,
- "versions": ALL_WITH_RELATIONS,
- "created_by": ALL_WITH_RELATIONS,
- "suites": ALL_WITH_RELATIONS
+ "productversion": ALL_WITH_RELATIONS,
+ "tags": ALL_WITH_RELATIONS,
+ "case": ALL_WITH_RELATIONS,
+ "created_by": ALL_WITH_RELATIONS
}
+ ordering = ["case"]
+
+ # def build_filters(self, filters=None):
+ #
+ # .order_by("case__suitecases__order")
def dehydrate(self, bundle):
"""Add some convenience fields to the return JSON."""
- versions = bundle.obj.versions.filter(latest=1)
- if versions:
- bundle.data["name"] = unicode(versions[0].name)
+ case = bundle.obj.case
+ bundle.data["case_id"] = unicode(case.id)
+ bundle.data["product_id"] = unicode(case.product_id)
+ bundle.data["product"] = {"id": unicode(case.product_id)}
+
+ if "case__suites" in bundle.request.GET.keys():
+ bundle.data["order"] = case.suitecases.get(
+ suite_id=int(bundle.request.GET["case__suites"])
+ ).order
else:
- bundle.data["name"] = "No name available" # pragma: no cover
- bundle.data["order"] = bundle.obj.order
+ bundle.data["order"] = None
return bundle
@@ -400,8 +397,8 @@ class Meta:
"productversion",
"created_by",
).prefetch_related(
- "tags",
- )
+ "tags",
+ )
list_allowed_methods = ['get']
fields = ["id", "name", "latest", "created_by_id"]
filtering = {
@@ -25,7 +25,7 @@ class TagResource(MTResource):
#@@@ additional relationship caseversions needs to be handled
class Meta(MTResource.Meta):
- queryset = Tag.objects.all()
+ queryset = Tag.objects.all().select_related("product")
fields = ["id", "name", "description", "product"]
filtering = {
"name": ALL,
@@ -16,9 +16,9 @@
except NameError:
HMAC_KEYS = {"default": SECRET_KEY}
-# LOGGING["handlers"]["null"] = {
-# 'level': 'DEBUG',
-# 'class': 'django.utils.log.NullHandler',
-# }
-#
-# LOGGING["root"] = {"handlers": ["null"]}
+LOGGING["handlers"]["null"] = {
+ 'level': 'DEBUG',
+ 'class': 'django.utils.log.NullHandler',
+ }
+
+LOGGING["root"] = {"handlers": ["null"]}
View
@@ -184,9 +184,10 @@ var MT = (function (MT, $) {
container: '#suite-edit-form, #suite-add-form',
trigger_field: '#id_product',
ajax_url_root: "/api/v1/caseselection/?format=json&limit=0",
- ajax_trigger_filter: "product",
- ajax_for_field: "suites",
+ ajax_trigger_filter: "productversion__product",
+ ajax_for_field: "case__suites",
for_type: "suite",
+ included_sort_field: "case__suitecases__order",
ich_template: ich.case_select_item
});
MT.populateMultiselectItems({
@@ -215,6 +216,7 @@ var MT = (function (MT, $) {
ajax_trigger_filter: "product",
ajax_for_field: "runs",
for_type: "run",
+ included_sort_field: "runs__runsuites__order",
ich_template: ich.suite_select_item,
refetch_on_trigger: false
});
@@ -111,6 +111,7 @@ var MT = (function (MT, $) {
options.ich_template,
options.ajax_for_field,
included_id,
+ options.included_sort_field,
options.use_latest
);
}
@@ -138,6 +139,7 @@ var MT = (function (MT, $) {
ich_template,
ajax_for_field,
included_id,
+ included_sort_field,
use_latest) {
var available = $(".multiunselected").find(".select"),
@@ -163,7 +165,7 @@ var MT = (function (MT, $) {
// get the ``latest`` case versions to display here
// @@@ maybe we could check cookies here. If productversion is
- // set, then use that instead. But, garsh.. what if they have more
+ // set, then use that instead. But... what if they have more
// than one productversion filter pinned? Have to check if the
// productversion matched the product set in this form, but I
// don't have that info. Need it server side, or via ajax.
@@ -176,6 +178,7 @@ var MT = (function (MT, $) {
if (included_id) {
avail_url.addSearch(ajax_for_field + "__ne", included_id);
incl_url.addSearch(ajax_for_field, included_id);
+ incl_url.addSearch("order_by", included_sort_field);
}
if (available.length) {
@@ -112,54 +112,34 @@ def resource_name(self):
@property
def included_param(self):
- return "suites"
+ return "case__suites"
@property
def available_param(self):
return "{0}__ne".format(self.included_param)
- def get_exp_obj(self, cv, order=None, suites=None):
+ def get_exp_obj(self, cv, order=None):
"""Return an expected caseselection object with fields filled."""
- if not suites:
- suites = []
- case = cv.case
- product = case.product
- pv = cv.productversion
-
return {
- u'suites': [unicode(self.get_detail_url("suite", s.id)) for s in suites],
- u"product": unicode(self.get_detail_url("product", product.id)),
+ u"case": unicode(
+ self.get_detail_url("case", cv.case.id)),
+ u"case_id": unicode(cv.case.id),
+ u"created_by": None,
+ u"id": unicode(cv.id),
+ u"latest": True,
u"name": unicode(cv.name),
- u'versions': [{
- u"case": unicode(
- self.get_detail_url("case", case.id)),
- u'product': {u'id': unicode(product.id)},
- u"name": unicode(cv.name),
- u'tags': [],
- u'productversion_name': unicode(pv.name),
- u'created_by': None,
- u'case_id': unicode(cv.case.id),
- u'productversion': {
- u'product': unicode(self.get_detail_url(
- "product", product.id)),
- u'codename': u'',
- u'version': unicode(pv.version),
- u'id': unicode(pv.id),
- u'resource_uri': unicode(self.get_detail_url(
- "productversion", pv.id))
- },
- u'resource_uri': unicode(
- self.get_detail_url("caseversionselection", cv.id)),
- u'product_id': unicode(product.id),
- u'id': unicode(cv.id),
- u'latest': True
- }],
- u'id': unicode(case.id),
u"order": order,
+ u"product": {
+ u"id": unicode(cv.productversion.product_id)
+ },
+ u"product_id": unicode(cv.productversion.product_id),
+ u"productversion": unicode(
+ self.get_detail_url("productversion", cv.productversion.id)),
u"resource_uri": unicode(
- self.get_detail_url("caseselection", case.id)),
+ self.get_detail_url("caseselection", cv.id)),
+ u"tags": [],
}
@@ -238,7 +218,6 @@ def test_included_for_two_included(self):
self.get_exp_obj(
cv,
order=sc.order,
- suites=[data["s"]],
) for cv, sc in [
(data["cv1"], data["sc1"]),
(data["cv2"], data["sc2"]),
@@ -290,7 +269,6 @@ def test_included_for_one_included_one_not(self):
self.get_exp_obj(
cv,
order=sc.order,
- suites=[data["s"]],
) for cv, sc in [(data["cv1"], data["sc1"])]
]

0 comments on commit e8a9e1f

Please sign in to comment.