new_contents: # Generated by Django 2.2.10 on 2022-07-27 09:30
  
  import django.core.validators
  from django.db import migrations, models
  import django.db.models.deletion
  import urllib.request
  from django.core.files.uploadedfile import SimpleUploadedFile
  from urllib.parse import urlparse
  
  
  def set_home_community(apps, schema_editor):
      Program = apps.get_model('accelerator', 'Program')
      Community = apps.get_model('accelerator', 'Community')
  
      data = [{"name": "MC Switzerland",
               "email": "support.2622.15317b82e21677f6@helpscout.net",
               "is_default": True,
               "assignment_order": 1,
               "image": ("https://home-community-image.s3"
                         ".amazonaws.com/mc_images/mc_swiss.jpg"),
               "icon": ("https://home-community-image.s3"
                      ".amazonaws.com/icons/mc_swiss.png")
              },{
               "name": "MC Israel",
               "email": "support.2622.5304df655bf8538a@helpscout.net",
               "is_default": False,
               "assignment_order": 2,
               "image": ("https://home-community-image.s3"
                         ".amazonaws.com/mc_images/mc_israel.jpg"),
               "icon": ("https://home-community-image.s3"
                        ".amazonaws.com/icons/mc_israel.png")
              },{
               "name": "MC Mexico",
               "email": "support.2622.5012bf8e0f9cb2f7@helpscout.net",
               "is_default": False,
               "assignment_order": 3,
               "image": ("https://home-community-image.s3"
                         ".amazonaws.com/mc_images/mc_mexico.jpg"),
               "icon": ("https://home-community-image.s3"
                        ".amazonaws.com/icons/mc_mexico.png")
              },{
               'name': 'MC Bridge',
               "email": 'support.2622.1347a3fe9de0848d@helpscout.net',
               "is_default": False,
               "assignment_order": 4,
               "image": ("https://home-community-image.s3"
                         ".amazonaws.com/mc_images/mc_bridge.jpg"),
               "icon": ("https://home-community-image.s3"
                        ".amazonaws.com/icons/mc_bridge.png")
              },{
               "name": "MC United States",
               "email": "community@masschallenge.helpscoutapp.com",
               "is_default": False,
               "assignment_order": 5,
               "image": ("https://home-community-image.s3"
                         ".amazonaws.com/mc_images/mc_united_state.jpg"),
               "icon": ("https://home-community-image.s3"
                        ".amazonaws.com/icons/mc_usa.png")}]
      for item in data:
          image_name = urlparse(item['image']).path.split('/')[-1]
          image_tmpfile, _ = urllib.request.urlretrieve(item['image'])
  
          icon_name = urlparse(item['icon']).path.split('/')[-1]
          icon_tmpfile, _ = urllib.request.urlretrieve(item['icon'])
  
          community = Community()
          community.name = item['name']
          community.is_default = item['is_default']
          community.is_visible = True
          community.assignment_order = item['assignment_order']
          community.image = SimpleUploadedFile(image_name, open(image_tmpfile, "rb").read())
          community.icon = SimpleUploadedFile(icon_name, open(icon_tmpfile, "rb").read())
          community.save()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('accelerator', '0115_add_ecosystem_model'),
      ]
  
      operations = [
          migrations.RemoveField(
              model_name='programfamily',
              name='home_community',
          ),
          migrations.AddField(
              model_name='program',
              name='home_community',
              field=models.ForeignKey(
                  blank=True,
                  null=True,
                  on_delete=django.db.models.deletion.SET_NULL,
                  to='accelerator.Community',
                  verbose_name='home community'),
          ),
          migrations.RunPython(set_home_community,
                               migrations.RunPython.noop)
  
      ]
  
subject: Add home community migrations