Exemple #1
0
 def setUpClass(cls):
     cls.domain = 'skbanskdjoasdkng'
     cls.cases = [
         CommCareCase(name='A', domain=cls.domain),
         CommCareCase(name='B', domain=cls.domain),
         CommCareCase(name='C', domain=cls.domain),
         CommCareCase(name='D', domain=cls.domain),
         CommCareCase(name='X', domain='bunny'),
     ]
     CommCareCase.get_db().bulk_save(cls.cases)
     cls.case_groups = [
         CommCareCaseGroup(name='alpha',
                           domain=cls.domain,
                           cases=[cls.cases[0]._id, cls.cases[1]._id]),
         CommCareCaseGroup(name='beta',
                           domain=cls.domain,
                           cases=[cls.cases[2]._id, cls.cases[3]._id]),
         CommCareCaseGroup(name='gamma',
                           domain=cls.domain,
                           cases=[cls.cases[0]._id, cls.cases[3]._id]),
         CommCareCaseGroup(name='delta',
                           domain=cls.domain,
                           cases=[cls.cases[1]._id, cls.cases[2]._id]),
     ]
     CommCareCaseGroup.get_db().bulk_save(cls.case_groups)
    def handle(self, *labels, **options):
        existing_samples = CommCareCaseGroup.get_db().view(
            'reminders/sample_by_domain',
            startkey=[],
            endkey=[{}],
            include_docs=True
        ).all()

        print "Found %d SurveySamples to migrate..." % len(existing_samples)
        print "Migrating"

        for sample in existing_samples:
            try:
                sample_doc = sample["doc"]
                sample_doc["timezone"] = sample_doc.get("time_zone")
                del sample_doc["time_zone"]
                sample_doc["cases"] = sample_doc.get("contacts", [])
                del sample_doc["contacts"]
                sample_doc["doc_type"] = CommCareCaseGroup.__name__

                case_group = CommCareCaseGroup.wrap(sample_doc)
                case_group.save()
                sys.stdout.write('.')
            except Exception:
                sys.stdout.write('!')
            sys.stdout.flush()

        print "\nMigration complete."
def get_number_of_case_groups_in_domain(domain):
    data = CommCareCaseGroup.get_db().view(
        'casegroups/groups_by_domain',
        startkey=[domain],
        endkey=[domain, {}],
        reduce=True
    ).first()
    return data['value'] if data else 0
Exemple #4
0
 def setUpClass(cls):
     cls.domain = 'skbanskdjoasdkng'
     cls.cases = [
         CommCareCase(name='A', domain=cls.domain),
         CommCareCase(name='B', domain=cls.domain),
         CommCareCase(name='C', domain=cls.domain),
         CommCareCase(name='D', domain=cls.domain),
         CommCareCase(name='X', domain='bunny'),
     ]
     CommCareCase.get_db().bulk_save(cls.cases)
     cls.case_groups = [
         CommCareCaseGroup(name='alpha', domain=cls.domain,
                           cases=[cls.cases[0]._id, cls.cases[1]._id]),
         CommCareCaseGroup(name='beta', domain=cls.domain,
                           cases=[cls.cases[2]._id, cls.cases[3]._id]),
         CommCareCaseGroup(name='gamma', domain=cls.domain,
                           cases=[cls.cases[0]._id, cls.cases[3]._id]),
         CommCareCaseGroup(name='delta', domain=cls.domain,
                           cases=[cls.cases[1]._id, cls.cases[2]._id]),
     ]
     CommCareCaseGroup.get_db().bulk_save(cls.case_groups)
Exemple #5
0
 def tearDownClass(cls):
     CommCareCase.get_db().bulk_delete(cls.cases)
     CommCareCaseGroup.get_db().bulk_delete(cls.case_groups)
Exemple #6
0
def get_number_of_case_groups_in_domain(domain):
    data = CommCareCaseGroup.get_db().view('casegroups/groups_by_domain',
                                           startkey=[domain],
                                           endkey=[domain, {}],
                                           reduce=True).first()
    return data['value'] if data else 0
Exemple #7
0
 def tearDownClass(cls):
     CommCareCase.get_db().bulk_delete(cls.cases)
     CommCareCaseGroup.get_db().bulk_delete(cls.case_groups)
Exemple #8
0
 def tearDownClass(cls):
     CommCareCase.get_db().bulk_delete(cls.cases)
     CommCareCaseGroup.get_db().bulk_delete(cls.case_groups)
     super(DBAccessorsTest, cls).tearDownClass()
Exemple #9
0
 def tearDownClass(cls):
     CommCareCase.get_db().bulk_delete(cls.cases)
     CommCareCaseGroup.get_db().bulk_delete(cls.case_groups)
     super(DBAccessorsTest, cls).tearDownClass()