@@ -0,0 +1,1416 @@
+# -*- coding: utf-8 -*-%0A%0A# Akvo Reporting is covered by the GNU Affero General Public License.%0A# See more details in the license.txt file located at the root folder of the Akvo RSR module.%0A# For additional details on the GNU license please see %3C http://www.gnu.org/licenses/agpl.html %3E.%0A%0Afrom django.core.management.base import BaseCommand%0Afrom django.db.models import Count%0A%0Afrom ...models import IndicatorPeriod%0A%0A%0Aclass Command(BaseCommand):%0A%0A    args = '%5B%3Cproject_id%3E%5D'%0A    help = 'Script for recalculating periods which have children'%0A%0A    def handle(self, *args, **options):%0A%0A        # parse options%0A        verbosity = int(options%5B'verbosity'%5D)%0A%0A        if len(args) == 1:%0A            project_id = args%5B0%5D%0A        else:%0A            project_id = None%0A%0A        periods = IndicatorPeriod.objects%5C%0A                                 .annotate(child_count=Count('child_periods'))%5C%0A                                 .filter(child_count__gt=0)%0A%0A        if project_id:%0A            periods = periods.filter(indicator__result__project=project_id)%0A            if verbosity %3E 1:%0A                print('Recalculating periods on project %7B%7D'.format(project_id))%0A%0A        if verbosity %3E 1:%0A            print('Recalculating %7B%7D periods'.format(periods.count()))%0A%0A        for period in periods:%0A            if verbosity %3E 1:%0A                print('Recalculating period %7B%7D'.format(period.id))%0A            period.recalculate_period()%0A

Add a script to recalculate periods