make an endpoint for removing a locale from an add-on (bug 650392)
This commit is contained in:
Родитель
f3462b1b92
Коммит
07f11165ba
|
@ -837,6 +837,13 @@ class Addon(amo.models.OnChangeMixin, amo.models.ModelBase):
|
|||
app_cats.append((amo.APP_IDS[app], list(cats)))
|
||||
return app_cats
|
||||
|
||||
def remove_locale(self, locale):
|
||||
"""NULLify the add-on's strings in this locale."""
|
||||
ids = [getattr(self, f.attname) for f in self._meta.translated_fields]
|
||||
qs = Translation.objects.filter(id__in=filter(None, ids),
|
||||
locale=locale)
|
||||
qs.update(localized_string=None, localized_string_clean=None)
|
||||
|
||||
|
||||
def update_name_table(sender, **kw):
|
||||
from . import cron
|
||||
|
|
|
@ -25,7 +25,7 @@ from devhub.models import ActivityLog
|
|||
from files.models import File, Platform
|
||||
from files.tests.test_models import UploadTest
|
||||
from reviews.models import Review
|
||||
from translations.models import TranslationSequence
|
||||
from translations.models import TranslationSequence, Translation
|
||||
from users.models import UserProfile
|
||||
from versions.models import ApplicationsVersions, Version
|
||||
|
||||
|
@ -1240,3 +1240,17 @@ class TestFrozenAddons(test_utils.TestCase):
|
|||
a = Addon.objects.create(type=1, hotness=22)
|
||||
FrozenAddon.objects.create(addon=a)
|
||||
eq_(Addon.objects.get(id=a.id).hotness, 0)
|
||||
|
||||
|
||||
class TestRemoveLocale(test_utils.TestCase):
|
||||
|
||||
def test_remove(self):
|
||||
a = Addon.objects.create(type=1)
|
||||
a.name = {'en-US': 'woo', 'el': 'yeah'}
|
||||
a.description = {'en-US': 'woo', 'el': 'yeah', 'he': 'ola'}
|
||||
a.save()
|
||||
a.remove_locale('el')
|
||||
qs = (Translation.objects.filter(localized_string__isnull=False)
|
||||
.values_list('locale', flat=True))
|
||||
eq_(sorted(qs.filter(id=a.name_id)), ['en-US'])
|
||||
eq_(sorted(qs.filter(id=a.description_id)), ['en-US', 'he'])
|
||||
|
|
|
@ -38,6 +38,7 @@ from files.models import File, FileUpload, Platform, FileValidation
|
|||
from files.tests.test_models import UploadTest as BaseUploadTest
|
||||
from reviews.models import Review
|
||||
from tags.models import Tag, AddonTag
|
||||
from translations.models import Translation
|
||||
from users.models import UserProfile
|
||||
from versions.models import ApplicationsVersions, License, Version
|
||||
|
||||
|
@ -3296,3 +3297,31 @@ class TestNewsletter(test_utils.TestCase):
|
|||
# Test call to responsys
|
||||
eq_(v.call_args[0], ('http://awesomeness.mozilla.org/pub/rf',))
|
||||
assert(urlencode({'EMAIL_ADDRESS_': email}) in v.call_args[1]['data'])
|
||||
|
||||
|
||||
class TestRemoveLocale(test_utils.TestCase):
|
||||
fixtures = ['base/apps', 'base/users', 'base/addon_3615']
|
||||
|
||||
def setUp(self):
|
||||
self.url = reverse('devhub.remove-locale', args=['a3615'])
|
||||
assert self.client.login(username='del@icio.us', password='password')
|
||||
|
||||
def test_bad_request(self):
|
||||
r = self.client.post(self.url)
|
||||
eq_(r.status_code, 400)
|
||||
|
||||
def test_success(self):
|
||||
a = Addon.objects.get(id=3615)
|
||||
a.name = {'en-US': 'woo', 'el': 'yeah'}
|
||||
a.save()
|
||||
a.remove_locale('el')
|
||||
qs = (Translation.objects.filter(localized_string__isnull=False)
|
||||
.values_list('locale', flat=True))
|
||||
r = self.client.post(self.url, {'locale': 'el'})
|
||||
eq_(r.status_code, 200)
|
||||
eq_(sorted(qs.filter(id=a.name_id)), ['en-US'])
|
||||
|
||||
def test_delete_default_locale(self):
|
||||
a = Addon.objects.get(id=3615)
|
||||
r = self.client.post(self.url, {'locale': a.default_locale})
|
||||
eq_(r.status_code, 400)
|
||||
|
|
|
@ -68,6 +68,7 @@ detail_patterns = patterns('',
|
|||
url('^request-review/(?P<status>[%s])$'
|
||||
% ''.join(map(str, views.REQUEST_REVIEW)),
|
||||
views.request_review, name='devhub.request-review'),
|
||||
url('^rmlocale$', views.remove_locale, name='devhub.remove-locale'),
|
||||
)
|
||||
|
||||
# These will all start with /ajax/addon/<addon_id>/
|
||||
|
|
|
@ -1005,6 +1005,16 @@ def submit_select_review(request, addon_id, addon, step):
|
|||
'step': step})
|
||||
|
||||
|
||||
@dev_required
|
||||
@post_required
|
||||
def remove_locale(request, addon_id, addon):
|
||||
POST = request.POST
|
||||
if 'locale' in POST and POST['locale'] != addon.default_locale:
|
||||
addon.remove_locale(POST['locale'])
|
||||
return http.HttpResponse()
|
||||
return http.HttpResponseBadRequest()
|
||||
|
||||
|
||||
@dev_required
|
||||
@submit_step(7)
|
||||
def submit_done(request, addon_id, addon, step):
|
||||
|
|
Загрузка…
Ссылка в новой задаче