old_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.10.8 on 2017-12-11 09:38
  from __future__ import unicode_literals
  import urllib2
  
  from django.core.files import File
  from django.core.files.temp import NamedTemporaryFile
  from django.db import migrations, connection
  
  
  def scrape_mail_logo(apps, schema_editor):
      Client = apps.get_model('clients', 'Client')
      tenant = Client.objects.get(schema_name=connection.tenant.schema_name)
      if 'localhost' in tenant.domain_url:
          logo_url = 'http://' + tenant.domain_url + ':4200/images/logo-email.gif'
      else:
          logo_url = 'https://' + tenant.domain_url + '/images/logo-email.gif'
      MailPlatformSettings = apps.get_model('mails', 'MailPlatformSettings')
  
      from django.core.files import File
  
      img_temp = NamedTemporaryFile(delete=True)
      img_temp.write(urllib2.urlopen(logo_url).read())
      img_temp.flush()
  
      mail_settings, _ = MailPlatformSettings.objects.get_or_create()
      mail_settings.email_logo.save('logo-email.gif', File(img_temp))
  
  
  def backward(apps, schema_editor):
      pass
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('mails', '0001_initial'),
      ]
  
      operations = [
          migrations.RunPython(scrape_mail_logo, backward)
      ]
  
new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.10.8 on 2017-12-11 09:38
  from __future__ import unicode_literals
  import urllib2
  
  from django.core.files import File
  from django.core.files.temp import NamedTemporaryFile
  from django.db import migrations, connection
  
  
  def scrape_mail_logo(apps, schema_editor):
      Client = apps.get_model('clients', 'Client')
      tenant = Client.objects.get(schema_name=connection.tenant.schema_name)
      if 'localhost' in tenant.domain_url:
          logo_url = 'http://' + tenant.domain_url + ':4200/images/logo-email.gif'
      else:
          logo_url = 'https://' + tenant.domain_url + '/images/logo-email.gif'
      MailPlatformSettings = apps.get_model('mails', 'MailPlatformSettings')
  
      from django.core.files import File
  
      try:
          img_temp = NamedTemporaryFile(delete=True)
          img_temp.write(urllib2.urlopen(logo_url).read())
          img_temp.flush()
  
          mail_settings, _ = MailPlatformSettings.objects.get_or_create()
          mail_settings.email_logo.save('logo-email.gif', File(img_temp))
      except urllib2.URLError:
          pass
  
  
  def backward(apps, schema_editor):
      pass
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('mails', '0001_initial'),
      ]
  
      operations = [
          migrations.RunPython(scrape_mail_logo, backward)
      ]
  
subject: Fix migration for tests