Improve handling of invalid branch in layer CSV export view

On layers.openembedded.org we're seeing requests from some search engine
crawlers requesting the CSV export URL with an invalid branch for the
layer. I couldn't see the referer anywhere in the logs but I suspect it
has to do with some recent cleanup work I did in the database where I
deleted some invalid LayerBranch records - they were probably following
links in a cached version of the webpage. In any event we want to return
404 in this situation rather than an internal server error.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2018-10-04 08:43:02 +13:00
parent a7820077b0
commit f76e811403

View File

@ -1323,6 +1323,8 @@ def layer_export_recipes_csv_view(request, branch, slug):
import csv import csv
layer = get_object_or_404(LayerItem, name=slug) layer = get_object_or_404(LayerItem, name=slug)
layerbranch = layer.get_layerbranch(branch) layerbranch = layer.get_layerbranch(branch)
if not layerbranch:
raise Http404
response = HttpResponse(content_type='text/csv') response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="recipes_%s_%s.csv"' % (layer.name, layerbranch.branch.name) response['Content-Disposition'] = 'attachment; filename="recipes_%s_%s.csv"' % (layer.name, layerbranch.branch.name)