@@ -57,11 +57,9 @@ def send_email(addresses_to, ctx_dict, subject_template, body_template,
57
57
"""
58
58
Function that sends an email
59
59
"""
60
- subject = (
61
- getattr (settings , 'REGISTRATION_EMAIL_SUBJECT_PREFIX' , '' ) +
62
- render_to_string (
63
- subject_template , ctx_dict )
64
- )
60
+
61
+ prefix = getattr (settings , 'REGISTRATION_EMAIL_SUBJECT_PREFIX' , '' )
62
+ subject = prefix + render_to_string (subject_template , ctx_dict )
65
63
# Email subject *must not* contain newlines
66
64
subject = '' .join (subject .splitlines ())
67
65
from_email = get_from_email (ctx_dict .get ('site' ))
@@ -269,9 +267,13 @@ def delete_expired_users(self):
269
267
be deleted.
270
268
271
269
"""
272
- for profile in self .all ():
270
+ profiles = self .filter (
271
+ models .Q (user__is_active = False ) | models .Q (user = None ),
272
+ activated = False ,
273
+ )
274
+ for profile in profiles :
273
275
try :
274
- if profile .activation_key_expired () and not profile . activated :
276
+ if profile .activation_key_expired ():
275
277
user = profile .user
276
278
logger .warning ('Deleting expired Registration profile {} and user {}.' .format (profile , user ))
277
279
profile .delete ()
@@ -350,10 +352,10 @@ def activation_key_expired(self):
350
352
method returns ``True``.
351
353
352
354
"""
353
- expiration_date = datetime .timedelta (
355
+ max_expiry_days = datetime .timedelta (
354
356
days = settings .ACCOUNT_ACTIVATION_DAYS )
355
- return ( self .activated or
356
- ( self .user . date_joined + expiration_date <= datetime_now ()) )
357
+ expiration_date = self .user . date_joined + max_expiry_days
358
+ return self .activated or expiration_date <= datetime_now ()
357
359
358
360
def send_activation_email (self , site , request = None ):
359
361
"""
@@ -418,9 +420,11 @@ def send_activation_email(self, site, request=None):
418
420
'expiration_days' : settings .ACCOUNT_ACTIVATION_DAYS ,
419
421
'site' : site ,
420
422
}
421
- subject = (getattr (settings , 'REGISTRATION_EMAIL_SUBJECT_PREFIX' , '' ) +
422
- render_to_string (
423
- activation_email_subject , ctx_dict , request = request ))
423
+ prefix = getattr (settings , 'REGISTRATION_EMAIL_SUBJECT_PREFIX' , '' )
424
+ subject = prefix + render_to_string (
425
+ activation_email_subject , ctx_dict , request = request
426
+ )
427
+
424
428
# Email subject *must not* contain newlines
425
429
subject = '' .join (subject .splitlines ())
426
430
from_email = get_from_email (site )
0 commit comments