Skip to content

Commit

Permalink
feat: toward #17 and #21, survey models, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
erictheise committed May 18, 2020
1 parent e984a12 commit 8add98c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions mdi/migrations/0068_survey_to_models_manytomany.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Generated by Django 3.0.3 on 2020-05-17 22:33

from django.db import migrations
from django.core.exceptions import ObjectDoesNotExist
from mdi.models import Organization, LegalStatus, Sector, Challenge
from surveys.models import Ecosystem2020
from django.contrib.auth import get_user_model


def forward(apps, schema_editor):
for organization in Organization.objects.filter(created_at__gt='2020-03-14 22:43:01.000000'):
print("\nname: {} email: {}".format(organization.name, organization.admin_email))
survey = Ecosystem2020.objects.filter(a__range=(organization.created_at,organization.created_at)).get(f=organization.name)

# LegalStatus
for legal_status in survey.y.split(', '):
if legal_status != '' and legal_status != None:
l = ''
try:
l = LegalStatus.objects.get(name=legal_status)
print(" status_id: {} status: {}".format(l.id, l.name))
organization.legal_status.add(l)
except ObjectDoesNotExist:
print(" status_huh? {}".format(legal_status))
l = LegalStatus(name=legal_status, order=9999)
l.save()
organization.legal_status.add(l)

# Sector
for sector in survey.al.split(', '):
if sector != '' and sector != None and sector != 'fundraising' and sector != 'Technology':
sector = sector.replace('Technology-', 'Technology:')
sector = sector.replace('Art/Artistic Production', 'Art')
s = ''
try:
s = Sector.objects.get(name=sector)
print(" sector_id: {} sector: {}".format(s.id, s.name))
organization.sectors.add(s)
except ObjectDoesNotExist:
print(" sector_huh? {}".format(sector))

# Challenges
challenge = survey.ae
if challenge != '' and challenge != None:
c = ''
try:
c = Challenge.objects.get(name=challenge)
print(" challenge_id: {} challenge: {}".format(c.id, c.name))
except ObjectDoesNotExist:
print(" challenge_huh? {}".format(challenge))
c = Challenge(name=challenge, order=9999)
c.save()
organization.challenges.add(c)


class Migration(migrations.Migration):

dependencies = [
('mdi', '0067_auto_20200517_0503'),
]

operations = [
migrations.RunPython(forward)
]

0 comments on commit 8add98c

Please sign in to comment.