summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2018-05-07 12:04:38 +1200
committerPaul Eggleton <paul.eggleton@linux.intel.com>2018-05-07 15:30:04 +1200
commit09f629b997da1e52b1cb93d36566e04908e0517c (patch)
treee0dd95a48dcaed2e0ddf7c49ccd5acc8b4647fa2
parent15d1253f79e081c1f6223d8e95ccc50acff27734 (diff)
downloadopenembedded-core-contrib-09f629b997da1e52b1cb93d36566e04908e0517c.tar.gz
openembedded-core-contrib-09f629b997da1e52b1cb93d36566e04908e0517c.tar.bz2
openembedded-core-contrib-09f629b997da1e52b1cb93d36566e04908e0517c.zip
Add CSV export for layer recipes
Add the ability to export the recipe listing for a layer to a CSV file for importing into external tools. At the moment we include name, version and license, but there is a parameter that lets you specify the fields to include in the URL if desired. Implements [YOCTO #12722]. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
-rw-r--r--layerindex/urls_branch.py5
-rw-r--r--layerindex/views.py22
-rw-r--r--templates/layerindex/detail.html14
3 files changed, 33 insertions, 8 deletions
diff --git a/layerindex/urls_branch.py b/layerindex/urls_branch.py
index 0e41435e76..2809147bca 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, ClassSearchView, 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, LayerDetailView, edit_layer_view, delete_layer_view, edit_layernote_view, delete_layernote_view, RedirectParamsView, DuplicatesView, LayerUpdateDetailView, layer_export_recipes_csv_view
urlpatterns = [
url(r'^$',
@@ -20,6 +20,9 @@ urlpatterns = [
LayerDetailView.as_view(
template_name='layerindex/detail.html'),
name='layer_item'),
+ url(r'^layer/(?P<slug>[-\w]+)/recipes/csv/$',
+ layer_export_recipes_csv_view,
+ name='layer_export_recipes_csv'),
url(r'^recipes/$',
RecipeSearchView.as_view(
template_name='layerindex/recipes.html'),
diff --git a/layerindex/views.py b/layerindex/views.py
index 0b3345a007..a905c347cc 100644
--- a/layerindex/views.py
+++ b/layerindex/views.py
@@ -1025,3 +1025,25 @@ class StatsView(TemplateView):
machine_count=Count('layerbranch__machine', distinct=True),
distro_count=Count('layerbranch__distro', distinct=True))
return context
+
+
+def layer_export_recipes_csv_view(request, branch, slug):
+ import csv
+ layer = get_object_or_404(LayerItem, name=slug)
+ layerbranch = layer.get_layerbranch(branch)
+
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment; filename="recipes_%s_%s.csv"' % (layer.name, layerbranch.branch.name)
+
+ fieldlist = request.GET.get('fields', 'pn,pv,license').split(',')
+ recipe_fields = [f.name for f in Recipe._meta.get_fields() if not (f.auto_created and f.is_relation)]
+ for field in fieldlist:
+ if field not in recipe_fields:
+ return HttpResponse('Field %s is invalid' % field)
+
+ writer = csv.writer(response)
+ for recipe in layerbranch.sorted_recipes():
+ values = [getattr(recipe, field) for field in fieldlist]
+ writer.writerow(values)
+
+ return response
diff --git a/templates/layerindex/detail.html b/templates/layerindex/detail.html
index 97363d591f..b68234f12b 100644
--- a/templates/layerindex/detail.html
+++ b/templates/layerindex/detail.html
@@ -210,13 +210,13 @@
<div class="navbar-inner">
<a class="brand pull-left">{{ layeritem.name }} recipes <span class="muted">({{ layerbranch.sorted_recipes.count }})</span></a>
- <ul class="nav pull-right">
- <li>
- <form action="" class="navbar-search pull-right" id="filter-form">
- <input type="text" placeholder="Search recipes" class="search-query" id="filter">
- </form>
- </li>
- </ul>
+ <div class="pull-right">
+ <a href="{% url 'layer_export_recipes_csv' layerbranch.branch.name layerbranch.layer.name %}" class="btn"><i class="icon-file"></i> Export CSV</a>
+
+ <form action="" class="navbar-search nav-spacer pull-right" id="filter-form">
+ <input type="text" placeholder="Search recipes" class="search-query" id="filter">
+ </form>
+ </div>
</div>
</div>