@staticmethod
    @task
    def plan2index (plan):
        status = DistrictFile.get_file_status(plan)
        while status == 'pending':
            time.sleep(15)
            status = DistrictFile.get_file_status(plan)
        if status == 'none':
            pending = DistrictFile.get_file_name(plan) + '_pending.zip'
            archive = open(pending, 'w')
            f = tempfile.NamedTemporaryFile(delete=False)
            try:
                units = plan.get_base_geounits()

                # csv layout: portable id, district id, num members, label, types, comments
                # the final three are only written when the plan is a community
                if not plan.is_community():
                    mapping = [(pid, did, members) for (gid, pid, did, members) in units]
                else:
                    # create a map of district_id -> tuple of community details
                    dm = {}
                    ct = ContentType.objects.get(app_label='redistricting',model='district')
                    for district in plan.get_districts_at_version(plan.version, include_geom=False):
                        if district.district_id > 0:
                            types = Tag.objects.get_for_object(district).filter(name__startswith='type=')
                            types = '|'.join([t.name[5:] for t in types])
                            comments = Comment.objects.filter(object_pk__in=[str(district.id)],content_type=ct)
                            comments = comments[0].comment if len(comments) > 0 else ''
                            dm[district.district_id] = (district.long_label, types, comments)
                    mapping = [(pid, did, members, dm[did][0], dm[did][1], dm[did][2]) for (gid, pid, did, members) in units]
                
                difile = csv.writer(f)
                difile.writerows(mapping)
                f.close()

                # Zip up the file 
                zipwriter = zipfile.ZipFile(archive, 'w', zipfile.ZIP_DEFLATED)
                zipwriter.write(f.name, plan.get_friendly_name() + '.csv')
                zipwriter.close()
                archive.close()
                os.rename(archive.name, DistrictFile.get_file_name(plan) + '.zip')
            except Exception, ex:
                logger.warn('The plan "%s" could not be serialized to a district index file', plan.name)
                logger.debug('Reason:', ex)
                os.unlink(archive.name)
            # delete the temporary csv file
            finally:
                os.unlink(f.name)

        return DistrictFile.get_file(plan)
Gets a zipped copy of the district index file for the
dataset/ETHPy150Open PublicMapping/DistrictBuilder/django/publicmapping/redistricting/tasks.py/DistrictIndexFile.plan2index