Patchwork [bitbake-devel,18/18] toaster: replace package dependency tag w/ view queries

login
register
mail settings
Submitter Alexandru DAMIAN
Date March 24, 2014, 6:37 p.m.
Message ID <9dd53bd4355148916a89cf672b6c5db5f6b1ae35.1395686148.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/69115/
State New
Headers show

Comments

Alexandru DAMIAN - March 24, 2014, 6:37 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

This patch moves the queries for package dependencies from the
project tags to the views. This is done to bring the code inline
with the Django philosophy of making all data queries in views.py

This change has no performance implication.

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 lib/toaster/toastergui/templates/target.html       |  4 ++--
 lib/toaster/toastergui/templatetags/projecttags.py | 14 --------------
 lib/toaster/toastergui/views.py                    |  6 ++++++
 3 files changed, 8 insertions(+), 16 deletions(-)

Patch

diff --git a/lib/toaster/toastergui/templates/target.html b/lib/toaster/toastergui/templates/target.html
index 4512898..5396b17 100644
--- a/lib/toaster/toastergui/templates/target.html
+++ b/lib/toaster/toastergui/templates/target.html
@@ -79,7 +79,7 @@ 
             {{package.license}}
         </td>
         <td class="depends">
-            {% with deps=package|runtime_dependencies:target.id %}
+            {% with deps=package.runtime_dependencies %}
             {% with deps_count=deps|length %}
             {% if deps_count > 0 %}
             <a class="btn"
@@ -96,7 +96,7 @@ 
             {% endwith %}
         </td>
         <td class="brought_in_by">
-            {% with rdeps=package|reverse_runtime_dependencies:target.id %}
+            {% with rdeps=package.reverse_runtime_dependencies %}
             {% with rdeps_count=rdeps|length %}
             {% if rdeps_count > 0 %}
             <a class="btn"
diff --git a/lib/toaster/toastergui/templatetags/projecttags.py b/lib/toaster/toastergui/templatetags/projecttags.py
index 39e92ce..12c2468 100644
--- a/lib/toaster/toastergui/templatetags/projecttags.py
+++ b/lib/toaster/toastergui/templatetags/projecttags.py
@@ -217,20 +217,6 @@  def filtered_packageversion(version, revision):
     """
     return "" if (not version or version == "") else version if (not revision or revision == "") else version + "-" + revision
         
-from django.db import models
-from orm.models import Package
-@register.filter
-def runtime_dependencies(package_object, targetid):
-    """ Return a queryset that lists the packages this package depends on
-    """
-    return package_object.package_dependencies_source.filter(target_id__exact=targetid, dep_type__in={'1'})
-
-@register.filter
-def reverse_runtime_dependencies(package_object, targetid):
-    """ Return a queryset that lists the packages depending on this package
-    """
-    return package_object.package_dependencies_target.filter(target_id__exact = targetid,dep_type__in={'1'})
-
 @register.filter
 def filter_sizeovertotal(package_object, total_size):
     """ Return the % size of the package over the total size argument
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 732be8f..e523c31 100644
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -429,6 +429,12 @@  def target(request, build_id, target_id):
     packages_sum =  queryset.aggregate(Sum('installed_size'))
     queryset = _get_queryset(Package, queryset, filter_string, search_term, ordering_string)
     packages = _build_page_range(Paginator(queryset, request.GET.get('count', 25)),request.GET.get('page', 1))
+
+    # bring in package dependencies
+    for p in packages.object_list:
+        p.runtime_dependencies = p.package_dependencies_source.filter(target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS)
+        p.reverse_runtime_dependencies = p.package_dependencies_target.filter(target_id = target_id, dep_type=Package_Dependency.TYPE_TRDEPENDS)
+
     context = { 'build': Build.objects.filter(pk=build_id)[0],
                 'target': Target.objects.filter(pk=target_id)[0],
                 'objects': packages,