Esempio n. 1
0
    def handle(self, *args, **options):

        self.stdout.write("Pulling stuff\n")
        beneficiaries = CommCareCase.get_all_cases('opm', include_docs=True)
        users = CommCareUser.by_domain('opm')
        fixtures = FixtureDataItem.get_item_list('opm', 'condition_amounts')
        # you won't be able to get the fixtures without the FixtureDataType
        fixtures.append(FixtureDataType.by_domain_tag('opm',
            'condition_amounts').one())
        forms = []

        for b in beneficiaries:
            forms += b.get_forms()

        test_data = []

        month, year = test_month_year
        for report_class in [IncentivePaymentReport, BeneficiaryPaymentReport]:
            self.stdout.write("Running %s\n" % report_class.__name__)
            report = get_report(report_class, month, year)
            snapshot = OpmReportSnapshot(
                domain=DOMAIN,
                month=month,
                year=year,
                report_class=report.report_class.__name__,
                headers=report.headers,
                slugs=report.slugs,
                rows=report.rows,
            )
            test_data.append(snapshot.to_json())

        self.stdout.write("Saving raw data\n")
        test_data += [form.to_json() for form in forms]
        test_data += [u.to_json() for u in users]
        test_data += [b.to_json() for b in beneficiaries]
        test_data += [f.to_json() for f in fixtures]

        doc_ids = set()
        docs = []
        for doc in test_data:
            if doc.get('_id') not in doc_ids:
                for attrib in ['_rev', '_attachments']:
                    try:
                        del doc[attrib]
                    except KeyError:
                        pass                
                doc_ids.add(doc.get('_id', 'null'))
                docs.append(doc)
            else:
                self.stdout.write("Ignoring duplicates\n")

        with open(test_data_location, 'w') as f:
            f.write(json.dumps(docs, indent=2))
            
        self.stdout.write("Pulled stuff, let's hope it worked\n")
Esempio n. 2
0
 def get_rows(self, datespan):
     return CommCareCase.get_all_cases(DOMAIN, include_docs=True)