# HG changeset patch # User Brian Neal # Date 1356107332 21600 # Node ID d6489e6a40f6b4b47921b25eb171ac4e609e6129 # Parent efac466a05d4188b4cc7683b3df6da743edbe277 Add an encoding header to the downloads category report. Added a --titles-only option to the downloads category report. diff -r efac466a05d4 -r d6489e6a40f6 downloads/management/commands/dlcatreport.py --- a/downloads/management/commands/dlcatreport.py Sun Dec 02 14:42:08 2012 -0600 +++ b/downloads/management/commands/dlcatreport.py Fri Dec 21 10:28:52 2012 -0600 @@ -3,16 +3,32 @@ in a given category. """ +from optparse import make_option + from django.core.management.base import LabelCommand, CommandError from django.template.loader import render_to_string 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" + option_list = LabelCommand.option_list + ( + make_option('--titles-only', + action='store_true', + default=False, + help='Output a text listing of titles only'), + ) + def handle_label(self, slug, **options): """ Render a template using the downloads in a given category and send it to @@ -27,6 +43,10 @@ downloads = Download.public_objects.filter(category=category).order_by( 'title').select_related() + if options.get('titles_only'): + print_titles(downloads) + return + report = render_to_string('downloads/commands/category_report.html', { 'category': category, 'downloads': downloads, diff -r efac466a05d4 -r d6489e6a40f6 sg101/templates/downloads/commands/category_report.html --- a/sg101/templates/downloads/commands/category_report.html Sun Dec 02 14:42:08 2012 -0600 +++ b/sg101/templates/downloads/commands/category_report.html Fri Dec 21 10:28:52 2012 -0600 @@ -1,6 +1,7 @@ + Download Report: {{ category.title }}