forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport-persons.py
More file actions
executable file
·195 lines (147 loc) · 7.17 KB
/
import-persons.py
File metadata and controls
executable file
·195 lines (147 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/python
import sys, os, re, datetime
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
sys.path = [ basedir ] + sys.path
from ietf import settings
settings.USE_DB_REDESIGN_PROXY_CLASSES = False
from django.core import management
management.setup_environ(settings)
from ietf.idtracker.models import IESGLogin, AreaDirector, IETFWG, PersonOrOrgInfo, IDAuthor
from ietf.ietfauth.models import LegacyWgPassword, LegacyLiaisonUser
from ietf.liaisons.models import LiaisonDetail, LiaisonManagers, SDOAuthorizedIndividual
from ietf.person.models import *
from redesign.importing.utils import *
# creates system person and email
# imports AreaDirector persons that are connected to an IETFWG,
# persons from IDAuthor, announcement originators from Announcements,
# requesters from WgMeetingSession, LiaisonDetail persons,
# LiaisonManagers/SDOAuthorizedIndividual persons,
# WgProceedingsActivities persons
# should probably import
# PersonOrOrgInfo/PostalAddress/EmailAddress/PhoneNumber fully
import_docs_from = None
if len(sys.argv) > 1:
import_docs_from = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d")
# make sure special system user/email is created
print "creating (System) person and email"
try:
system_person = Person.objects.get(name="(System)")
except Person.DoesNotExist:
system_person = Person.objects.create(
id=0, # special value
name="(System)",
ascii="(System)",
address="",
)
system_person = Person.objects.get(name="(System)")
if system_person.id != 0: # work around bug in Django
Person.objects.filter(id=system_person.id).update(id=0)
system_person = Person.objects.get(id=0)
system_alias = Alias.objects.get_or_create(
person=system_person,
name=system_person.name
)
system_email = Email.objects.get_or_create(
address="(System)",
defaults=dict(active=True, person=system_person)
)
# LegacyWgPassword
for o in LegacyWgPassword.objects.all():
print "importing LegacyWgPassword", o.pk, o.person.first_name.encode('utf-8'), o.person.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=False)
if not email:
continue
username = o.login_name[:30]
persons = Person.objects.filter(user__username=username)
if persons:
if persons[0] != email.person:
print "SKIPPING", o.login_name, "who is connected to another person "
continue
user, _ = User.objects.get_or_create(username=username)
email.person.user = user
email.person.save()
# LegacyLiaisonUser
for o in LegacyLiaisonUser.objects.all():
print "importing LegacyLiaisonUser", o.pk, o.person.first_name.encode('utf-8'), o.person.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=False)
if not email:
continue
username = o.login_name[:30]
persons = Person.objects.filter(user__username=username)
if persons:
if persons[0] != email.person:
print "SKIPPING", o.login_name, "who is connected to another person "
continue
user, _ = User.objects.get_or_create(username=username)
email.person.user = user
email.person.save()
# IESGLogin
for o in IESGLogin.objects.all():
print "importing IESGLogin", o.pk, o.first_name.encode('utf-8'), o.last_name.encode('utf-8')
if not o.person:
persons = PersonOrOrgInfo.objects.filter(first_name=o.first_name, last_name=o.last_name)
if persons:
o.person = persons[0]
else:
print "NO PERSON", o.person_id
continue
email = get_or_create_email(o, create_fake=False)
if not email:
continue
user, _ = User.objects.get_or_create(username=o.login_name)
email.person.user = user
email.person.save()
# AreaDirector from IETFWG persons
for o in AreaDirector.objects.filter(ietfwg__in=IETFWG.objects.all()).exclude(area=None).distinct().order_by("pk").iterator():
print "importing AreaDirector (from IETFWG) persons", o.pk
get_or_create_email(o, create_fake=False)
# IESGHistory persons
for o in PersonOrOrgInfo.objects.filter(iesghistory__id__gte=1).order_by("pk").distinct():
print "importing IESGHistory person", o.pk, o.first_name.encode('utf-8'), o.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=False)
# WgMeetingSession persons
for o in PersonOrOrgInfo.objects.filter(wgmeetingsession__pk__gte=1).distinct().order_by("pk").iterator():
print "importing WgMeetingSession persons", o.pk, o.first_name.encode('utf-8'), o.last_name.encode('utf-8')
get_or_create_email(o, create_fake=False)
# Announcement persons
for o in PersonOrOrgInfo.objects.filter(announcement__announcement_id__gte=1).order_by("pk").distinct():
print "importing Announcement originator", o.pk, o.first_name.encode('utf-8'), o.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=False)
# LiaisonManagers persons
for o in LiaisonManagers.objects.order_by("pk"):
print "importing LiaisonManagers person", o.pk, o.person.first_name.encode('utf-8'), o.person.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=False)
addresses = o.person.emailaddress_set.filter(priority=o.email_priority).filter(address__contains="@")[:1]
if addresses:
possibly_import_other_priority_email(email, addresses[0])
# SDOAuthorizedIndividual persons
for o in PersonOrOrgInfo.objects.filter(sdoauthorizedindividual__pk__gte=1).order_by("pk").distinct():
print "importing SDOAuthorizedIndividual person", o.pk, o.first_name.encode('utf-8'), o.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=False)
# Liaison persons (these are used as from contacts)
for o in LiaisonDetail.objects.exclude(person=None).order_by("pk"):
print "importing LiaisonDetail person", o.pk, o.person.first_name.encode('utf-8'), o.person.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=True)
# we may also need to import email address used specifically for
# the document
if "@" in email.address:
try:
possibly_import_other_priority_email(email, o.from_email())
except EmailAddress.DoesNotExist:
pass
# WgProceedingsActivities persons
for o in PersonOrOrgInfo.objects.filter(wgproceedingsactivities__id__gte=1).order_by("pk").distinct():
print "importing WgProceedingsActivities person", o.pk, o.first_name.encode('utf-8'), o.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=True)
# IDAuthor persons
all_authors = IDAuthor.objects.all().order_by('id').select_related('person')
if import_docs_from:
all_authors = all_authors.filter(document__last_modified_date__gte=import_docs_from)
for o in all_authors.iterator():
print "importing IDAuthor", o.id, o.person_id, o.person.first_name.encode('utf-8'), o.person.last_name.encode('utf-8')
email = get_or_create_email(o, create_fake=True)
# we may also need to import email address used specifically for
# the document
addresses = o.person.emailaddress_set.filter(type='I-D', priority=o.document_id).filter(address__contains="@")[:1]
if addresses:
possibly_import_other_priority_email(email, addresses[0])