コード例 #1
0
ファイル: views.py プロジェクト: maxkoryukov/pasportaservo
 def post(self, request, *args, **kwargs):
     if self.valid:
         Profile.mark_valid_emails([self.profile.user.email])
     else:
         Profile.mark_invalid_emails([self.profile.user.email])
     if request.is_ajax():
         success_value = 'valid' if self.valid else 'invalid'
         return JsonResponse({'success': success_value})
     else:
         return TemplateResponse(request, self.template_name, context={'view': self})
コード例 #2
0
ファイル: views.py プロジェクト: RibeiroAna/pasportaservo
 def post(self, request, *args, **kwargs):
     if self.valid:
         Profile.mark_valid_emails([self.user.email])
     else:
         Profile.mark_invalid_emails([self.user.email])
     if request.is_ajax():
         success_value = 'valid' if self.valid else 'invalid'
         return JsonResponse({'success': success_value})
     else:
         return TemplateResponse(request, self.template_name)
コード例 #3
0
    def test_mark_identical_emails(self):
        # Having two profiles with the same public email address is
        # permitted. The `mark_invalid_emails` and `mark_valid_emails`
        # methods are expected to update both profile objects.
        profile_two = ProfileSansAccountFactory(with_email=True)
        Profile.all_objects.filter(pk=self.profile.pk).update(
            email=profile_two.email)
        email = profile_two.email
        invalid_email = f'{settings.INVALID_PREFIX}{email}'

        result = Profile.mark_invalid_emails([email])
        self.profile.refresh_from_db()
        profile_two.refresh_from_db()
        self.assertEqual(self.profile.email, profile_two.email)
        self.assertTrue(self.profile.email.startswith(settings.INVALID_PREFIX))
        self.assertEqual(result[Profile], 2)
        # When one of the profiles has its email already marked as
        # invalid, only the other one is expected to be updated.
        Profile.all_objects.filter(pk=self.profile.pk).update(email=email)
        result = Profile.mark_invalid_emails([email])
        self.profile.refresh_from_db()
        profile_two.refresh_from_db()
        self.assertTrue(self.profile.email.startswith(settings.INVALID_PREFIX))
        self.assertEqual(self.profile.email.count(settings.INVALID_PREFIX), 1)
        self.assertTrue(profile_two.email.startswith(settings.INVALID_PREFIX))
        self.assertEqual(profile_two.email.count(settings.INVALID_PREFIX), 1)
        self.assertEqual(result[Profile], 1)
        # Repeating the operation is not expected to update anything.
        result = Profile.mark_invalid_emails([email])
        self.assertEqual(result[Profile], 0)

        # Both profile objects' emails are expected to have the
        # marker prefix removed.
        result = Profile.mark_valid_emails([invalid_email])
        self.profile.refresh_from_db()
        profile_two.refresh_from_db()
        self.assertEqual(self.profile.email, profile_two.email)
        self.assertEqual(self.profile.email.count(settings.INVALID_PREFIX), 0)
        self.assertEqual(result[Profile], 2)
        # When one of the profiles has its email already marked as
        # valid, only the other one is expected to be updated.
        Profile.all_objects.filter(pk=self.profile.pk).update(
            email=invalid_email)
        result = Profile.mark_valid_emails([invalid_email])
        self.profile.refresh_from_db()
        profile_two.refresh_from_db()
        self.assertEqual(self.profile.email.count(settings.INVALID_PREFIX), 0)
        self.assertEqual(profile_two.email.count(settings.INVALID_PREFIX), 0)
        self.assertEqual(result[Profile], 1)
        # Repeating the operation is not expected to update anything.
        result = Profile.mark_valid_emails([email])
        self.assertEqual(result[Profile], 0)
コード例 #4
0
 def post(self, request, *args, **kwargs):
     # Spare the extra trip to the database to fetch the User object associated
     # with the profile, just to retrieve the email address in that record.
     email = User.objects.filter(
         pk=self.profile.user_id).values_list('email')
     if self.valid:
         Profile.mark_valid_emails(email)
     else:
         Profile.mark_invalid_emails(email)
     if request.is_ajax():
         success_value = 'valid' if self.valid else 'invalid'
         return JsonResponse({'success': success_value})
     else:
         return TemplateResponse(request,
                                 self.template_name,
                                 context={'view': self})
コード例 #5
0
ファイル: validate.py プロジェクト: maxkoryukov/pasportaservo
 def action(self, file_name, emails):
     results = Profile.mark_valid_emails(emails=emails)
     for model, updated in results.items():
         print(updated, model.__name__, "emails marked as valid from", file_name)
コード例 #6
0
ファイル: forms.py プロジェクト: maxkoryukov/pasportaservo
 def save(self, commit=True):
     super().save(commit)
     if commit:
         Profile.mark_valid_emails([self.user.email])
     return self.user
コード例 #7
0
 def action(self, file_name, emails):
     results = Profile.mark_valid_emails(emails=emails)
     for model, updated in results.items():
         print(updated, model.__name__, "emails marked as valid from",
               file_name)