removing pledge drives (bug 616239)

This commit is contained in:
Jeff Balogh 2011-01-04 15:35:24 -08:00
Родитель 53caf60843
Коммит 42f202d85a
7 изменённых файлов: 19 добавлений и 273 удалений

Просмотреть файл

@ -65,14 +65,6 @@ def contribution(context, addon, text=None, src='', show_install=False,
show_install: Whether or not to show the install button.
show_help: Show "What's this?" link?
"""
# prepare pledge
try:
pledge = addon.pledges.ongoing()[0]
src = '%s-pledge-%s' % (src, pledge.id)
except IndexError:
pledge = None
has_suggested = bool(addon.suggested_amount)
return new_context(**locals())
@ -82,9 +74,7 @@ def contribution(context, addon, text=None, src='', show_install=False,
def review_list_box(context, addon, reviews):
"""Details page: Show a box with three add-on reviews."""
c = dict(context.items())
c.update({'addon': addon,
'reviews': reviews,
})
c.update(addon=addon, reviews=reviews)
return c

Просмотреть файл

@ -922,45 +922,6 @@ class AddonCategory(caching.CachingMixin, models.Model):
return rv
class PledgeManager(amo.models.ManagerBase):
def ongoing(self):
"""Get non-expired pledges only"""
return self.filter(deadline__gte=date.today())
class AddonPledge(amo.models.ModelBase):
addon = models.ForeignKey(Addon, related_name='pledges')
target = models.PositiveIntegerField() # Only $ for now
what_ima_gonna_do = TranslatedField()
active = models.BooleanField(default=False)
deadline = models.DateField(null=True)
objects = PledgeManager()
class Meta:
db_table = 'addons_pledges'
ordering = ('-deadline',)
@property
def contributions(self):
return ContributionStats.objects.filter(
addon=self.addon, created__gte=self.created,
created__lte=self.deadline, transaction_id__isnull=False)
@amo.cached_property
def num_users(self):
return self.contributions.count()
@amo.cached_property
def raised(self):
qs = self.contributions.aggregate(raised=Sum('amount'))
return qs['raised'] or 0
def __unicode__(self):
return '%s ($%s, %s)' % (self.addon.name, self.target, self.deadline)
class AddonRecommendation(models.Model):
"""
Add-on recommendations. For each `addon`, a group of `other_addon`s

Просмотреть файл

@ -3,64 +3,24 @@
{% set charity_name = addon.charity.name %}
{% endif %}
<div class="notification">
{% if pledge %}
{% cache pledge %}
<div class="pledgebox">
{% with target=pledge.target|float|currencyfmt('USD') %}
{# L10n: {0} is a number #}
<h3>{{ _('Help the developer of this add-on raise {0} to support '
'its continued development.')|f(target) }}</h3>
<p>{{ pledge.what_ima_gonna_do }}</p>
<div class="o-meter">
<dl class="raised">
<dt>
{# L10n: title for the amount of money a developer has raised #}
{{ _('Raised') }}
</dt>
<dd>
{# L10n: {0} is a number, {1} is a user count #}
{{ _('<span class="money">{0}</span> from {1} users')|f(
pledge.raised|float|currencyfmt('USD'), pledge.num_users)|safe }}
</dd>
</dl>
<canvas class="pledge-o-meter"
data-ratio="{{ pledge.raised / pledge.target|float }}"
data-radius="14" height="70px"></canvas>
<dl class="goal">
<dt>
{# L10n: title for the amount of money a developer would like to raise #}
{{ _('Goal') }}
</dt>
<dd>
{# L10n: {0} is a number, {1} is a username #}
{{ _('<span class="money">{0}</span> by {1}')|f(
target, pledge.deadline|datetime(_('%b %d')))|safe }}
</dd>
</dl>
</div>
{% endwith %}
</div>{# /pledgebox #}
{% endcache %}
{% else %}
<h3>
{% if text %}
{{ text }}
{% elif not addon.charity %}
{{ _('The developer of this add-on asks that you help support its '
'continued development by making a small contribution.') }}
{% elif addon.charity_id == amo.FOUNDATION_ORG %}
{% trans %}
The developer of this add-on asks that you show your support
by making a donation to the <a href="{{ charity_url }}">{{ charity_name }}</a>.
{% endtrans %}
{% else %}
{% trans %}
The developer of this add-on asks that you show your support
by making a small contribution to the <a href="{{ charity_url }}">{{ charity_name }}</a>.
{% endtrans %}
{% endif %}
</h3>
{% endif %}
<h3>
{% if text %}
{{ text }}
{% elif not addon.charity %}
{{ _('The developer of this add-on asks that you help support its '
'continued development by making a small contribution.') }}
{% elif addon.charity_id == amo.FOUNDATION_ORG %}
{% trans %}
The developer of this add-on asks that you show your support
by making a donation to the <a href="{{ charity_url }}">{{ charity_name }}</a>.
{% endtrans %}
{% else %}
{% trans %}
The developer of this add-on asks that you show your support
by making a small contribution to the <a href="{{ charity_url }}">{{ charity_name }}</a>.
{% endtrans %}
{% endif %}
</h3>
<div class="aux">
<div class="button-wrapper">

Просмотреть файл

@ -439,43 +439,6 @@ class TestCategoryModel(test_utils.TestCase):
assert cat.get_url_path()
class TestAddonPledgeModel(test_utils.TestCase):
fixtures = ['stats/test_models']
def test_ongoing(self):
"""Make sure ongoing pledges are returned correctly."""
myaddon = Addon.objects.get(id=4)
mypledge = AddonPledge(addon=myaddon, target=10,
created=date(2009, 6, 1),
deadline=date(2009, 7, 1))
mypledge.save()
mypledge2 = AddonPledge(addon=myaddon, target=10,
created=date(2009, 6, 1),
deadline=date.today())
mypledge2.save()
ongoing = AddonPledge.objects.ongoing()
eq_(ongoing.count(), 1)
eq_(ongoing[0], mypledge2)
def test_contributions(self):
myaddon = Addon.objects.get(id=4)
mypledge = AddonPledge(addon=myaddon, target=10,
created=date(2009, 6, 1),
deadline=date(2009, 7, 1))
# Only the two valid contributions must be counted.
eq_(mypledge.num_users, 2)
self.assertAlmostEqual(mypledge.raised, 4.98)
def test_raised(self):
"""AddonPledge.raised should never return None."""
pledge = AddonPledge.objects.create(addon_id=4, target=230,
deadline=date.today())
eq_(pledge.raised, 0)
class TestPersonaModel(test_utils.TestCase):
def test_image_urls(self):

Просмотреть файл

@ -2337,53 +2337,6 @@ div.visit-listed-popup {
}
/* END Listed add-ons */
/* Pledge Box */
.o-meter {
display: table;
margin: 1em 0;
width: 100%;
}
.raised, .goal {
width: 14%;
display: table-cell;
}
.o-meter dt {
margin-top: 0;
}
.pledge-o-meter {
width: 100%;
display: table-cell;
vertical-align: text-top;
}
.pledgebox h3 {
font-style: italic;
}
.pledgebox p {
margin-bottom: 0;
}
.pledgebox .money {
display: block;
font-weight: bold;
font-size: 140%;
}
.raised {
color: #223355;
}
.goal {
text-align: right;
color: #666;
}
/* END Pledge Box */
/* Beta Channel */
.install-beta {

Просмотреть файл

@ -210,85 +210,6 @@ $(document).ready(function(){
});
/* TODO(jbalogh): delete with bug 616239. */
// Draw a thermometer for contribution pledges in the selected canvas element.
// Configuration parameters are taken from 'data-' attributes:
// data-ratio, data-radius
jQuery.fn.thermometer = function() {
this.each(function() {
var canvas = this;
if (!canvas.getContext) return;
var ctx = canvas.getContext('2d');
// Draws the outline of the thermometer.
// Options: {x, y, len, radius}
var thermometer = function (opts) {
/* The big circle goes from 30º to 330º, so we go horizontal at
* y +- (radius / 2). Thus, the smaller half-circle gets a
* radius of radius / 2. Trigonometry!
*/
ctx.beginPath();
ctx.arc(opts.x, opts.y, opts.radius,
Math.PI / 6, Math.PI * (11 / 6), false);
ctx.arc(opts.x + opts.len, opts.y, opts.radius / 2,
Math.PI * (3 / 2), Math.PI / 2, false);
ctx.closePath();
}
// HTML5 data attribute helper.
var dataset = function (element, name) {
return JSON.parse(element.getAttribute('data-' + name));
};
var ratio = Math.max(0, Math.min(1, dataset(canvas, 'ratio'))),
radius = dataset(canvas, 'radius'),
padding = 10,
length = ctx.canvas.width - ((radius + padding) * 2),
start_x = radius + padding,
start_y = ctx.canvas.height / 2,
opts = {x: start_x, y: start_y, len: length * ratio,
radius: radius - 4}
// The inner fill (the mercury). We add a second circle so the bulb
// gets filled in more. It's just for looks.
if (ratio > 0) {
ctx.fillStyle = '#3dacfd';
thermometer(opts);
ctx.fill();
ctx.arc(opts.x, opts.y, opts.radius + 2, 0, Math.PI * 2, false);
ctx.fill();
}
// The outer container (the thermometer).
opts = $.extend(opts, {len: length, radius: radius});
ctx.strokeStyle = '#739fb9'; // Border color.
// Glassy gradient overlaying the inner fill.
var gradient = ctx.createLinearGradient(0, opts.y - opts.radius,
0, opts.y + opts.radius);
gradient.addColorStop(0, 'rgba(255, 255, 255, 0.5)');
gradient.addColorStop(1, 'rgba(255, 255, 255, 0)');
// Draw the container.
thermometer(opts);
ctx.stroke();
ctx.fillStyle = gradient;
ctx.fill();
// Tick marks at 25%, 50%, 75%;
ctx.strokeStyle = '#666'; // Darker to compete with the fill color.
for (var i = 1; i < 4; i++) {
var x = start_x + i * (length / 4);
ctx.beginPath();
ctx.moveTo(x, start_y);
ctx.lineTo(x, start_y + (radius / 2));
ctx.stroke();
}
});
return this;
}
// TODO(jbalogh): save from amo2009.
var AMO = {};

Просмотреть файл

@ -2,6 +2,4 @@ $(document).ready(function() {
$("#contribute-why").popup("#contribute-more-info", {
pointTo: "#contribute-more-info"
});
$('canvas.pledge-o-meter').thermometer();
});