diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-09-30 13:31:57 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-10-30 13:39:50 +0000 |
commit | 477587b99616911665055af67ccbfa7abbc48116 (patch) | |
tree | 01ffad4e138a775da49c01c528fc85524e381d61 /bitbake/lib/toaster | |
parent | 1b109c7908a87bfc20c058116b6b72cc16155399 (diff) | |
download | poky-477587b99616911665055af67ccbfa7abbc48116.tar.gz |
bitbake: toastergui: refactor objects get in views.py
We refactor the objects.filter()[0] pattern to the proper
Django QuerySet usage of objects.get() to make sure we
get one and only one object for a query.
(Bitbake rev: 6abec6631fbadaecc474f2a4e7981fde3c58657c)
Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rwxr-xr-x | bitbake/lib/toaster/toastergui/views.py | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 53f46ff532..6a13a99bae 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py | |||
@@ -551,14 +551,14 @@ def recipe(request, build_id, recipe_id): | |||
551 | if Recipe.objects.filter(pk=recipe_id).count() == 0 : | 551 | if Recipe.objects.filter(pk=recipe_id).count() == 0 : |
552 | return redirect(builds) | 552 | return redirect(builds) |
553 | 553 | ||
554 | object = Recipe.objects.filter(pk=recipe_id)[0] | 554 | object = Recipe.objects.get(pk=recipe_id) |
555 | layer_version = Layer_Version.objects.filter(pk=object.layer_version_id)[0] | 555 | layer_version = Layer_Version.objects.get(pk=object.layer_version_id) |
556 | layer = Layer.objects.filter(pk=layer_version.layer_id)[0] | 556 | layer = Layer.objects.get(pk=layer_version.layer_id) |
557 | tasks = Task.objects.filter(recipe_id = recipe_id, build_id = build_id).exclude(order__isnull=True).exclude(task_name__endswith='_setscene').exclude(outcome=Task.OUTCOME_NA) | 557 | tasks = Task.objects.filter(recipe_id = recipe_id, build_id = build_id).exclude(order__isnull=True).exclude(task_name__endswith='_setscene').exclude(outcome=Task.OUTCOME_NA) |
558 | packages = Package.objects.filter(recipe_id = recipe_id).filter(build_id = build_id).filter(size__gte=0) | 558 | packages = Package.objects.filter(recipe_id = recipe_id).filter(build_id = build_id).filter(size__gte=0) |
559 | 559 | ||
560 | context = { | 560 | context = { |
561 | 'build' : Build.objects.filter(pk=build_id)[0], | 561 | 'build' : Build.objects.get(pk=build_id), |
562 | 'object' : object, | 562 | 'object' : object, |
563 | 'layer_version' : layer_version, | 563 | 'layer_version' : layer_version, |
564 | 'layer' : layer, | 564 | 'layer' : layer, |
@@ -846,8 +846,8 @@ def dirinfo(request, build_id, target_id, file_path=None): | |||
846 | if head != sep: | 846 | if head != sep: |
847 | dir_list.insert(0, head) | 847 | dir_list.insert(0, head) |
848 | 848 | ||
849 | context = { 'build': Build.objects.filter(pk=build_id)[0], | 849 | context = { 'build': Build.objects.get(pk=build_id), |
850 | 'target': Target.objects.filter(pk=target_id)[0], | 850 | 'target': Target.objects.get(pk=target_id), |
851 | 'packages_sum': packages_sum['installed_size__sum'], | 851 | 'packages_sum': packages_sum['installed_size__sum'], |
852 | 'objects': objects, | 852 | 'objects': objects, |
853 | 'dir_list': dir_list, | 853 | 'dir_list': dir_list, |
@@ -1092,7 +1092,7 @@ def tasks_common(request, build_id, variant, task_anchor): | |||
1092 | 'object_search_display': object_search_display, | 1092 | 'object_search_display': object_search_display, |
1093 | 'filter_search_display': filter_search_display, | 1093 | 'filter_search_display': filter_search_display, |
1094 | 'title': title_variant, | 1094 | 'title': title_variant, |
1095 | 'build': Build.objects.filter(pk=build_id)[0], | 1095 | 'build': Build.objects.get(pk=build_id), |
1096 | 'objects': tasks, | 1096 | 'objects': tasks, |
1097 | 'default_orderby' : orderby, | 1097 | 'default_orderby' : orderby, |
1098 | 'search_term': search_term, | 1098 | 'search_term': search_term, |
@@ -1159,7 +1159,7 @@ def recipes(request, build_id): | |||
1159 | 1159 | ||
1160 | context = { | 1160 | context = { |
1161 | 'objectname': 'recipes', | 1161 | 'objectname': 'recipes', |
1162 | 'build': Build.objects.filter(pk=build_id)[0], | 1162 | 'build': Build.objects.get(pk=build_id), |
1163 | 'objects': recipes, | 1163 | 'objects': recipes, |
1164 | 'default_orderby' : 'name:+', | 1164 | 'default_orderby' : 'name:+', |
1165 | 'recipe_deps' : deps, | 1165 | 'recipe_deps' : deps, |
@@ -1249,15 +1249,15 @@ def configuration(request, build_id): | |||
1249 | template = 'configuration.html' | 1249 | template = 'configuration.html' |
1250 | 1250 | ||
1251 | variables = Variable.objects.filter(build=build_id) | 1251 | variables = Variable.objects.filter(build=build_id) |
1252 | BB_VERSION=variables.filter(variable_name='BB_VERSION')[0].variable_value | 1252 | BB_VERSION=variables.get(variable_name='BB_VERSION').variable_value |
1253 | BUILD_SYS=variables.filter(variable_name='BUILD_SYS')[0].variable_value | 1253 | BUILD_SYS=variables.get(variable_name='BUILD_SYS').variable_value |
1254 | NATIVELSBSTRING=variables.filter(variable_name='NATIVELSBSTRING')[0].variable_value | 1254 | NATIVELSBSTRING=variables.get(variable_name='NATIVELSBSTRING').variable_value |
1255 | TARGET_SYS=variables.filter(variable_name='TARGET_SYS')[0].variable_value | 1255 | TARGET_SYS=variables.get(variable_name='TARGET_SYS').variable_value |
1256 | MACHINE=variables.filter(variable_name='MACHINE')[0].variable_value | 1256 | MACHINE=variables.get(variable_name='MACHINE').variable_value |
1257 | DISTRO=variables.filter(variable_name='DISTRO')[0].variable_value | 1257 | DISTRO=variables.get(variable_name='DISTRO').variable_value |
1258 | DISTRO_VERSION=variables.filter(variable_name='DISTRO_VERSION')[0].variable_value | 1258 | DISTRO_VERSION=variables.get(variable_name='DISTRO_VERSION').variable_value |
1259 | TUNE_FEATURES=variables.filter(variable_name='TUNE_FEATURES')[0].variable_value | 1259 | TUNE_FEATURES=variables.get(variable_name='TUNE_FEATURES').variable_value |
1260 | TARGET_FPU=variables.filter(variable_name='TARGET_FPU')[0].variable_value | 1260 | TARGET_FPU=variables.get(variable_name='TARGET_FPU').variable_value |
1261 | 1261 | ||
1262 | targets = Target.objects.filter(build=build_id) | 1262 | targets = Target.objects.filter(build=build_id) |
1263 | 1263 | ||
@@ -1265,7 +1265,7 @@ def configuration(request, build_id): | |||
1265 | 'objectname': 'configuration', | 1265 | 'objectname': 'configuration', |
1266 | 'object_search_display':'variables', | 1266 | 'object_search_display':'variables', |
1267 | 'filter_search_display':'variables', | 1267 | 'filter_search_display':'variables', |
1268 | 'build': Build.objects.filter(pk=build_id)[0], | 1268 | 'build': Build.objects.get(pk=build_id), |
1269 | 'BB_VERSION':BB_VERSION, | 1269 | 'BB_VERSION':BB_VERSION, |
1270 | 'BUILD_SYS':BUILD_SYS, | 1270 | 'BUILD_SYS':BUILD_SYS, |
1271 | 'NATIVELSBSTRING':NATIVELSBSTRING, | 1271 | 'NATIVELSBSTRING':NATIVELSBSTRING, |
@@ -1310,14 +1310,14 @@ def configvars(request, build_id): | |||
1310 | file_filter += 'conf/distro/' | 1310 | file_filter += 'conf/distro/' |
1311 | if filter_string.find('/bitbake.conf') > 0: | 1311 | if filter_string.find('/bitbake.conf') > 0: |
1312 | file_filter += '/bitbake.conf' | 1312 | file_filter += '/bitbake.conf' |
1313 | build_dir=re.sub("/tmp/log/.*","",Build.objects.filter(pk=build_id)[0].cooker_log_path) | 1313 | build_dir=re.sub("/tmp/log/.*","",Build.objects.get(pk=build_id).cooker_log_path) |
1314 | 1314 | ||
1315 | context = { | 1315 | context = { |
1316 | 'objectname': 'configvars', | 1316 | 'objectname': 'configvars', |
1317 | 'object_search_display':'BitBake variables', | 1317 | 'object_search_display':'BitBake variables', |
1318 | 'filter_search_display':'variables', | 1318 | 'filter_search_display':'variables', |
1319 | 'file_filter': file_filter, | 1319 | 'file_filter': file_filter, |
1320 | 'build': Build.objects.filter(pk=build_id)[0], | 1320 | 'build': Build.objects.get(pk=build_id), |
1321 | 'objects' : variables, | 1321 | 'objects' : variables, |
1322 | 'total_count':queryset_with_search.count(), | 1322 | 'total_count':queryset_with_search.count(), |
1323 | 'default_orderby' : 'variable_name:+', | 1323 | 'default_orderby' : 'variable_name:+', |
@@ -1383,7 +1383,7 @@ def bpackage(request, build_id): | |||
1383 | 1383 | ||
1384 | context = { | 1384 | context = { |
1385 | 'objectname': 'packages built', | 1385 | 'objectname': 'packages built', |
1386 | 'build': Build.objects.filter(pk=build_id)[0], | 1386 | 'build': Build.objects.get(pk=build_id), |
1387 | 'objects' : packages, | 1387 | 'objects' : packages, |
1388 | 'default_orderby' : 'name:+', | 1388 | 'default_orderby' : 'name:+', |
1389 | 'tablecols':[ | 1389 | 'tablecols':[ |
@@ -1466,13 +1466,13 @@ def bpackage(request, build_id): | |||
1466 | def bfile(request, build_id, package_id): | 1466 | def bfile(request, build_id, package_id): |
1467 | template = 'bfile.html' | 1467 | template = 'bfile.html' |
1468 | files = Package_File.objects.filter(package = package_id) | 1468 | files = Package_File.objects.filter(package = package_id) |
1469 | context = {'build': Build.objects.filter(pk=build_id)[0], 'objects' : files} | 1469 | context = {'build': Build.objects.get(pk=build_id), 'objects' : files} |
1470 | return render(request, template, context) | 1470 | return render(request, template, context) |
1471 | 1471 | ||
1472 | def tpackage(request, build_id, target_id): | 1472 | def tpackage(request, build_id, target_id): |
1473 | template = 'package.html' | 1473 | template = 'package.html' |
1474 | packages = map(lambda x: x.package, list(Target_Installed_Package.objects.filter(target=target_id))) | 1474 | packages = map(lambda x: x.package, list(Target_Installed_Package.objects.filter(target=target_id))) |
1475 | context = {'build': Build.objects.filter(pk=build_id)[0], 'objects' : packages} | 1475 | context = {'build': Build.objects.get(pk=build_id), 'objects' : packages} |
1476 | return render(request, template, context) | 1476 | return render(request, template, context) |
1477 | 1477 | ||
1478 | def layer(request): | 1478 | def layer(request): |
@@ -1494,7 +1494,7 @@ def layer_versions_recipes(request, layerversion_id): | |||
1494 | recipes = Recipe.objects.filter(layer_version__id = layerversion_id) | 1494 | recipes = Recipe.objects.filter(layer_version__id = layerversion_id) |
1495 | 1495 | ||
1496 | context = {'objects': recipes, | 1496 | context = {'objects': recipes, |
1497 | 'layer_version' : Layer_Version.objects.filter( id = layerversion_id )[0] | 1497 | 'layer_version' : Layer_Version.objects.get( id = layerversion_id ) |
1498 | } | 1498 | } |
1499 | 1499 | ||
1500 | return render(request, template, context) | 1500 | return render(request, template, context) |
@@ -1625,10 +1625,10 @@ def package_built_detail(request, build_id, package_id): | |||
1625 | (filter_string, search_term, ordering_string) = _search_tuple(request, Package_File) | 1625 | (filter_string, search_term, ordering_string) = _search_tuple(request, Package_File) |
1626 | paths = _get_queryset(Package_File, queryset, filter_string, search_term, ordering_string, 'path') | 1626 | paths = _get_queryset(Package_File, queryset, filter_string, search_term, ordering_string, 'path') |
1627 | 1627 | ||
1628 | package = Package.objects.filter(pk=package_id)[0] | 1628 | package = Package.objects.get(pk=package_id) |
1629 | package.fullpackagespec = _get_fullpackagespec(package) | 1629 | package.fullpackagespec = _get_fullpackagespec(package) |
1630 | context = { | 1630 | context = { |
1631 | 'build' : Build.objects.filter(pk=build_id)[0], | 1631 | 'build' : Build.objects.get(pk=build_id), |
1632 | 'package' : package, | 1632 | 'package' : package, |
1633 | 'dependency_count' : _get_package_dependency_count(package, -1, False), | 1633 | 'dependency_count' : _get_package_dependency_count(package, -1, False), |
1634 | 'objects' : paths, | 1634 | 'objects' : paths, |
@@ -1658,11 +1658,11 @@ def package_built_dependencies(request, build_id, package_id): | |||
1658 | if Build.objects.filter(pk=build_id).count() == 0 : | 1658 | if Build.objects.filter(pk=build_id).count() == 0 : |
1659 | return redirect(builds) | 1659 | return redirect(builds) |
1660 | 1660 | ||
1661 | package = Package.objects.filter(pk=package_id)[0] | 1661 | package = Package.objects.get(pk=package_id) |
1662 | package.fullpackagespec = _get_fullpackagespec(package) | 1662 | package.fullpackagespec = _get_fullpackagespec(package) |
1663 | dependencies = _get_package_dependencies(package_id) | 1663 | dependencies = _get_package_dependencies(package_id) |
1664 | context = { | 1664 | context = { |
1665 | 'build' : Build.objects.filter(pk=build_id)[0], | 1665 | 'build' : Build.objects.get(pk=build_id), |
1666 | 'package' : package, | 1666 | 'package' : package, |
1667 | 'runtime_deps' : dependencies['runtime_deps'], | 1667 | 'runtime_deps' : dependencies['runtime_deps'], |
1668 | 'other_deps' : dependencies['other_deps'], | 1668 | 'other_deps' : dependencies['other_deps'], |
@@ -1687,12 +1687,12 @@ def package_included_detail(request, build_id, target_id, package_id): | |||
1687 | queryset = Package_File.objects.filter(package_id__exact=package_id) | 1687 | queryset = Package_File.objects.filter(package_id__exact=package_id) |
1688 | paths = _get_queryset(Package_File, queryset, filter_string, search_term, ordering_string, 'path') | 1688 | paths = _get_queryset(Package_File, queryset, filter_string, search_term, ordering_string, 'path') |
1689 | 1689 | ||
1690 | package = Package.objects.filter(pk=package_id)[0] | 1690 | package = Package.objects.get(pk=package_id) |
1691 | package.fullpackagespec = _get_fullpackagespec(package) | 1691 | package.fullpackagespec = _get_fullpackagespec(package) |
1692 | package.alias = _get_package_alias(package) | 1692 | package.alias = _get_package_alias(package) |
1693 | target = Target.objects.filter(pk=target_id)[0] | 1693 | target = Target.objects.get(pk=target_id) |
1694 | context = { | 1694 | context = { |
1695 | 'build' : Build.objects.filter(pk=build_id)[0], | 1695 | 'build' : Build.objects.get(pk=build_id), |
1696 | 'target' : target, | 1696 | 'target' : target, |
1697 | 'package' : package, | 1697 | 'package' : package, |
1698 | 'reverse_count' : _get_package_reverse_dep_count(package, target_id), | 1698 | 'reverse_count' : _get_package_reverse_dep_count(package, target_id), |
@@ -1723,14 +1723,14 @@ def package_included_dependencies(request, build_id, target_id, package_id): | |||
1723 | if Build.objects.filter(pk=build_id).count() == 0 : | 1723 | if Build.objects.filter(pk=build_id).count() == 0 : |
1724 | return redirect(builds) | 1724 | return redirect(builds) |
1725 | 1725 | ||
1726 | package = Package.objects.filter(pk=package_id)[0] | 1726 | package = Package.objects.get(pk=package_id) |
1727 | package.fullpackagespec = _get_fullpackagespec(package) | 1727 | package.fullpackagespec = _get_fullpackagespec(package) |
1728 | package.alias = _get_package_alias(package) | 1728 | package.alias = _get_package_alias(package) |
1729 | target = Target.objects.filter(pk=target_id)[0] | 1729 | target = Target.objects.get(pk=target_id) |
1730 | 1730 | ||
1731 | dependencies = _get_package_dependencies(package_id, target_id) | 1731 | dependencies = _get_package_dependencies(package_id, target_id) |
1732 | context = { | 1732 | context = { |
1733 | 'build' : Build.objects.filter(pk=build_id)[0], | 1733 | 'build' : Build.objects.get(pk=build_id), |
1734 | 'package' : package, | 1734 | 'package' : package, |
1735 | 'target' : target, | 1735 | 'target' : target, |
1736 | 'runtime_deps' : dependencies['runtime_deps'], | 1736 | 'runtime_deps' : dependencies['runtime_deps'], |
@@ -1755,16 +1755,16 @@ def package_included_reverse_dependencies(request, build_id, target_id, package_ | |||
1755 | queryset = Package_Dependency.objects.select_related('depends_on__name', 'depends_on__size').filter(depends_on=package_id, target_id=target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS) | 1755 | queryset = Package_Dependency.objects.select_related('depends_on__name', 'depends_on__size').filter(depends_on=package_id, target_id=target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS) |
1756 | objects = _get_queryset(Package_Dependency, queryset, filter_string, search_term, ordering_string, 'package__name') | 1756 | objects = _get_queryset(Package_Dependency, queryset, filter_string, search_term, ordering_string, 'package__name') |
1757 | 1757 | ||
1758 | package = Package.objects.filter(pk=package_id)[0] | 1758 | package = Package.objects.get(pk=package_id) |
1759 | package.fullpackagespec = _get_fullpackagespec(package) | 1759 | package.fullpackagespec = _get_fullpackagespec(package) |
1760 | package.alias = _get_package_alias(package) | 1760 | package.alias = _get_package_alias(package) |
1761 | target = Target.objects.filter(pk=target_id)[0] | 1761 | target = Target.objects.get(pk=target_id) |
1762 | for o in objects: | 1762 | for o in objects: |
1763 | if o.package.version != '': | 1763 | if o.package.version != '': |
1764 | o.package.version += '-' + o.package.revision | 1764 | o.package.version += '-' + o.package.revision |
1765 | o.alias = _get_package_alias(o.package) | 1765 | o.alias = _get_package_alias(o.package) |
1766 | context = { | 1766 | context = { |
1767 | 'build' : Build.objects.filter(pk=build_id)[0], | 1767 | 'build' : Build.objects.get(pk=build_id), |
1768 | 'package' : package, | 1768 | 'package' : package, |
1769 | 'target' : target, | 1769 | 'target' : target, |
1770 | 'objects' : objects, | 1770 | 'objects' : objects, |
@@ -2153,7 +2153,6 @@ if toastermain.settings.MANAGED: | |||
2153 | 2153 | ||
2154 | 2154 | ||
2155 | context = { | 2155 | context = { |
2156 | 'prj' : prj, | ||
2157 | 'projectlayerset' : json.dumps(map(lambda x: x.layercommit.id, prj.projectlayer_set.all())), | 2156 | 'projectlayerset' : json.dumps(map(lambda x: x.layercommit.id, prj.projectlayer_set.all())), |
2158 | 'objects' : layer_info, | 2157 | 'objects' : layer_info, |
2159 | 'objectname' : "layers", | 2158 | 'objectname' : "layers", |