@@ -38,7 +39,7 @@
Versions
var packages;
$.ajax({
type: "GET",
- url: {% url "django_version_viewer" %},
+ url: "{% url 'django_version_viewer' %}",
csrfmiddlewaretoken: '{{ csrf_token }}',
success: function(data){
packages = data;
diff --git a/django_version_viewer/urls.py b/django_version_viewer/urls.py
index ea076e5..30bef84 100644
--- a/django_version_viewer/urls.py
+++ b/django_version_viewer/urls.py
@@ -9,4 +9,5 @@
urlpatterns = [
url(r'^$', views.DjangoVersionViewer.as_view(), name='django_version_viewer'),
+ url(r'^csv/$', views.DjangoVersionViewerCSV.as_view(), name='django_version_viewer_csv')
]
diff --git a/django_version_viewer/views.py b/django_version_viewer/views.py
index e72e49d..f8b85f8 100644
--- a/django_version_viewer/views.py
+++ b/django_version_viewer/views.py
@@ -1,11 +1,14 @@
+import json
+import csv
+
from pydoc import locate
from django.http import HttpResponse
from django.conf import settings
from django.core.exceptions import PermissionDenied
-from pip_viewer import list_package_versions
from django.views.generic import View
-import json
+
+from pip_viewer import list_package_versions, get_pip_packages_csv
accessor_class = locate(
getattr(settings, 'ACCESSOR_CLASS_PATH', 'django_version_viewer.mixins.Accessor'))
@@ -19,3 +22,19 @@ def get(self, request, *args, **kwargs):
raise PermissionDenied
packages = list_package_versions()
return HttpResponse(json.dumps(packages), status=200, content_type="application/json")
+
+
+class DjangoVersionViewerCSV(View):
+
+ def get(self, request, *args, **kwargs):
+ if not accessor.allow_access(request):
+ raise PermissionDenied
+ response = HttpResponse(content_type='text/csv')
+ response['Content-Disposition'] = 'attachment; filename="pip_package_versions.csv"'
+
+ fieldnames = ['Package Name', 'Package Version']
+ writer = csv.writer(response)
+
+ writer.writerow(fieldnames)
+ get_pip_packages_csv(writer)
+ return response
diff --git a/example18/templates/admin/base.html b/example18/templates/admin/base.html
deleted file mode 100644
index f60f3d5..0000000
--- a/example18/templates/admin/base.html
+++ /dev/null
@@ -1,92 +0,0 @@
-{% load i18n admin_static pip_version_viewer_tags %}
-{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
-
-
-
{% block title %}{% endblock %}
-
-
-{% block extrastyle %}{% endblock %}
-
-{% if LANGUAGE_BIDI %}
{% endif %}
-
-
-
-
-{% block extrahead %}{% endblock %}
-{% block blockbots %}
{% endblock %}
-
-{% load i18n %}
-
-
-
-
-
- {% if not is_popup %}
-
-
-
- {% block breadcrumbs %}
-
- {% endblock %}
- {% endif %}
-
- {% block messages %}
- {% if messages %}
-
{% for message in messages %}
- - {{ message|capfirst }}
- {% endfor %}
- {% endif %}
- {% endblock messages %}
-
-
-
- {% block pretitle %}{% show_pip_package_versions %}{% endblock %}
- {% block content_title %}{% if title %}
{{ title }}
{% endif %}{% endblock %}
- {% block content %}
- {% block object-tools %}{% endblock %}
- {{ content }}
- {% endblock %}
- {% block sidebar %}{% endblock %}
-
-
-
-
- {% block footer %}{% endblock %}
-
-
-
-
-
diff --git a/example18/templates/admin/base_site.html b/example18/templates/admin/base_site.html
new file mode 100644
index 0000000..5a012bd
--- /dev/null
+++ b/example18/templates/admin/base_site.html
@@ -0,0 +1,11 @@
+{% extends "admin/base.html" %}
+{% load i18n pip_version_viewer_tags %}
+
+{% block extrahead %}
+
+
+
+{% endblock %}
+{% block pretitle %}
+ {% show_pip_package_versions %}
+{% endblock %}