changeset 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 c83d330cb65f
children a75554eb6bae
files donations/management/commands/donations_report.py downloads/management/commands/dlcatreport.py downloads/management/commands/dlwgetcat.py
diffstat 3 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/donations/management/commands/donations_report.py	Fri Aug 23 19:02:45 2013 -0500
+++ b/donations/management/commands/donations_report.py	Fri Aug 23 19:17:40 2013 -0500
@@ -32,9 +32,9 @@
 
         max_month = 12 if year != today.year else today.month
 
-        print ROW_FMT % ('Month', 'Gross', 'Net')
+        self.stdout.write(ROW_FMT % ('Month', 'Gross', 'Net'))
         sep = ROW_FMT % ('-' * 10, '-' * 7, '-' * 7)
-        print sep
+        self.stdout.write(sep)
 
         total_gross = decimal.Decimal()
         total_net = decimal.Decimal()
@@ -54,10 +54,10 @@
 
             d = datetime.date(year=year, month=month, day=1)
 
-            print ROW_FMT % (d.strftime('%b %Y'), gross, net)
+            self.stdout.write(ROW_FMT % (d.strftime('%b %Y'), gross, net))
 
             total_gross += gross
             total_net += net
 
-        print sep
-        print ROW_FMT % ('Total:', total_gross, total_net)
+        self.stdout.write(sep)
+        self.stdout.write(ROW_FMT % ('Total:', total_gross, total_net))
--- 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'))
+
+
--- a/downloads/management/commands/dlwgetcat.py	Fri Aug 23 19:02:45 2013 -0500
+++ b/downloads/management/commands/dlwgetcat.py	Fri Aug 23 19:17:40 2013 -0500
@@ -17,7 +17,7 @@
 class Command(LabelCommand):
     help = ("Produce on standard output a bash script that wgets all the files"
             " in a category. The files are downloaded with a slugified name.")
-    
+
     args = "category-slug"
 
     def handle_label(self, slug, **options):
@@ -50,4 +50,4 @@
 
         # 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 output.encode('utf-8')
+        self.stdout.write(output.encode('utf-8'))