From ccc1fa775b0b5aa2f4760509c7696d3ea712a94d Mon Sep 17 00:00:00 2001 From: Paul Eggleton Date: Wed, 20 Oct 2021 11:07:46 +1300 Subject: [PATCH] Report charset for text & CSV views I noticed in the branch comparison plain text view ("Plain text" button in the Tools -> Branch Comparison page) that in current versions of Firefox the ellipses were coming through corrupted, though they looked fine in the HTML version, and it turns out this is because I wasn't specifying a character set encoding. It should be UTF-8, so add a charset to the content type stating as such for this and other similar views. Signed-off-by: Paul Eggleton --- layerindex/urls.py | 4 ++-- layerindex/views.py | 2 +- rrs/views.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/layerindex/urls.py b/layerindex/urls.py index 7264b11..45dbd3c 100644 --- a/layerindex/urls.py +++ b/layerindex/urls.py @@ -157,7 +157,7 @@ urlpatterns = [ ClassicRecipeSearchView.as_view( template_name='layerindex/classicrecipes_csv.txt', paginate_by=0, - content_type='text/csv'), + content_type='text/csv; charset=utf-8'), name='comparison_recipe_search_csv'), url(r'^comparison/stats/(?P[-.\w]+)/$', ClassicRecipeStatsView.as_view( @@ -194,7 +194,7 @@ urlpatterns = [ name='branch_comparison'), url(r'^branch_comparison_plain/$', BranchCompareView.as_view( - content_type='text/plain', + content_type='text/plain; charset=utf-8', template_name='layerindex/branchcompare_plain.txt'), name='branch_comparison_plain'), url(r'^recipe_deps/$', diff --git a/layerindex/views.py b/layerindex/views.py index 91b3280..6f22c0c 100644 --- a/layerindex/views.py +++ b/layerindex/views.py @@ -1493,7 +1493,7 @@ def layer_export_recipes_csv_view(request, branch, slug): if not layerbranch: raise Http404 - response = HttpResponse(content_type='text/csv') + response = HttpResponse(content_type='text/csv; charset=utf-8') response['Content-Disposition'] = 'attachment; filename="recipes_%s_%s.csv"' % (layer.name, layerbranch.branch.name) fieldlist = request.GET.get('fields', 'pn,pv,license').split(',') diff --git a/rrs/views.py b/rrs/views.py index 6c73866..0374f5a 100644 --- a/rrs/views.py +++ b/rrs/views.py @@ -607,7 +607,7 @@ def recipes_report(request, maintplan_name, release_name, milestone_name): recipe_list = _get_recipe_list(milestone) - response = HttpResponse(content_type='text/csv') + response = HttpResponse(content_type='text/csv; charset=utf-8') response['Content-Disposition'] = 'attachment; filename="%s_%s.csv"' % ( release_name , milestone_name)