From b6b98ecaf16db9431ed3aa8ce0edabd4e09ac284 Mon Sep 17 00:00:00 2001 From: petercat12 Date: Fri, 28 Apr 2017 16:14:09 -0500 Subject: [PATCH 1/2] add csv download url --- django_version_viewer/pip_viewer.py | 15 ++++++++++++ .../templates/version_viewer.html | 3 ++- django_version_viewer/urls.py | 1 + django_version_viewer/views.py | 23 +++++++++++++++++-- 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/django_version_viewer/pip_viewer.py b/django_version_viewer/pip_viewer.py index f217da3..c42a0fd 100644 --- a/django_version_viewer/pip_viewer.py +++ b/django_version_viewer/pip_viewer.py @@ -3,6 +3,21 @@ def list_package_versions(): + """ + Returns a dict of installed pip packages + + {'package_name': "django", 'package_version': "1.8.18"} + """ installed_packages = pip.get_installed_distributions() results = [{"package_name": i.key, "package_version": i.version} for i in installed_packages] return sorted(results, key=itemgetter('package_name')) + + +def get_pip_packages_csv(writer): + """ + Takes a csv writer and writes installed pip packages to it. + """ + installed_packages = pip.get_installed_distributions() + for i in installed_packages: + writer.writerow([i.key, i.version]) + return writer diff --git a/django_version_viewer/templates/version_viewer.html b/django_version_viewer/templates/version_viewer.html index 8c66b1b..2d7a7bc 100644 --- a/django_version_viewer/templates/version_viewer.html +++ b/django_version_viewer/templates/version_viewer.html @@ -15,6 +15,7 @@