Browse Source

Don't output anything if a command does nothing (useful for cron, to avoid sending emails)

Baptiste Jonglez 10 years ago
parent
commit
41e51c7508

+ 6 - 4
coin/billing/management/commands/charge_subscriptions.py

@@ -20,11 +20,13 @@ class Command(BaseCommand):
             raise CommandError(
                 'Please enter a valid date : YYYY-mm-dd (ex: 2011-07-04)')
 
-        self.stdout.write(
-            'Create invoices for all members for the date : %s' % date)
+        if options['verbosity'] >= 2:
+            self.stdout.write(
+                'Create invoices for all members for the date : %s' % date)
         with respect_language(settings.LANGUAGE_CODE):
             invoices = create_all_members_invoices_for_a_period(date)
 
-        self.stdout.write(
-            u'%d invoices were created' % len(invoices))
+        if invoices > 0 or options['verbosity'] >= 2:
+            self.stdout.write(
+                u'%d invoices were created' % len(invoices))
 

+ 10 - 7
coin/members/management/commands/call_for_membership_fees.py

@@ -35,15 +35,17 @@ class Command(BaseCommand):
                      date,
                      date + relativedelta(months=+1)]
 
-        self.stdout.write("Selecting members whose membership fee end at the "
-                          "following dates : {dates}".format(
-                              dates=[str(d) for d in end_dates]))
+        if options['verbosity'] >= 2:
+            self.stdout.write("Selecting members whose membership fee end at "
+                              "the following dates : {dates}".format(
+                                  dates=[str(d) for d in end_dates]))
 
         members = Member.objects.filter(status='member')\
                                 .annotate(end=Max('membership_fees__end_date'))\
                                 .filter(end__in=end_dates)
-        self.stdout.write(
-            "Got {number} members.".format(number=members.count()))
+        if options['verbosity'] >= 2:
+            self.stdout.write(
+                "Got {number} members.".format(number=members.count()))
 
         cpt = 0
         with respect_language(settings.LANGUAGE_CODE):
@@ -54,5 +56,6 @@ class Command(BaseCommand):
                             member=member, email=member.email))
                     cpt = cpt + 1
 
-        self.stdout.write("{number} call for membership fees emails were "
-                          "sent".format(number=cpt))
+        if cpt > 0 or options['verbosity'] >= 2:
+            self.stdout.write("{number} call for membership fees emails were "
+                              "sent".format(number=cpt))