record org ids in contribution stats (bug 624446)

This commit is contained in:
Jeff Balogh 2011-01-10 13:41:44 -07:00
Родитель 2f48c28cd5
Коммит 72e38213fe
4 изменённых файлов: 18 добавлений и 2 удалений

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

@ -21,10 +21,11 @@ from amo.tests.test_helpers import AbuseBase, AbuseDisabledBase
from addons import views
from addons.models import Addon, AddonUser, Charity
from files.models import File
from users.helpers import users_list
from users.models import UserProfile
from stats.models import Contribution
from translations.helpers import truncate
from translations.query import order_by_translation
from users.helpers import users_list
from users.models import UserProfile
from versions.models import Version
@ -265,6 +266,16 @@ class TestContribute(test_utils.TestCase):
eq_(qs['item_name'], 'Contribution for moz')
eq_(qs['business'], 'mozcom')
contrib = Contribution.objects.get(addon=addon)
eq_(addon.charity_id, contrib.charity_id)
def test_no_org(self):
addon = Addon.objects.get(id=592)
r = self.client.get(reverse('addons.contribute', args=['a592']))
eq_(r.status_code, 302)
contrib = Contribution.objects.get(addon=addon)
eq_(contrib.charity_id, None)
class TestDeveloperPages(test_utils.TestCase):
fixtures = ['base/apps', 'base/addon_3615', 'base/addon_592',

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

@ -385,6 +385,7 @@ def contribute(request, addon):
contribution_uuid = hashlib.md5(str(uuid.uuid4())).hexdigest()
contrib = Contribution(addon_id=addon.id,
charity_id=addon.charity_id,
amount=amount,
source=source,
source_locale=request.LANG,

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

@ -136,6 +136,7 @@ class ContributionError(Exception):
class Contribution(caching.base.CachingMixin, models.Model):
addon = models.ForeignKey('addons.Addon')
charity = models.ForeignKey('addons.Charity', null=True)
amount = DecimalCharField(max_digits=9, decimal_places=2,
nullify_invalid=True, null=True)
source = models.CharField(max_length=255, null=True)

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

@ -0,0 +1,3 @@
ALTER TABLE stats_contributions
ADD COLUMN charity_id int(11) UNSIGNED,
ADD CONSTRAINT FOREIGN KEY (charity_id) REFERENCES charities (id);