diff downloads/management/commands/dlcatreport.py @ 684:161b56849114

For Django 1.5: management commands should use self.stdout, etc. for output. Note that I did not update the legacy commands since it is likely I will never run or test these commands again.
author Brian Neal <bgneal@gmail.com>
date Fri, 23 Aug 2013 19:17:40 -0500
parents d6489e6a40f6
children b59c154d0163
line wrap: on
line diff
--- a/downloads/management/commands/dlcatreport.py	Fri Aug 23 19:02:45 2013 -0500
+++ b/downloads/management/commands/dlcatreport.py	Fri Aug 23 19:17:40 2013 -0500
@@ -11,13 +11,6 @@
 from downloads.models import Category, Download
 
 
-def print_titles(dls):
-    """Print out the download titles"""
-
-    for dl in dls:
-        print dl.title.encode('utf-8')
-
-
 class Command(LabelCommand):
     help = "Produce on standard output a report of all downloads in a category."
     args = "category-slug"
@@ -44,7 +37,7 @@
                 'title').select_related()
 
         if options.get('titles_only'):
-            print_titles(downloads)
+            self.print_titles(downloads)
             return
 
         report = render_to_string('downloads/commands/category_report.html', {
@@ -54,5 +47,12 @@
 
         # encode it ourselves since it can fail if you try to redirect output to
         # a file and any of the content is not ASCII...
-        print report.encode('utf-8')
+        self.stdout.write(report.encode('utf-8'))
 
+    def print_titles(self, dls):
+        """Print out the download titles"""
+
+        for dl in dls:
+            self.stdout.write(dl.title.encode('utf-8'))
+
+