[yocto] [layerindex-web][patch v2 1/1] templates/layerindex/classes.html: Add bbclass search

Amanda Brindle amanda.r.brindle at intel.com
Mon Nov 6 14:22:17 PST 2017


Add another tab to search for classes.

Fixes [YOCTO #11207]

Signed-off by: Amanda Brindle <amanda.r.brindle at intel.com>
---
 layerindex/restviews.py            | 10 ++++-
 layerindex/urls.py                 |  3 ++
 layerindex/urls_branch.py          |  6 ++-
 layerindex/views.py                | 24 ++++++++++++
 templates/layerindex/classes.html  | 75 ++++++++++++++++++++++++++++++++++++++
 templates/layerindex/distros.html  |  1 +
 templates/layerindex/layers.html   |  1 +
 templates/layerindex/machines.html |  1 +
 templates/layerindex/recipes.html  |  1 +
 9 files changed, 120 insertions(+), 2 deletions(-)
 create mode 100644 templates/layerindex/classes.html

diff --git a/layerindex/restviews.py b/layerindex/restviews.py
index d947bbf..836aa54 100644
--- a/layerindex/restviews.py
+++ b/layerindex/restviews.py
@@ -1,4 +1,4 @@
-from layerindex.models import Branch, LayerItem, LayerNote, LayerBranch, LayerDependency, Recipe, Machine, Distro
+from layerindex.models import Branch, LayerItem, LayerNote, LayerBranch, LayerDependency, Recipe, Machine, Distro, BBClass
 from rest_framework import viewsets, serializers
 from layerindex.querysethelper import params_to_queryset, get_search_tuple
 
@@ -64,3 +64,11 @@ class DistroSerializer(serializers.ModelSerializer):
 class DistroViewSet(ParametricSearchableModelViewSet):
     queryset = Distro.objects.all()
     serializer_class = DistroSerializer
+
+class ClassSerializer(serializers.ModelSerializer):
+    class Meta:
+        model = BBClass
+
+class ClassViewSet(ParametricSearchableModelViewSet):
+    queryset = BBClass.objects.all()
+    serializer_class = ClassSerializer
diff --git a/layerindex/urls.py b/layerindex/urls.py
index b4535d2..6a1cb6a 100644
--- a/layerindex/urls.py
+++ b/layerindex/urls.py
@@ -22,6 +22,7 @@ router.register(r'layerDependencies', restviews.LayerDependencyViewSet)
 router.register(r'recipes', restviews.RecipeViewSet)
 router.register(r'machines', restviews.MachineViewSet)
 router.register(r'distros', restviews.DistroViewSet)
+router.register(r'classes', restviews.ClassViewSet)
 
 urlpatterns = patterns('',
     url(r'^$',
@@ -40,6 +41,8 @@ urlpatterns = patterns('',
         RedirectView.as_view(url=reverse_lazy('machine_search', args=('master',)), permanent=False)),
     url(r'^distros/$',
         RedirectView.as_view(url=reverse_lazy('distro_search', args=('master',)), permanent=False)),
+    url(r'^classes/$',
+        RedirectView.as_view(url=reverse_lazy('class_search', args=('master',)), permanent=False)),
  
     url(r'^submit/$', edit_layer_view, {'template_name': 'layerindex/submitlayer.html'}, name="submit_layer"),
     url(r'^submit/thanks$',
diff --git a/layerindex/urls_branch.py b/layerindex/urls_branch.py
index 89659d9..d451896 100644
--- a/layerindex/urls_branch.py
+++ b/layerindex/urls_branch.py
@@ -7,7 +7,7 @@
 from django.conf.urls import *
 from django.views.defaults import page_not_found
 from django.core.urlresolvers import reverse_lazy
-from layerindex.views import LayerListView, RecipeSearchView, MachineSearchView, DistroSearchView, PlainTextListView, LayerDetailView, edit_layer_view, delete_layer_view, edit_layernote_view, delete_layernote_view, RedirectParamsView, DuplicatesView, LayerUpdateDetailView
+from layerindex.views import LayerListView, RecipeSearchView, MachineSearchView, DistroSearchView, ClassSearchView, PlainTextListView, LayerDetailView, edit_layer_view, delete_layer_view, edit_layernote_view, delete_layernote_view, RedirectParamsView, DuplicatesView, LayerUpdateDetailView
 
 urlpatterns = patterns('',
     url(r'^$', 
@@ -32,6 +32,10 @@ urlpatterns = patterns('',
         DistroSearchView.as_view(
             template_name='layerindex/distros.html'),
             name='distro_search'),
+    url(r'^classes/$',
+        ClassSearchView.as_view(
+            template_name='layerindex/classes.html'),
+            name='class_search'),
     url(r'^edit/(?P<slug>[-\w]+)/$', edit_layer_view, {'template_name': 'layerindex/editlayer.html'}, name="edit_layer"),
     url(r'^duplicates/$',
         DuplicatesView.as_view(
diff --git a/layerindex/views.py b/layerindex/views.py
index 3b22067..03d47f2 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -724,6 +724,30 @@ class DistroSearchView(ListView):
         context['this_url_name'] = resolve(self.request.path_info).url_name
         return context
 
+class ClassSearchView(ListView):
+    context_object_name = 'class_list'
+    paginate_by = 50
+
+    def get_queryset(self):
+        _check_url_branch(self.kwargs)
+        query_string = self.request.GET.get('q', '')
+        init_qs = BBClass.objects.filter(layerbranch__branch__name=self.kwargs['branch'])
+        if query_string.strip():
+            entry_query = simplesearch.get_query(query_string, ['name'])
+            return init_qs.filter(entry_query).order_by('name', 'layerbranch__layer')
+
+        if 'q' in self.request.GET:
+            return init_qs.order_by('name', 'layerbranch__layer')
+
+        # Be consistent with RecipeSearchView
+        return Distro.objects.none()
+
+    def get_context_data(self, **kwargs):
+        context = super(ClassSearchView, self).get_context_data(**kwargs)
+        context['search_keyword'] = self.request.GET.get('q', '')
+        context['url_branch'] = self.kwargs['branch']
+        context['this_url_name'] = resolve(self.request.path_info).url_name
+        return context
 
 class PlainTextListView(ListView):
     def render_to_response(self, context):
diff --git a/templates/layerindex/classes.html b/templates/layerindex/classes.html
new file mode 100644
index 0000000..f16cba7
--- /dev/null
+++ b/templates/layerindex/classes.html
@@ -0,0 +1,75 @@
+{% extends "base_toplevel.html" %}
+{% load i18n %}
+
+{% comment %}
+
+  layerindex-web - class index page template
+
+  Copyright (C) 2013 Intel Corporation
+  Copyright (C) 2016 Wind River Systems
+  Licensed under the MIT license, see COPYING.MIT for details
+
+{% endcomment %}
+
+
+<!--
+{% block title_append %} - classes{% endblock %}
+-->
+
+{% block navs %}
+{% autoescape on %}
+                            <li><a href="{% url 'layer_list' url_branch %}">Layers</a></li>
+                            <li><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li>
+                            <li><a href="{% url 'machine_search' url_branch %}">Machines</a></li>
+                            <li class="active"><a href="{% url 'class_search' url_branch %}">Classes</a></li>
+                            <li><a href="{% url 'distro_search' url_branch %}">Distros</a></li>
+{% endautoescape %}
+{% endblock %}
+
+
+{% block content_inner %}
+{% autoescape on %}
+
+
+                <div class="row-fluid">
+                    <div class="input-append">
+                        <form id="filter-form" action="{% url 'class_search' url_branch %}" method="get">
+                            <input type="text" class="input-xxlarge" id="appendedInputButtons" placeholder="Search classes" name="q" value="{{ search_keyword }}" />
+                            <button class="btn" type="submit">search</button>
+                        </form>
+                    </div>
+                </div>
+
+{% if class_list %}
+                <table class="table table-striped table-bordered classestable">
+                    <thead>
+                        <tr>
+                            <th>Class Name</th>
+                            <th>Layer</th>
+                        </tr>
+                    </thead>
+
+                    <tbody>
+                        {% for class in class_list %}
+                            <tr>
+                                <td><a href="{{ class.vcs_web_url }}">{{ class.name }}</a></td>
+                                <td><a href="{% url 'layer_item' url_branch class.layerbranch.layer.name %}">{{ class.layerbranch.layer.name }}</a></td>
+                            </tr>
+                        {% endfor %}
+                    </tbody>
+                </table>
+
+    {% if is_paginated %}
+        {% load pagination %}
+        {% pagination page_obj %}
+    {% endif %}
+{% else %}
+    {% if search_keyword %}
+    <p>No matching classes in database.</p>
+    {% endif %}
+{% endif %}
+
+
+{% endautoescape %}
+
+{% endblock %}
diff --git a/templates/layerindex/distros.html b/templates/layerindex/distros.html
index 7085584..5b6995a 100644
--- a/templates/layerindex/distros.html
+++ b/templates/layerindex/distros.html
@@ -21,6 +21,7 @@
                             <li><a href="{% url 'layer_list' url_branch %}">Layers</a></li>
                             <li><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li>
                             <li><a href="{% url 'machine_search' url_branch %}">Machines</a></li>
+                            <li><a href="{% url 'class_search' url_branch %}">Classes</a></li>
                             <li class="active"><a href="{% url 'distro_search' url_branch %}">Distros</a></li>
 {% endautoescape %}
 {% endblock %}
diff --git a/templates/layerindex/layers.html b/templates/layerindex/layers.html
index f1a3703..11954e0 100644
--- a/templates/layerindex/layers.html
+++ b/templates/layerindex/layers.html
@@ -21,6 +21,7 @@
                             <li class="active"><a href="{% url 'layer_list' url_branch %}">Layers</a></li>
                             <li><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li>
                             <li><a href="{% url 'machine_search' url_branch %}">Machines</a></li>
+                            <li><a href="{% url 'class_search' url_branch %}">Classes</a></li>
                             <li><a href="{% url 'distro_search' url_branch %}">Distros</a></li>
 {% endautoescape %}
 {% endblock %}
diff --git a/templates/layerindex/machines.html b/templates/layerindex/machines.html
index 2a9f947..c0c6f33 100644
--- a/templates/layerindex/machines.html
+++ b/templates/layerindex/machines.html
@@ -20,6 +20,7 @@
                             <li><a href="{% url 'layer_list' url_branch %}">Layers</a></li>
                             <li><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li>
                             <li class="active"><a href="{% url 'machine_search' url_branch %}">Machines</a></li>
+                            <li><a href="{% url 'class_search' url_branch %}">Classes</a></li>
                             <li><a href="{% url 'distro_search' url_branch %}">Distros</a></li>
 {% endautoescape %}
 {% endblock %}
diff --git a/templates/layerindex/recipes.html b/templates/layerindex/recipes.html
index 60a2667..1322750 100644
--- a/templates/layerindex/recipes.html
+++ b/templates/layerindex/recipes.html
@@ -20,6 +20,7 @@
                             <li><a href="{% url 'layer_list' url_branch %}">Layers</a></li>
                             <li class="active"><a href="{% url 'recipe_search' url_branch %}">Recipes</a></li>
                             <li><a href="{% url 'machine_search' url_branch %}">Machines</a></li>
+                            <li><a href="{% url 'class_search' url_branch %}">Classes</a></li>
                             <li><a href="{% url 'distro_search' url_branch %}">Distros</a></li>
 {% endautoescape %}
 {% endblock %}
-- 
2.7.4




More information about the yocto mailing list