for user in users db_user created DuggaUser objects update_or_create e

 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
for user in users:
db_user, created = DuggaUser.objects.update_or_create(
email=user['email'],
defaults=dict(
external_integration_id=user['external_integration_id'],
external_integration_type_id=external_integration_type_id,
use_external_integration=user['use_external_integration'],
first_name=user['first_name'],
last_name=user['last_name']
)
)
password = DuggaUser.objects.make_random_password()
db_user.set_password(password)
for user_group_name in user['groups_as_string']:
if user_group_name in groups_by_name:
user_group = groups_by_name[user_group_name]
db_user.groups.add(user_group)
for school_class_external_integration_id in user['school_class_external_integration_ids']:
if school_class_external_integration_id in school_classes_by_external_integration_id:
school_class = school_classes_by_external_integration_id[school_class_external_integration_id]
db_user.schoolclasses.add(school_class)
if 'extra_schools' in user:
extra_school_ids = set()
# this line has been changed
for extra_school_id in user['extra_schools']:
try:
# this line has been changed
extra_school_ids.add(int(extra_school_id))
except ValueError:
# this line has been changed
self.logger.error('Extra school id %s not convertable to int' % extra_school_ids)
db_user.add_extra_school(*extra_school_ids)
self.logger.info('Created (external type id %s) user %s' % (external_integration_type_id, db_user.email))
db_user.save()
# this line has been added
SchoolMembership.objects.create(is_main=True, user=db_user, school_id=school_id)