def register(self, form): data = form.cleaned_data request = self.request user = User.objects.create_user(data['username'], data['email'], data['password1']) user.first_name = data['first_name'] user.last_name = data['last_name'] user.is_active = not settings.SEND_USER_ACTIVATION_EMAIL user.save() auditLogger.info( "User %d (%s) created account from IP %s UA: %s", user.id, user.username, request.META.get('REMOTE_ADDR', '?'), request.META.get('HTTP_USER_AGENT', '?'), ) registration_profile = RegistrationProfile.objects.create_profile(user) signals.user_registered.send(sender=self.__class__, user=user, request=request) PreferencesSaved.send(form, user=user) if settings.SEND_USER_ACTIVATION_EMAIL: registration_profile.send_activation_email(RequestSite(request)) else: signals.user_activated.send(sender=self.__class__, user=user, request=request) return user
def test_invalidate_preferences_saved(self): # PreferencesSaved signal is sent after user changes their preferences # (like name), so we need to test that ranking is invalidated after # this signal is broadcasted class MockSender: def __init__(self): self.cleaned_data = {'terms_accepted': True} from oioioi.base.models import PreferencesSaved result = UserResultForProblem.objects.first() sender = MockSender() contest = Contest.objects.get() contest.controller_name = \ 'oioioi.rankings.tests.MockRankingContestController' contest.save() ranking, _ = Ranking.objects.get_or_create(contest=contest, key='key', needs_recalculation=False) ranking.save() self.assertTrue(ranking.is_up_to_date()) recalc = choose_for_recalculation() self.assertIsNone(recalc) PreferencesSaved.send(sender, user=result.user) ranking.refresh_from_db() self.assertFalse(ranking.is_up_to_date()) recalc = choose_for_recalculation() self.assertIsNotNone(recalc)
def save(self, *args, **kwargs): instance = super(UserForm, self).save(*args, **kwargs) PreferencesSaved.send(self) return instance