# HG changeset patch # User Brian Neal # Date 1640647826 21600 # Node ID cb712b2c34afd593489b083f48ef227d1d3ce8b2 # Parent a38ecbffbd5934a209c4a11f2de2228c156c03e6 Add JSON option to dlcatreport management command. diff -r a38ecbffbd59 -r cb712b2c34af downloads/management/commands/dlcatreport.py --- a/downloads/management/commands/dlcatreport.py Mon Dec 27 16:58:02 2021 -0600 +++ b/downloads/management/commands/dlcatreport.py Mon Dec 27 17:30:26 2021 -0600 @@ -5,6 +5,7 @@ """ from optparse import make_option +from django.core import serializers from django.core.management.base import LabelCommand, CommandError from django.template.loader import render_to_string @@ -20,6 +21,10 @@ action='store_true', default=False, help='Output a text listing of titles only'), + make_option('--json', + action='store_true', + default=False, + help='Output downloads in JSON format'), ) def handle_label(self, slug, **options): @@ -40,6 +45,10 @@ self.print_titles(downloads) return + if options.get('json'): + self.print_json(downloads) + return + report = render_to_string('downloads/commands/category_report.html', { 'category': category, 'downloads': downloads, @@ -53,4 +62,9 @@ for dl in dls: self.stdout.write(dl.title) + def print_json(self, dls): + """Output downloads in JSON format""" + data = serializers.serialize('json', dls) + self.stdout.write(data) +