|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +import sys, os, re, datetime, pytz |
| 4 | + |
| 5 | +basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")) |
| 6 | +sys.path = [ basedir ] + sys.path |
| 7 | + |
| 8 | +from ietf import settings |
| 9 | +settings.USE_DB_REDESIGN_PROXY_CLASSES = False |
| 10 | +settings.IMPORTING_FROM_OLD_SCHEMA = True |
| 11 | + |
| 12 | +from django.core import management |
| 13 | +management.setup_environ(settings) |
| 14 | + |
| 15 | +from django.template.defaultfilters import slugify |
| 16 | + |
| 17 | +from ietf.idtracker.models import AreaDirector, IETFWG, Acronym, IRTF |
| 18 | +from ietf.liaisons.models import * |
| 19 | +from redesign.person.models import * |
| 20 | +from redesign.importing.utils import get_or_create_email, old_person_to_person |
| 21 | +from redesign.name.models import * |
| 22 | +from redesign.name.utils import name |
| 23 | + |
| 24 | + |
| 25 | +# imports LiaisonDetail, OutgoingLiaisonApproval, Uploads |
| 26 | + |
| 27 | +# todo: LiaisonStatementManager, LiaisonManagers, SDOAuthorizedIndividual |
| 28 | + |
| 29 | +# assumptions: |
| 30 | +# - persons have been imported |
| 31 | +# - groups have been imported |
| 32 | + |
| 33 | +purpose_mapping = { |
| 34 | + 1: name(LiaisonStatementPurposeName, "action", "For action"), |
| 35 | + 2: name(LiaisonStatementPurposeName, "comment", "For comment"), |
| 36 | + 3: name(LiaisonStatementPurposeName, "info", "For information"), |
| 37 | + 4: name(LiaisonStatementPurposeName, "response", "In response"), |
| 38 | + 5: name(LiaisonStatementPurposeName, "other", "Other"), |
| 39 | + } |
| 40 | + |
| 41 | +purpose_mapping[None] = purpose_mapping[3] # map unknown to "For information" |
| 42 | + |
| 43 | +system_person = Person.objects.get(name="(System)") |
| 44 | +obviously_bogus_date = datetime.date(1970, 1, 1) |
| 45 | + |
| 46 | +bodies = { |
| 47 | + 'IESG': Group.objects.get(acronym="iesg"), |
| 48 | + 'IETF': Group.objects.get(acronym="ietf"), |
| 49 | + 'IAB/ISOC': Group.objects.get(acronym="iab"), |
| 50 | + 'IAB/IESG': Group.objects.get(acronym="iab"), |
| 51 | + 'IAB': Group.objects.get(acronym="iab"), |
| 52 | + 'IETF Transport Directorate': Group.objects.get(acronym="tsvdir"), |
| 53 | + 'Sigtran': Group.objects.get(acronym="sigtran", type="wg"), |
| 54 | + 'IETF RAI WG': Group.objects.get(acronym="rai", type="area"), |
| 55 | + 'IETF Mobile IP WG': Group.objects.get(acronym="mobileip", type="wg"), |
| 56 | + } |
| 57 | + |
| 58 | +def get_from_body(name): |
| 59 | + # the from body name is a nice case study in how inconsistencies |
| 60 | + # build up over time |
| 61 | + b = bodies.get(name) |
| 62 | + t = name.split() |
| 63 | + if not b and name.startswith("IETF"): |
| 64 | + if len(t) < 3 or t[2].lower() == "wg": |
| 65 | + b = lookup_group(acronym=t[1].lower(), type="wg") |
| 66 | + elif t[2].lower() in ("area", "ad"): |
| 67 | + print "inside AREA" |
| 68 | + b = lookup_group(acronym=t[1].lower(), type="area") |
| 69 | + if not b: |
| 70 | + b = lookup_group(name=u"%s %s" % (t[1], t[2]), type="area") |
| 71 | + |
| 72 | + if not b and name.endswith(" WG"): |
| 73 | + b = lookup_group(acronym=t[-2].lower(), type="wg") |
| 74 | + |
| 75 | + if not b: |
| 76 | + b = lookup_group(name=name, type="sdo") |
| 77 | + |
| 78 | + return b |
| 79 | + |
| 80 | +for o in LiaisonDetail.objects.all().order_by("pk"):#[:10]: |
| 81 | + print "importing LiaisonDetail", o.pk |
| 82 | + |
| 83 | + try: |
| 84 | + l = LiaisonStatement.objects.get(pk=o.pk) |
| 85 | + except LiaisonStatement.DoesNotExist: |
| 86 | + l = LiaisonStatement(pk=o.pk) |
| 87 | + |
| 88 | + l.title = (o.title or "").strip() |
| 89 | + l.purpose = purpose_mapping[o.purpose_id] |
| 90 | + if o.purpose_text and not o.purpose and "action" in o.purpose_text.lower(): |
| 91 | + o.purpose = purpose_mapping[1] |
| 92 | + l.body = (o.body or "").strip() |
| 93 | + l.deadline = o.deadline_date |
| 94 | + |
| 95 | + l.related_to_id = o.related_to_id # should not dangle as we process ids in turn |
| 96 | + |
| 97 | + def lookup_group(**kwargs): |
| 98 | + try: |
| 99 | + return Group.objects.get(**kwargs) |
| 100 | + except Group.DoesNotExist: |
| 101 | + return None |
| 102 | + |
| 103 | + l.from_name = o.from_body() |
| 104 | + l.from_body = get_from_body(l.from_name) # try to establish link |
| 105 | + continue |
| 106 | + |
| 107 | + l.to_body = o.to_raw_body |
| 108 | + l.to_name = o.to_raw_body |
| 109 | + l.to_contact = (o.to_poc or "").strip() |
| 110 | + |
| 111 | + l.reply_to = (o.replyto or "").strip() |
| 112 | + |
| 113 | + l.response_contact = (o.response_contact or "").strip() |
| 114 | + l.technical_contact = (o.technical_contact or "").strip() |
| 115 | + l.cc = (o.cc1 or "").strip() |
| 116 | + |
| 117 | + l.submitted = o.submitted_date |
| 118 | + l.submitted_by = old_person_to_person(o.person) |
| 119 | + l.modified = o.last_modified_date |
| 120 | + l.approved = o.approval and o.approval.approved and (o.approval.approval_date or l.modified or datetime.datetime.now()) |
| 121 | + |
| 122 | + l.action_taken = o.action_taken |
| 123 | + |
| 124 | + #l.save() |
0 commit comments