Merge pull request #64 from Gluejar/prepopulate_ack_name

Prepopulate ack name
pull/1/head
Raymond Yee 2012-10-23 10:35:40 -07:00
commit b4c1d09e88
4 changed files with 39 additions and 23 deletions

View File

@ -973,6 +973,7 @@ 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')
@ -1019,6 +1020,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')
@ -1031,6 +1033,31 @@ class UserProfile(models.Model):
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 = self.last_transaction
if last and last.ack_name:
return last.ack_name
else:
return self.user.username
@property
def anon_pref(self):
# use preferences from last transaction, if any
last = self.last_transaction
if last:
return last.anonymous
else:
return None
#class CampaignSurveyResponse(models.Model):
# # generic

View File

@ -8,6 +8,7 @@
<link type="text/css" rel="stylesheet" href="/static/css/pledge.css" />
<script type="text/javascript" src="/static/js/reconcile_pledge.js"></script>
{% endblock %}
{% block news %}
@ -125,14 +126,7 @@
<div class="cancel_notice">
{% if faqmenu == 'modify' %}We hope you won't, but of course you're also free to <a href="{% url pledge_cancel campaign_id=work.last_campaign.id %}">cancel your pledge</a>.{% endif %}</div>
<div id="pass_supporter_name" style="display: none;">{{ request.user.username }}</div>
{% if transaction.ack_name %}
<div id="pass_ack_name" style="display: none;">{{ transaction.ack_name }}</div>
{% else %}
<div id="pass_ack_name" style="display: none;">{{ request.user.username }}</div>
{% endif %}
<div id="pass_ack_link" style="display: none;">{{ transaction.ack_link }}</div>
<div id="pass_ack_dedication" style="display: none;">{{ transaction.ack_dedication }}</div>
<div id="pass_anon" style="display: none;">{{ transaction.anonymous }}</div>
{% endblock %}

View File

@ -644,15 +644,18 @@ 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:
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,

View File

@ -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() {