Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

# -*- coding: utf-8 -*- 

# Generated by Django 1.11 on 2018-06-29 10:33 

from __future__ import unicode_literals 

 

import datetime 

import dirtyfields.dirtyfields 

from django.db import migrations, models 

import django.db.models.deletion 

import members.countryfield 

import members.models 

from django.apps import apps as global_apps 

 

 

def forward(apps, _): 

 

ContentType = apps.get_model('contenttypes', 'ContentType') 

 

Member_old = apps.get_model('members', 'Member') 

Member_new = apps.get_model('members', 'Member_new') 

 

# Use Member_old here because "Member_new" will be renamed to "Member" right after migration of the data 

new_member_ct = ContentType.objects.get_for_model(Member_old).id 

 

24 ↛ 25line 24 didn't jump to line 25, because the loop on line 24 never started for old_member in Member_old.objects.all(): 

new_member = Member_new() 

 

new_member._imported = True 

new_member.polymorphic_ctype_id = new_member_ct 

 

new_member.chaos_number = old_member.chaos_number 

new_member.membership_type = old_member.membership_type 

new_member.is_active = old_member.is_active 

new_member.membership_reduced = old_member.membership_reduced 

new_member.erfa = old_member.erfa 

new_member.first_name = old_member.first_name 

new_member.last_name = old_member.last_name 

new_member.address_1 = old_member.address_1 

new_member.address_2 = old_member.address_2 

new_member.address_3 = old_member.address_3 

new_member.address_country = old_member.address_country 

new_member.address_unknown = old_member.address_unknown 

new_member.membership_start = old_member.membership_start 

new_member.membership_end = old_member.membership_end 

new_member.fee_last_paid = old_member.fee_last_paid 

new_member.fee_paid_until = old_member.fee_paid_until 

new_member.last_update = old_member.last_update 

new_member.account_balance = old_member.account_balance 

new_member.fee_override = old_member.fee_override 

new_member.fee_registration_paid = old_member.fee_registration_paid 

new_member.comment = old_member.comment 

 

new_member.save() 

 

try: 

Subscriber_old = apps.get_model('datenschleuder', 'Subscriber') 

except LookupError: 

# datenschleuder app isn't installed, no migration necessary 

return 

 

Subscriber_new = apps.get_model('members', 'Subscriber') 

subscriber_ct = ContentType.objects.get_for_model(Subscriber_new).id 

 

for old_subscriber in Subscriber_old.objects.all(): 

# This filters Datenschleuder subscribers, who have the same chaos_number as an already existing member 

# These doublicates usually stem from moving a subscriber to the member database without deleting it from 

# the subscriber database 

if Member_new.objects.filter(chaos_number=old_subscriber.datenschleuder_number).exists(): 

continue 

 

new_subscriber = Subscriber_new() 

 

new_subscriber._imported = True 

new_subscriber.polymorphic_ctype_id = subscriber_ct 

 

new_subscriber.chaos_number = old_subscriber.datenschleuder_number 

new_subscriber.subscriber_source = old_subscriber.subscriber_source 

new_subscriber.first_name = old_subscriber.first_name 

new_subscriber.last_name = old_subscriber.last_name 

new_subscriber.address_1 = old_subscriber.address_1 

new_subscriber.address_2 = old_subscriber.address_2 

new_subscriber.address_3 = old_subscriber.address_3 

new_subscriber.address_country = old_subscriber.address_country 

new_subscriber.address_unknown = old_subscriber.address_unknown 

new_subscriber.max_datenschleuder_issue = old_subscriber.max_datenschleuder_issue 

new_subscriber.is_endless = old_subscriber.is_endless 

new_subscriber.rt_link = old_subscriber.rt_link 

 

new_subscriber.save() 

 

 

def backward(apps, _): 

Member_old = apps.get_model('members', 'Member') 

Member_new = apps.get_model('members', 'Member_new') 

 

for new_member in Member_new.objects.all(): 

old_member = Member_old() 

 

old_member._imported = True 

 

old_member.chaos_number = new_member.chaos_number 

old_member.membership_type = new_member.membership_type 

old_member.is_active = new_member.is_active 

old_member.membership_reduced = new_member.membership_reduced 

old_member.erfa = new_member.erfa 

old_member.first_name = new_member.first_name 

old_member.last_name = new_member.last_name 

old_member.address_1 = new_member.address_1 

old_member.address_2 = new_member.address_2 

old_member.address_3 = new_member.address_3 

old_member.address_country = new_member.address_country 

old_member.address_unknown = new_member.address_unknown 

old_member.membership_start = new_member.membership_start 

old_member.membership_end = new_member.membership_end 

old_member.fee_last_paid = new_member.fee_last_paid 

old_member.fee_paid_until = new_member.fee_paid_until 

old_member.last_update = new_member.last_update 

old_member.account_balance = new_member.account_balance 

old_member.fee_override = new_member.fee_override 

old_member.fee_registration_paid = new_member.fee_registration_paid 

old_member.comment = new_member.comment 

 

old_member.save() 

 

try: 

Subscriber_old = apps.get_model('datenschleuder', 'Subscriber') 

except LookupError: 

# datenschleuder app isn't installed, no migration necessary 

return 

 

Subscriber_new = apps.get_model('members', 'Subscriber') 

 

for new_subscriber in Subscriber_new.objects.all(): 

old_subscriber, created = Subscriber_old.objects.get_or_create( 

datenschleuder_number=new_subscriber.chaos_number, 

subscriber_source=new_subscriber.subscriber_source, 

first_name=new_subscriber.first_name, 

last_name=new_subscriber.last_name, 

address_1=new_subscriber.address_1, 

address_2=new_subscriber.address_2, 

address_3=new_subscriber.address_3, 

address_country=new_subscriber.address_country, 

address_unknown=new_subscriber.address_unknown, 

max_datenschleuder_issue=new_subscriber.max_datenschleuder_issue, 

is_endless=new_subscriber.is_endless, 

rt_link=new_subscriber.rt_link, 

) 

 

if created: 

old_subscriber._imported = True 

old_subscriber.save() 

 

 

class Migration(migrations.Migration): 

 

dependencies = [ 

('members', '0026_auto_20180522_0548'), 

] 

 

operations = [ 

migrations.RunPython(forward, backward), 

migrations.DeleteModel(name='Member'), 

migrations.RenameModel(old_name='Member_new', new_name='Member'), 

migrations.RenameField( 

model_name='emailaddress', 

old_name='member', 

new_name='person', 

), 

migrations.AlterUniqueTogether( 

name='emailaddress', 

unique_together=set([('person', 'email_address')]), 

), 

migrations.AlterField( 

model_name='emailaddress', 

name='person', 

field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='members.Person'), 

), 

migrations.AlterField( 

model_name='emailtomember', 

name='email_type', 

field=models.CharField(choices=[('def', 'default'), ('dml', 'data record'), ('wlc', 'welcome'), ('dep', 'delayed payment'), ('gpg', 'gpg error'), ('ext', 'member exit'), ('dex', 'doppelerfa exit'), ('rar', 'reactivation reminder'), ('gai', 'ga invitation')], default='def', max_length=3), 

), 

]