From d03405252307c6b52311c9e41950f8c09e75863e Mon Sep 17 00:00:00 2001 From: sork Date: Thu, 14 Apr 2011 00:03:41 +0200 Subject: [PATCH] Bug 649652 - Login on mobile is now required to get the Multi-sparker badge --- apps/challenges/challenges.py | 2 +- apps/users/models.py | 7 +++---- apps/users/views.py | 19 +++++++++++++++++-- lib/staging/test-data.sql | 10 +++++----- migrations/11-mobile-login-flag.sql | 3 +++ 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 migrations/11-mobile-login-flag.sql diff --git a/apps/challenges/challenges.py b/apps/challenges/challenges.py index b0388f2..6509185 100644 --- a/apps/challenges/challenges.py +++ b/apps/challenges/challenges.py @@ -67,7 +67,7 @@ all_challenges[_id(2, 2)] = TwitterThreat() class Multisparker(ChallengeImpl): """ Sign in on both your phone and your desktop Web browser """ def is_completed_by(self, profile): - return profile.login_desktop + return profile.login_desktop and profile.login_mobile all_challenges[_id(2, 3)] = Multisparker() diff --git a/apps/users/models.py b/apps/users/models.py index 8059d3f..efeb86e 100644 --- a/apps/users/models.py +++ b/apps/users/models.py @@ -47,6 +47,7 @@ class Profile(models.Model): # Flags login_desktop = models.BooleanField(default=False) + login_mobile = models.BooleanField(default=False) is_non_android = models.BooleanField(default=False) # Personal stats @@ -297,12 +298,10 @@ class Profile(models.Model): pass - def trigger_desktop_login_badge(self): + def trigger_multisparker_badge(self): from challenges.tasks import update_completed_challenges - if not self.login_desktop: - self.login_desktop = True - self.save() + if self.login_desktop and self.login_mobile: update_completed_challenges(self.user.id) diff --git a/apps/users/views.py b/apps/users/views.py index bc141f3..acf6dab 100644 --- a/apps/users/views.py +++ b/apps/users/views.py @@ -45,6 +45,11 @@ def login(request, mobile=False): next_url = next or reverse('mobile.home') if request.user.is_authenticated(): + profile = request.user.profile + if not profile.login_mobile: + profile.login_mobile = True + profile.save() + profile.trigger_multisparker_badge() return HttpResponseRedirect(next_url) return jingo.render(request, 'users/mobile/login.html', @@ -55,7 +60,12 @@ def login(request, mobile=False): return {'status': 'error', 'errors': dict(form.errors.iteritems())} else: - request.user.profile.trigger_desktop_login_badge() + profile = request.user.profile + if not profile.login_desktop: + profile.login_desktop = True + profile.save() + profile.trigger_multisparker_badge() + return {'status': 'success', 'next': next or reverse('desktop.home')} @@ -103,7 +113,12 @@ def register(request, mobile=False): # Set a flag for mobile menu notifications profile = User.objects.get(username=form.cleaned_data['username']).profile - profile.new_challenges = True + profile.new_challenges = True + # Set desktop or mobile login flag + if mobile: + profile.login_mobile = True + else: + profile.login_desktop = True profile.save() if mobile: diff --git a/lib/staging/test-data.sql b/lib/staging/test-data.sql index 9877762..32836d4 100644 --- a/lib/staging/test-data.sql +++ b/lib/staging/test-data.sql @@ -9,11 +9,11 @@ INSERT INTO auth_user VALUES INSERT INTO users_profile VALUES -(1,1,0,1,NULL,NULL,NULL,'Paris','FR',NULL,1,1,'bob',NULL,0,0,0), -(2,1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,0,1,'john',NULL,0,0,0), -(3,1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,0,1,'batman',NULL,0,0,0), -(4,4,0,1,NULL,NULL,NULL,'New York','US',NULL,1,1,NULL,NULL,0,0,0), -(5,2,0,1,NULL,NULL,NULL,NULL,NULL,NULL,1,1,NULL,NULL,0,0,0); +(1,1,0,1,NULL,NULL,NULL,'Paris','FR',NULL,1,1,'bob',NULL,0,0,0,0), +(2,1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,0,1,'john',NULL,0,0,0,0), +(3,1,0,0,NULL,NULL,NULL,NULL,NULL,NULL,0,1,'batman',NULL,0,0,0,0), +(4,4,0,1,NULL,NULL,NULL,'New York','US',NULL,1,1,NULL,NULL,0,0,0,0), +(5,2,0,1,NULL,NULL,NULL,NULL,NULL,NULL,1,1,NULL,NULL,0,0,0,0); INSERT INTO users_tree VALUES diff --git a/migrations/11-mobile-login-flag.sql b/migrations/11-mobile-login-flag.sql new file mode 100644 index 0000000..3003b5a --- /dev/null +++ b/migrations/11-mobile-login-flag.sql @@ -0,0 +1,3 @@ + +-- Bug 649652: Multi-sparker badge requires a new profile flag since registration is now available on desktop +ALTER TABLE `users_profile` ADD COLUMN `login_mobile` bool NOT NULL AFTER `login_desktop`; \ No newline at end of file