remove device types from Submit Details submission step (bug 807871)

This commit is contained in:
Chris Van 2012-11-09 14:11:29 -08:00
Родитель 30c472f2dc
Коммит 3d13f52914
4 изменённых файлов: 28 добавлений и 45 удалений

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

@ -109,8 +109,8 @@ class NewWebappForm(NewWebappVersionForm):
ERRORS = {'both': _lazy(u'Cannot be free and paid.'),
'none': _lazy(u'Please select a device.'),
'packaged': _lazy(u'Packaged apps are only valid '
u'for Firefox OS.')}
'packaged': _lazy(u'Packaged apps are valid '
u'for only Firefox OS.')}
upload = forms.ModelChoiceField(widget=forms.HiddenInput,
queryset=FileUpload.objects.filter(valid=True),
@ -122,11 +122,9 @@ class NewWebappForm(NewWebappVersionForm):
free = forms.MultipleChoiceField(choices=FREE, required=False)
paid = forms.MultipleChoiceField(choices=PAID, required=False)
def _add_error(self, msg):
self._errors['free'] = self._errors['paid'] = self.ERRORS[msg]
def _get_combined(self):
return set(self.cleaned_data.get('free', []) +
self.cleaned_data.get('paid', []))

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

@ -126,8 +126,6 @@
{{ form_field(form_basic.flash, hint=True) }}
{{ form_field(form_devices.device_types) }}
<div>
<label>
{% if waffle.switch('video-upload') %}

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

@ -491,6 +491,7 @@ class TestDetails(TestSubmit):
self.dtype = DEVICE_TYPES.values()[0]
AddonDeviceType.objects.create(addon=self.webapp,
device_type=self.dtype.id)
self.device_types = [self.dtype]
# Associate category with app.
self.cat1 = Category.objects.create(type=amo.ADDON_WEBAPP, name='Fun')
@ -546,7 +547,6 @@ class TestDetails(TestSubmit):
'homepage': 'http://www.goodreads.com/user/show/7595895-krupa',
'support_url': 'http://www.goodreads.com/user_challenges/351558',
'support_email': 'krupa+to+the+rescue@goodreads.com',
'device_types': [self.dtype.id],
'categories': [self.cat1.id],
'flash': 'checked',
}
@ -580,7 +580,7 @@ class TestDetails(TestSubmit):
got = unicode(getattr(addon, field))
eq_(got, expected,
'Expected %r for %r. Got %r.' % (expected, field, got))
eq_(list(addon.device_types), [self.dtype])
self.assertSetEqual(addon.device_types, self.device_types)
def test_success(self):
self._step()
@ -591,6 +591,24 @@ class TestDetails(TestSubmit):
self.webapp = self.get_webapp()
self.assert3xx(r, self.get_url('done'))
def test_success_prefill_device_types_if_empty(self):
"""
The new submission flow asks for device types at step one.
This ensures that existing incomplete apps still have device
compatibility.
"""
self._step()
AddonDeviceType.objects.all().delete()
self.device_types = amo.DEVICE_TYPES.values()
data = self.get_dict()
r = self.client.post(self.url, data)
self.assertNoFormErrors(r)
self.check_dict(data=data)
self.webapp = self.get_webapp()
self.assert3xx(r, self.get_url('done'))
def test_no_video_types(self):
self._step()
res = self.client.get(self.url)
@ -802,39 +820,6 @@ class TestDetails(TestSubmit):
self.assertFormError(r, 'form_basic', 'support_email',
'Enter a valid e-mail address.')
def test_device_types_required(self):
self._step()
r = self.client.post(self.url, self.get_dict(device_types=None))
self.assertFormError(r, 'form_devices', 'device_types',
'This field is required.')
def test_device_types_invalid(self):
self._step()
r = self.client.post(self.url, self.get_dict(device_types='999'))
self.assertFormError(r, 'form_devices', 'device_types',
'Select a valid choice. 999 is not one of the available choices.')
def test_device_types_default(self):
self._step()
# Add the rest of the device types. We already add [0] in _step().
for d_id in DEVICE_TYPES.keys()[1:]:
AddonDeviceType.objects.create(addon=self.webapp,
device_type=d_id)
r = self.client.get(self.url)
eq_(r.status_code, 200)
checkboxes = pq(r.content)('input[name=device_types]')
eq_(checkboxes.filter(':checked').length, checkboxes.length,
'All device types should be checked by default.')
def test_device_types_default_on_post(self):
self._step()
r = self.client.post(self.url, self.get_dict(device_types=None))
eq_(r.status_code, 200)
checkboxes = pq(r.content)('input[name=device_types]')
eq_(checkboxes.filter(':checked').length, 0,
'POSTed values should not get replaced by the defaults.')
def test_categories_required(self):
self._step()
r = self.client.post(self.url, self.get_dict(categories=[]))

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

@ -11,7 +11,6 @@ from waffle.decorators import waffle_switch
import amo
from amo.decorators import login_required
from amo.urlresolvers import reverse
from addons.forms import DeviceTypeForm
from addons.models import Addon, AddonUser
from files.models import Platform
from users.models import UserProfile
@ -130,7 +129,6 @@ def details(request, addon_id, addon):
request=request)
form_cats = CategoryForm(request.POST or None, product=addon,
request=request)
form_devices = DeviceTypeForm(request.POST or None, addon=addon)
form_icon = AppFormMedia(request.POST or None, request.FILES or None,
instance=addon, request=request)
form_previews = PreviewFormSet(request.POST or None, prefix='files',
@ -151,7 +149,6 @@ def details(request, addon_id, addon):
request.POST[othername] = value
forms = {
'form_basic': form_basic,
'form_devices': form_devices,
'form_cats': form_cats,
'form_icon': form_icon,
'form_previews': form_previews,
@ -159,12 +156,17 @@ def details(request, addon_id, addon):
if request.POST and all(f.is_valid() for f in forms.itervalues()):
addon = form_basic.save(addon)
form_devices.save(addon)
form_cats.save()
form_icon.save(addon)
for preview in form_previews.forms:
preview.save(addon)
# If this is an incomplete app from the legacy submission flow, it may
# not have device types set yet - so assume it works everywhere.
if not addon.device_types:
for device in amo.DEVICE_TYPES:
addon.addondevicetype_set.create(device_type=device)
tasks.generate_image_assets.delay(addon)
AppSubmissionChecklist.objects.get(addon=addon).update(details=True)