1
1
from allauth .account .adapter import get_adapter
2
+ from allauth .account .models import EmailAddress
2
3
from allauth .account .utils import setup_user_email
3
- from allauth .utils import email_address_exists
4
4
from django .contrib .auth import authenticate , get_user_model
5
5
from django .core .mail import send_mail
6
6
from django .template .loader import render_to_string
@@ -106,10 +106,12 @@ def update(self, instance, validated_data):
106
106
107
107
# Update Profile
108
108
# Nie všetky polia v modeloch User a Profile sú editovateľné cez API.
109
- instance .profile .nickname = profile_data .get (
110
- 'nickname' , instance .profile .nickname )
111
109
instance .profile .phone = profile_data .get (
112
110
'phone' , instance .profile .phone )
111
+ instance .profile .fisrt_name = profile_data .get (
112
+ 'first_name' , instance .profile .first_name )
113
+ instance .profile .last_name = profile_data .get (
114
+ 'last_name' , instance .profile .last_name )
113
115
instance .profile .parent_phone = profile_data .get (
114
116
'parent_phone' , instance .profile .parent_phone )
115
117
instance .profile .gdpr = profile_data .get (
@@ -121,13 +123,17 @@ def update(self, instance, validated_data):
121
123
122
124
# User sa nikdy neupdatuje preto nie je potrebné volať instance.save()
123
125
instance .profile .save ()
124
- self .handle_other_school (validated_data .pop ('new_school_description' ))
126
+ instance .save ()
127
+ self .handle_other_school (validated_data .pop (
128
+ 'new_school_description' , None ))
125
129
return instance
126
130
127
131
def handle_other_school (self , school ):
128
132
'''
129
133
Ak je zadana skola "ina skola" tak posle o tom mail.
130
134
'''
135
+ if school is None :
136
+ return
131
137
if school .code == self .OTHER_SCHOOL_CODE :
132
138
email = self .validated_data ['email' ]
133
139
first_name = self .validated_data ['profile' ]['first_name' ]
@@ -169,7 +175,7 @@ class Meta:
169
175
170
176
def validate_email (self , email ):
171
177
email = get_adapter ().clean_email (email )
172
- if email and email_address_exists ( email ):
178
+ if email and EmailAddress . objects . filter ( email__iexact = email ). exists ( ):
173
179
raise serializers .ValidationError (
174
180
"Používateľ s danou emailovou adresou už existuje." )
175
181
return email
@@ -215,7 +221,6 @@ def save(self, request):
215
221
Profile .objects .create (user = user ,
216
222
first_name = profile_data ['first_name' ],
217
223
last_name = profile_data ['last_name' ],
218
- nickname = profile_data ['nickname' ],
219
224
school = profile_data ['school' ],
220
225
year_of_graduation = grade .get_year_of_graduation_by_date (),
221
226
phone = profile_data ['phone' ],
@@ -226,27 +231,3 @@ def save(self, request):
226
231
setup_user_email (request , user , [])
227
232
228
233
return user
229
-
230
- def handle_other_school (self , school ):
231
- '''
232
- Ak je zadana skola "ina skola" tak posle o tom mail.
233
- '''
234
- if school .code == self .OTHER_SCHOOL_CODE :
235
- email = self .validated_data ['email' ]
236
- first_name = self .validated_data ['profile' ]['first_name' ]
237
- last_name = self .validated_data ['profile' ]['last_name' ]
238
- school_info = self .validated_data ['new_school_description' ]
239
- send_mail (
240
- 'Žiadosť o pridanie novej školy' ,
241
- render_to_string (
242
- 'user/emails/new_school_request.txt' ,
243
- {
244
- 'email' : email ,
245
- 'first_name' : first_name ,
246
- 'last_name' : last_name ,
247
- 'school_info' : school_info
248
- },
249
- ),
250
- EMAIL_NO_REPLY ,
251
- [EMAIL_ALERT ]
252
- )
0 commit comments