@@ -0,0 +1,2446 @@
+import csv%0Afrom django.core.management.base import BaseCommand%0Afrom corehq.apps.locations.models import SQLLocation%0Afrom custom.enikshay.integrations.bets.repeaters import BETSLocationRepeater%0A%0A%0Aclass Command(BaseCommand):%0A%0A    def add_arguments(self, parser):%0A        parser.add_argument('domain')%0A%0A    def handle(self, domain, **options):%0A        self.domain = domain%0A        filename = 'eNikshay_locations.csv'%0A        with open(filename, 'w') as f:%0A            writer = csv.writer(f)%0A            writer.writerow(%5B%0A                'name',%0A                'site_code',%0A                'location_id',%0A                'doc_type',%0A                'domain',%0A                'external_id',%0A                'is_archived',%0A                'last_modified',%0A                'latitude',%0A                'longitude',%0A                # TODO exactly which metadata fields do they want? How do we%0A                # serialize the headers, metadata.is_test?%0A                # 'metadata',%0A                'location_type',%0A                'location_type_code',%0A                'parent_location_id',%0A                'parent_site_code',%0A                # They may also want ancestors_by_type, TBD%0A            %5D)%0A            loc_types = BETSLocationRepeater.location_types_to_forward%0A            for loc in (SQLLocation.active_objects%0A                        .filter(domain=domain, location_type__name__in=loc_types)%0A                        .prefetch_related('parent', 'location_type')):%0A                self.add_loc(loc, writer)%0A        print %22Wrote to %7B%7D%22.format(filename)%0A%0A    def add_loc(self, location, writer):%0A        if location.metadata.get('is_test') != %22yes%22:%0A            return%0A%0A        writer.writerow(%5B%0A            location.name,%0A            location.site_code,%0A            location.location_id,%0A            'Location',%0A            location.domain,%0A            location.external_id,%0A            location.is_archived,%0A            location.last_modified.isoformat(),%0A            float(location.latitude) if location.latitude else None,%0A            float(location.longitude) if location.longitude else None,%0A            # location.metadata,%0A            location.location_type.name,%0A            location.location_type.code,%0A            location.parent_location_id,%0A            location.parent.site_code,%0A            # They may also want ancestors_by_type, if so, use%0A            # custom.enikshay.integrations.bets.utils.get_bets_location_json%0A        %5D)%0A

Add first pass at BETS location dump