diff --git a/TODO b/TODO index 0e91ba5..cca4a12 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,6 @@ Later: * Add link to the all layers and all recipes tables from the layer details page? * Display no-results found message when search does not return any results (all tables) * Change behaviour of filter menus to stay open so that you can check / uncheck multiple items -* Show recipes from non-software/base layers differently in recipes list * Show layer type in layer detail? * Usage links in list page? * Avoid page content changing size depending on whether scrollbar is there or not? diff --git a/layerindex/static/css/additional.css b/layerindex/static/css/additional.css index cd99fdd..1e2e7b3 100644 --- a/layerindex/static/css/additional.css +++ b/layerindex/static/css/additional.css @@ -156,3 +156,7 @@ padding: 8px; background-color: white; height: 100%; } + +.muted a { + color: #66B8E0; +} diff --git a/layerindex/views.py b/layerindex/views.py index 9e61317..89822ba 100644 --- a/layerindex/views.py +++ b/layerindex/views.py @@ -247,9 +247,32 @@ class RecipeSearchView(ListView): init_qs = Recipe.objects.filter(layerbranch__branch__name=self.request.session.get('branch', 'master')) if query_string.strip(): entry_query = simplesearch.get_query(query_string, ['pn', 'summary', 'description', 'filename']) - return init_qs.filter(entry_query).order_by('pn', 'layerbranch__layer') + qs = init_qs.filter(entry_query).order_by('pn', 'layerbranch__layer') else: - return init_qs.order_by('pn', 'layerbranch__layer') + if 'q' in self.request.GET: + qs = init_qs.order_by('pn', 'layerbranch__layer') + else: + # It's a bit too slow to return all records by default, and most people + # won't actually want that (if they do they can just hit the search button + # with no query string) + return Recipe.objects.none() + + # Add extra column so we can show "duplicate" recipes from other layers de-emphasised + # (it's a bit crude having to do this using SQL but I couldn't find a better way...) + return qs.extra( + select={ + 'preferred_count': """SELECT COUNT(1) +FROM layerindex_recipe AS recipe2 +, layerindex_layerbranch as branch2 +, layerindex_layeritem as layer2 +WHERE branch2.id = recipe2.layerbranch_id +AND layer2.id = branch2.layer_id +AND layer2.layer_type in ('S', 'A') +AND recipe2.pn = layerindex_recipe.pn +AND recipe2.layerbranch_id < layerindex_recipe.layerbranch_id +""" + }, + ) def get_context_data(self, **kwargs): context = super(RecipeSearchView, self).get_context_data(**kwargs) diff --git a/templates/layerindex/recipes.html b/templates/layerindex/recipes.html index 36749de..f400442 100644 --- a/templates/layerindex/recipes.html +++ b/templates/layerindex/recipes.html @@ -50,7 +50,7 @@ {% for recipe in recipe_list %} - + 0 %}class="muted"{% endif %}> {{ recipe.name }} {{ recipe.pv }} {{ recipe.short_desc }} @@ -77,3 +77,14 @@ {% endautoescape %} {% endblock %} + + +{% block scripts %} + +{% endblock %}