From 96918d60a56bc07c48d24d21c5fbb76c90183d2a Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Wed, 17 Oct 2012 11:54:29 -0400 Subject: [PATCH 01/10] if not modifying pledge use ack data from previous transaction to prefill ack boxes [#37939351] --- frontend/templates/pledge.html | 7 ++++++- frontend/views.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/frontend/templates/pledge.html b/frontend/templates/pledge.html index 84173b09..3d2d3436 100644 --- a/frontend/templates/pledge.html +++ b/frontend/templates/pledge.html @@ -8,6 +8,7 @@ + {% endblock %} {% block news %} @@ -128,11 +129,15 @@ {% if transaction.ack_name %} {% else %} - + {% endif %} +{% if transaction.anonymous %} +{% else %} + +{% endif %} {% endblock %} diff --git a/frontend/views.py b/frontend/views.py index b6da2579..914ec71d 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -676,6 +676,19 @@ class PledgeView(FormView): context = super(PledgeView, self).get_context_data(**kwargs) context['nonprofit'] = settings.NONPROFIT + # use preferences from last transaction, if any + try: + last_transaction = Transaction.objects.filter(user=self.request.user).order_by('-date_modified')[0] + except: + last_transaction = None + + if last_transaction: + ack_name=last_transaction.ack_name + anonymous=last_transaction.anonymous + else: + ack_name=self.request.user.username + anonymous='' + context.update({ 'work':self.work, 'campaign':self.campaign, @@ -684,6 +697,8 @@ class PledgeView(FormView): 'faqmenu': 'modify' if self.transaction else 'pledge', 'transaction': self.transaction, 'tid': self.transaction.id if self.transaction else None, + 'ack_name':ack_name, + 'anonymous':anonymous, }) return context From 64681d95f72a1951f7025e8f959ab9111ceb9610 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Wed, 17 Oct 2012 12:11:54 -0400 Subject: [PATCH 02/10] ohhh that's how class-based views work --- frontend/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/views.py b/frontend/views.py index 914ec71d..f5c2969a 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -679,7 +679,7 @@ class PledgeView(FormView): # use preferences from last transaction, if any try: last_transaction = Transaction.objects.filter(user=self.request.user).order_by('-date_modified')[0] - except: + except IndexError: last_transaction = None if last_transaction: From bcba88221f77e368e49eceab30f6a963ff589946 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Thu, 18 Oct 2012 13:50:02 -0400 Subject: [PATCH 03/10] ack_name and anon_pref are now properties on user profile --- core/models.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/core/models.py b/core/models.py index 0866ae10..ec58c455 100755 --- a/core/models.py +++ b/core/models.py @@ -973,12 +973,20 @@ def pledger(): pledger.instance = Badge.objects.get(name='pledger') return pledger.instance pledger.instance=None + def pledger2(): if not pledger2.instance: pledger2.instance = Badge.objects.get(name='pledger2') return pledger2.instance pledger2.instance=None +def last_transaction(user): + from regluit.payment.models import Transaction + try: + return Transaction.objects.filter(user=user).order_by('-date_modified')[0] + except IndexError: + return None + class UserProfile(models.Model): created = models.DateTimeField(auto_now_add=True) user = models.OneToOneField(User, related_name='profile') @@ -1019,6 +1027,7 @@ class UserProfile(models.Model): return None else: return accounts[0] + @property def old_account(self): accounts = self.user.account_set.filter(date_deactivated__isnull=False).order_by('-date_deactivated') @@ -1030,7 +1039,24 @@ class UserProfile(models.Model): @property def pledges(self): return self.user.transaction_set.filter(status=TRANSACTION_STATUS_ACTIVE) - + + @property + def ack_name(self): + # use preferences from last transaction, if any + last = last_transaction(self.user) + if last: + return last.ack_name + else: + return self.user.username + + @property + def anon_pref(self): + # use preferences from last transaction, if any + last = last_transaction(self.user) + if last: + return last.anonymous + else: + return '' #class CampaignSurveyResponse(models.Model): # # generic From 4a6a392481b4c00e4adb742e988e8fe32a52db0a Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Thu, 18 Oct 2012 13:57:39 -0400 Subject: [PATCH 04/10] ack_name and anonpref are form initial values, not context variables --- frontend/views.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/frontend/views.py b/frontend/views.py index f5c2969a..5d090edf 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -610,6 +610,11 @@ class PledgeView(FormView): premiums = None data = None + def get_initial(self): + return { 'anonymous': self.request.user.profile.anonymous, + 'ack_name': self.request.user.profile.ack_name + } + def get_preapproval_amount(self): preapproval_amount = self.request.REQUEST.get('preapproval_amount', None) if preapproval_amount: @@ -676,19 +681,6 @@ class PledgeView(FormView): context = super(PledgeView, self).get_context_data(**kwargs) context['nonprofit'] = settings.NONPROFIT - # use preferences from last transaction, if any - try: - last_transaction = Transaction.objects.filter(user=self.request.user).order_by('-date_modified')[0] - except IndexError: - last_transaction = None - - if last_transaction: - ack_name=last_transaction.ack_name - anonymous=last_transaction.anonymous - else: - ack_name=self.request.user.username - anonymous='' - context.update({ 'work':self.work, 'campaign':self.campaign, @@ -697,8 +689,6 @@ class PledgeView(FormView): 'faqmenu': 'modify' if self.transaction else 'pledge', 'transaction': self.transaction, 'tid': self.transaction.id if self.transaction else None, - 'ack_name':ack_name, - 'anonymous':anonymous, }) return context From 79aefd4c91609f261a1f9bb39bf54f60b6514227 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Thu, 18 Oct 2012 14:13:42 -0400 Subject: [PATCH 05/10] nope, need to set the values over here --- frontend/views.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/frontend/views.py b/frontend/views.py index 5d090edf..abf65ae1 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -610,11 +610,6 @@ class PledgeView(FormView): premiums = None data = None - def get_initial(self): - return { 'anonymous': self.request.user.profile.anonymous, - 'ack_name': self.request.user.profile.ack_name - } - def get_preapproval_amount(self): preapproval_amount = self.request.REQUEST.get('preapproval_amount', None) if preapproval_amount: @@ -650,9 +645,9 @@ class PledgeView(FormView): transactions = self.campaign.transactions().filter(user=self.request.user, status=TRANSACTION_STATUS_ACTIVE, type=PAYMENT_TYPE_AUTHORIZATION) premium_id = self.request.REQUEST.get('premium_id', 150) if transactions.count() == 0: - ack_name='' + ack_name=self.request.user.profile.ack_name ack_dedication='' - anonymous='' + anonymous=self.request.user.profile.anon_pref else: self.transaction = transactions[0] if premium_id == 150 and self.transaction.premium is not None: From 21ef0c1bf2be0192548d88c9d8fdb92612821148 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Thu, 18 Oct 2012 14:16:05 -0400 Subject: [PATCH 06/10] now passing data through initial form values, not hidden divs --- frontend/templates/pledge.html | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/frontend/templates/pledge.html b/frontend/templates/pledge.html index 3d2d3436..65a1924c 100644 --- a/frontend/templates/pledge.html +++ b/frontend/templates/pledge.html @@ -126,18 +126,7 @@
{% if faqmenu == 'modify' %}We hope you won't, but of course you're also free to cancel your pledge.{% endif %}
-{% if transaction.ack_name %} - -{% else %} - -{% endif %} - - -{% if transaction.anonymous %} - -{% else %} - -{% endif %} + {% endblock %} From 17bfb3c58cb95d4670dd3399e9b536fe202bb915 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Thu, 18 Oct 2012 14:17:11 -0400 Subject: [PATCH 07/10] remove no-longer=used ack_link, get data from form values --- static/js/reconcile_pledge.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/static/js/reconcile_pledge.js b/static/js/reconcile_pledge.js index 551ab007..a85a83d8 100644 --- a/static/js/reconcile_pledge.js +++ b/static/js/reconcile_pledge.js @@ -12,19 +12,17 @@ $j().ready(function() { var anonbox = $j('#anonbox input'); var ackSection = $j('#ack_section'); var supporterName = $j('#pass_supporter_name').html(); - var ackName = $j('#pass_ack_name').html(); - var ackLink = $j('#pass_ack_link').html(); - var ackDedication = $j('#pass_ack_dedication').html(); + var ackName = $j('#id_ack_name').val(); + var ackDedication = $j('#id_ack_dedication').val(); if(ackDedication == 'None') { ackDedication = ''; } var acks = { ack_name: ackName, - ack_link: ackLink, ack_dedication: ackDedication }; - var ackAnon = $j('#pass_anon').html(); + var ackAnon = $j('#id_anonymous').val(); // we're not letting people submit arbitrary links $j('#id_ack_link').attr('disabled', 'disabled'); @@ -75,17 +73,11 @@ $j().ready(function() { // fill mandatory premium link input with supporter page var activateLink = function() { $j('#ack_link').removeClass('ack_inactive').addClass('ack_active'); - if(ackLink) { - $j('input#id_ack_link').val(ackLink); - } else { - $j('input#id_ack_link').val('https://unglue.it/supporter/'+supporterName); - } } // empty mandatory premium link var deactivateLink = function() { $j('#ack_link').removeClass('ack_active').addClass('ack_inactive'); - $j('input#id_ack_link').val(''); } var anonymizeName = function() { From 41f59024f4554d66c406fda82f1ef871042de33b Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Thu, 18 Oct 2012 15:51:52 -0400 Subject: [PATCH 08/10] last_transaction now a property on the profile --- core/models.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/models.py b/core/models.py index ec58c455..f4f8fa4f 100755 --- a/core/models.py +++ b/core/models.py @@ -980,13 +980,6 @@ def pledger2(): return pledger2.instance pledger2.instance=None -def last_transaction(user): - from regluit.payment.models import Transaction - try: - return Transaction.objects.filter(user=user).order_by('-date_modified')[0] - except IndexError: - return None - class UserProfile(models.Model): created = models.DateTimeField(auto_now_add=True) user = models.OneToOneField(User, related_name='profile') @@ -1039,11 +1032,19 @@ class UserProfile(models.Model): @property def pledges(self): return self.user.transaction_set.filter(status=TRANSACTION_STATUS_ACTIVE) - + + @property + def last_transaction(self): + from regluit.payment.models import Transaction + try: + return Transaction.objects.filter(user=self.user).order_by('-date_modified')[0] + except IndexError: + return None + @property def ack_name(self): # use preferences from last transaction, if any - last = last_transaction(self.user) + last = self.last_transaction if last: return last.ack_name else: @@ -1052,7 +1053,7 @@ class UserProfile(models.Model): @property def anon_pref(self): # use preferences from last transaction, if any - last = last_transaction(self.user) + last = self.last_transaction if last: return last.anonymous else: From b7ce48bfb0b0404baa81749080e7a49c22634815 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Fri, 19 Oct 2012 14:01:22 -0400 Subject: [PATCH 09/10] fix anon_pref --- core/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/models.py b/core/models.py index f4f8fa4f..7d96a2ae 100755 --- a/core/models.py +++ b/core/models.py @@ -1057,7 +1057,7 @@ class UserProfile(models.Model): if last: return last.anonymous else: - return '' + return None #class CampaignSurveyResponse(models.Model): # # generic From f9f19b204322e4eb4255c8ee0167caacc3055d86 Mon Sep 17 00:00:00 2001 From: Andromeda Yelton Date: Tue, 23 Oct 2012 09:37:00 -0400 Subject: [PATCH 10/10] if last transaction ack_name was blank, use username as ack_name --- core/models.py | 2 +- frontend/views.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/models.py b/core/models.py index 7d96a2ae..065e6941 100755 --- a/core/models.py +++ b/core/models.py @@ -1045,7 +1045,7 @@ class UserProfile(models.Model): def ack_name(self): # use preferences from last transaction, if any last = self.last_transaction - if last: + if last and last.ack_name: return last.ack_name else: return self.user.username diff --git a/frontend/views.py b/frontend/views.py index abf65ae1..53032dfc 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -652,8 +652,11 @@ class PledgeView(FormView): self.transaction = transactions[0] if premium_id == 150 and self.transaction.premium is not None: premium_id = self.transaction.premium.id - ack_name=self.transaction.ack_name - ack_dedication=self.transaction.ack_dedication + if self.transaction.ack_name: + ack_name = self.transaction.ack_name + else: + ack_name = self.request.user.profile.ack_name + ack_dedication = self.transaction.ack_dedication anonymous=self.transaction.anonymous self.data = {'preapproval_amount':self.get_preapproval_amount(), 'premium_id':premium_id,