create a list of addons installed (bug 696509)
This commit is contained in:
Родитель
481274a246
Коммит
840dad6fe5
|
@ -104,3 +104,13 @@ models.signals.post_save.connect(update_search_index, sender=Webapp,
|
|||
dispatch_uid='webapps.index')
|
||||
models.signals.post_delete.connect(delete_search_index, sender=Webapp,
|
||||
dispatch_uid='webapps.unindex')
|
||||
|
||||
|
||||
class Installed(amo.models.ModelBase):
|
||||
"""Track WebApp installations."""
|
||||
addon = models.ForeignKey('addons.Addon')
|
||||
user = models.ForeignKey('users.UserProfile')
|
||||
|
||||
class Meta:
|
||||
db_table = 'users_install'
|
||||
unique_together = ('addon', 'user')
|
||||
|
|
|
@ -50,7 +50,7 @@ class TestListing(WebappTest):
|
|||
self.url + '?sort=downloads')
|
||||
eq_(doc('#featured-apps a').attr('href'), self.url + '?sort=featured')
|
||||
eq_(doc('#submit-app a').attr('href'), reverse('devhub.submit_apps.1'))
|
||||
|
||||
|
||||
@patch.object(settings, 'READ_ONLY', False)
|
||||
def test_balloons_no_readonly(self):
|
||||
response = self.client.get(self.url)
|
||||
|
@ -58,7 +58,7 @@ class TestListing(WebappTest):
|
|||
eq_(doc('#site-notice').length, 0)
|
||||
eq_(doc('#site-nonfx').length, 0)
|
||||
eq_(doc('#site-welcome').length, 0)
|
||||
|
||||
|
||||
@patch.object(settings, 'READ_ONLY', True)
|
||||
def test_balloons_readonly(self):
|
||||
response = self.client.get(self.url)
|
||||
|
@ -197,3 +197,31 @@ class TestSharing(WebappTest):
|
|||
}
|
||||
url = iri_to_uri(SERVICES['delicious'].url.format(**d))
|
||||
self.assertRedirects(r, url, status_code=302, target_status_code=301)
|
||||
|
||||
|
||||
class TestInstall(amo.tests.TestCase):
|
||||
fixtures = ['base/users']
|
||||
|
||||
def setUp(self):
|
||||
self.addon = Addon.objects.create(type=amo.ADDON_WEBAPP)
|
||||
self.addon.update(app_slug=self.addon.pk)
|
||||
self.user = UserProfile.objects.get(email='regular@mozilla.com')
|
||||
self.url = reverse('apps.record', args=[self.addon.app_slug])
|
||||
assert self.client.login(username='regular@mozilla.com',
|
||||
password='password')
|
||||
|
||||
def test_record_logged_out(self):
|
||||
self.client.logout()
|
||||
res = self.client.post(self.url)
|
||||
eq_(res.status_code, 302)
|
||||
|
||||
def test_record_install(self):
|
||||
res = self.client.post(self.url)
|
||||
eq_(res.status_code, 200)
|
||||
eq_(self.user.installed_set.count(), 1)
|
||||
|
||||
def test_record_multiple_installs(self):
|
||||
self.client.get(self.url)
|
||||
res = self.client.post(self.url)
|
||||
eq_(res.status_code, 200)
|
||||
eq_(self.user.installed_set.count(), 1)
|
||||
|
|
|
@ -11,7 +11,8 @@ detail_patterns = patterns('',
|
|||
url('^$', views.app_detail, name='apps.detail'),
|
||||
url('^more$', views.app_detail, name='apps.detail_more'),
|
||||
url('^share$', views.share, name='apps.share'),
|
||||
url('^abuse$', addons_views.report_abuse, name='apps.abuse')
|
||||
url('^abuse$', addons_views.report_abuse, name='apps.abuse'),
|
||||
url('^record$', views.record, name='apps.record'),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -4,11 +4,13 @@ import jingo
|
|||
from tower import ugettext_lazy as _lazy
|
||||
|
||||
import amo
|
||||
from amo.decorators import json_view, login_required, post_required
|
||||
from amo.utils import paginate
|
||||
from addons.decorators import addon_view
|
||||
import addons.views
|
||||
import search.views
|
||||
|
||||
from addons.models import Addon, Category
|
||||
from addons.models import Category
|
||||
from browse.views import category_landing, CategoryLandingFilter
|
||||
from sharing.views import share as share_redirect
|
||||
from .models import Webapp
|
||||
|
@ -88,3 +90,13 @@ def app_detail(request, app_slug):
|
|||
def share(request, app_slug):
|
||||
webapp = get_object_or_404(Webapp, app_slug=app_slug)
|
||||
return share_redirect(request, webapp, webapp.name, webapp.summary)
|
||||
|
||||
|
||||
@json_view
|
||||
@addon_view
|
||||
@login_required
|
||||
@post_required
|
||||
def record(request, addon):
|
||||
if not request.amo_user.installed_set.filter(addon=addon).exists():
|
||||
request.amo_user.installed_set.create(addon=addon)
|
||||
return {'addon': addon.pk}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE users_install (
|
||||
id int(11) unsigned AUTO_INCREMENT NOT NULL PRIMARY KEY,
|
||||
created datetime NOT NULL,
|
||||
modified datetime NOT NULL,
|
||||
addon_id int(11) unsigned NOT NULL,
|
||||
user_id int(11) unsigned NOT NULL,
|
||||
UNIQUE (addon_id, user_id)
|
||||
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
|
||||
|
||||
ALTER TABLE users_install ADD CONSTRAINT addon_id_refs_id FOREIGN KEY (addon_id) REFERENCES addons (id);
|
||||
ALTER TABLE users_install ADD CONSTRAINT user_id_refs_id FOREIGN KEY (user_id) REFERENCES users (id);
|
||||
CREATE INDEX users_install_addon_idx ON users_install (addon_id);
|
||||
CREATE INDEX users_install_user_idx ON users_install (user_id);
|
Загрузка…
Ссылка в новой задаче