Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 1adb7fe

Browse files
author
Andy McKay
committed
allow devs to specify uses_flash (bug 790654)
1 parent 5fa8599 commit 1adb7fe

File tree

9 files changed

+73
-86
lines changed

9 files changed

+73
-86
lines changed

apps/amo/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ def recaptcha(context, form):
423423
@register.filter
424424
def is_choice_field(value):
425425
try:
426-
return isinstance(value.field.widget, CheckboxInput)
426+
return (hasattr(value.field, 'choices') and
427+
isinstance(value.field.widget, CheckboxInput))
427428
except AttributeError:
428429
pass
429430

mkt/developers/forms.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ class AdminSettingsForm(PreviewForm):
333333
app_ratings = forms.MultipleChoiceField(
334334
required=False,
335335
choices=RATINGS_BY_NAME)
336-
flash = forms.BooleanField(required=False)
337336

338337
class Meta:
339338
model = Preview
@@ -359,7 +358,6 @@ def __init__(self, *args, **kw):
359358
rating = RATINGS_BODIES[r.ratings_body].ratings[r.rating]
360359
rs.append(ALL_RATINGS.index(rating))
361360
self.initial['app_ratings'] = rs
362-
self.initial['flash'] = addon.uses_flash
363361

364362
def clean_caption(self):
365363
return '__promo__'
@@ -983,3 +981,24 @@ def __init__(self, *args, **kw):
983981
def save(self):
984982
self.instance.read_dev_agreement = datetime.now()
985983
self.instance.save()
984+
985+
986+
class AppFormTechnical(addons.forms.AddonFormBase):
987+
developer_comments = TransField(widget=TransTextarea, required=False)
988+
flash = forms.BooleanField(required=False)
989+
990+
class Meta:
991+
model = Addon
992+
fields = ('developer_comments',)
993+
994+
def __init__(self, *args, **kw):
995+
super(AppFormTechnical, self).__init__(*args, **kw)
996+
self.initial['flash'] = self.instance.uses_flash
997+
998+
def save(self, addon, commit=False):
999+
uses_flash = self.cleaned_data.get('flash')
1000+
af = self.instance.get_latest_file()
1001+
if af is not None:
1002+
af.update(uses_flash=bool(uses_flash))
1003+
1004+
return super(AppFormTechnical, self).save(commit=True)

mkt/developers/templates/developers/apps/edit/admin.html

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,28 +102,6 @@ <h2>
102102
{% endif %}
103103
</td>
104104
</tr>
105-
<tr>
106-
<th>
107-
<label for="flash">
108-
{{ _('Uses Flash') }}
109-
{{ tip(None,
110-
_('Whether or not this app should be excluded for devices without Flash support.')) }}
111-
</label>
112-
</th>
113-
<td>
114-
{% if editable and form %}
115-
{{ form.flash }}
116-
{{ form.flash.error }}
117-
{% else %}
118-
<input type="checkbox"
119-
{% if addon.uses_flash %}
120-
checked="checked"
121-
{% endif %}
122-
disabled="disabled">
123-
{% endif %}
124-
</td>
125-
</tr>
126-
127105
</tbody>
128106
</table>
129107
{% if editable %}

mkt/developers/templates/developers/apps/edit/technical.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ <h2>
3939
{% endif %}
4040
</td>
4141
</tr>
42+
<tr>
43+
<th>
44+
<label for="flash">
45+
{{ _('Uses Flash') }}
46+
{{ tip(None,
47+
_('Whether or not this app should be excluded for devices without Flash support.')) }}
48+
</label>
49+
</th>
50+
<td>
51+
{% if editable and form %}
52+
{{ form.flash }}
53+
{{ form.flash.error }}
54+
{% else %}
55+
<input type="checkbox"
56+
{% if addon.uses_flash %}
57+
checked="checked"
58+
{% endif %}
59+
disabled="disabled">
60+
{% endif %}
61+
</td>
62+
</tr>
4263
{% if waffle.switch('app-stats') %}
4364
<tr>
4465
<th>

mkt/developers/tests/test_views_edit.py

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ def compare(self, data):
9494
webapp = self.get_webapp()
9595
for k, v in data.iteritems():
9696
k = mapping.get(k, k)
97-
9897
val = getattr(webapp, k, '')
9998
if callable(val):
10099
val = val()
100+
if val is None:
101+
val = ''
101102

102103
eq_(unicode(val), unicode(v))
103104

@@ -1387,38 +1388,25 @@ def test_log(self):
13871388
def test_toggles(self):
13881389
# Turn everything on.
13891390
data = dict(developer_comments='Test comment!',
1390-
external_software='on',
1391-
site_specific='on',
1392-
view_source='on')
1393-
1391+
flash='checked')
13941392
r = self.client.post(self.edit_url, formset(**data))
13951393
self.assertNoFormErrors(r)
13961394
expected = dict(developer_comments='Test comment!',
1397-
external_software=True,
1398-
site_specific=True,
1399-
view_source=True)
1395+
uses_flash=True)
14001396
self.compare(expected)
14011397

14021398
# And off.
14031399
r = self.client.post(self.edit_url,
14041400
formset(developer_comments='Test comment!'))
1405-
expected.update(external_software=False,
1406-
site_specific=False,
1407-
view_source=False)
1401+
expected.update(uses_flash=False)
14081402
self.compare(expected)
14091403

14101404
def test_devcomment_optional(self):
1411-
data = dict(developer_comments='',
1412-
external_software='on',
1413-
site_specific='on',
1414-
view_source='on')
1405+
data = dict(developer_comments='')
14151406
r = self.client.post(self.edit_url, formset(**data))
14161407
self.assertNoFormErrors(r)
14171408

1418-
expected = dict(developer_comments='',
1419-
external_software=True,
1420-
site_specific=True,
1421-
view_source=True)
1409+
expected = dict(developer_comments='')
14221410
self.compare(expected)
14231411

14241412

@@ -1584,42 +1572,6 @@ def test_ratings_view(self):
15841572
'%s - %s' % (RATINGS_BODIES[0].name,
15851573
RATINGS_BODIES[0].ratings[2].name))
15861574

1587-
def test_set_flash(self):
1588-
self.log_in_with('Apps:Configure')
1589-
r = self.client.post(self.edit_url,
1590-
{'caption': 'x',
1591-
'position': '1',
1592-
'upload_hash': 'abcdef',
1593-
'flash': 'checked'})
1594-
eq_(r.status_code, 200)
1595-
assert self.webapp.uses_flash
1596-
1597-
def test_unset_flash(self):
1598-
self.webapp.versions.latest().files.latest().update(uses_flash=True)
1599-
self.log_in_with('Apps:Configure')
1600-
r = self.client.post(self.edit_url,
1601-
{'caption': 'x',
1602-
'position': '1',
1603-
'upload_hash': 'abcdef',
1604-
'flash': ''})
1605-
eq_(r.status_code, 200)
1606-
assert not self.webapp.uses_flash
1607-
1608-
def test_flash_set_view(self):
1609-
self.log_in_with('Apps:ViewConfiguration')
1610-
self.webapp.versions.latest().files.latest().update(uses_flash=True)
1611-
r = self.client.get(self.url)
1612-
checkbox = pq(r.content)[0].xpath(
1613-
"//label[@for='flash']/../../td/input")[0]
1614-
eq_(checkbox.get('checked'), 'checked')
1615-
1616-
def test_flash_unset_view(self):
1617-
self.log_in_with('Apps:ViewConfiguration')
1618-
r = self.client.get(self.url)
1619-
checkbox = pq(r.content)[0].xpath(
1620-
"//label[@for='flash']/../../td/input")[0]
1621-
eq_(checkbox.get('checked'), None)
1622-
16231575

16241576
class TestPromoUpload(TestAdmin):
16251577

mkt/developers/views.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858
from mkt.constants import APP_IMAGE_SIZES, MAX_PACKAGED_APP_SIZE, regions
5959
from mkt.developers.decorators import dev_required
6060
from mkt.developers.forms import (AppFormBasic, AppFormDetails, AppFormMedia,
61-
AppFormSupport, CategoryForm,
62-
ImageAssetFormSet, InappConfigForm,
63-
PaypalSetupForm, PreviewFormSet, RegionForm,
64-
trap_duplicate)
61+
AppFormSupport, AppFormTechnical,
62+
CategoryForm, ImageAssetFormSet,
63+
InappConfigForm,PaypalSetupForm,
64+
PreviewFormSet, RegionForm, trap_duplicate)
6565
from mkt.developers.models import AddonBlueViaConfig, BlueViaConfig
6666
from mkt.developers.utils import check_upload
6767
from mkt.inapp_pay.models import InappConfig
@@ -1061,7 +1061,7 @@ def addons_section(request, addon_id, addon, section, editable=False,
10611061
'media': AppFormMedia,
10621062
'details': AppFormDetails,
10631063
'support': AppFormSupport,
1064-
'technical': addon_forms.AddonFormTechnical,
1064+
'technical': AppFormTechnical,
10651065
'admin': forms.AdminSettingsForm}
10661066

10671067
if section not in models:

mkt/submit/forms.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,20 @@ class AppDetailsBasicForm(AddonFormBasic):
306306
help_text=_lazy(u'The email address used by end users to contact you '
307307
'with support issues and refund requests.'),
308308
widget=TransInput(attrs={'class': 'full'}))
309+
flash = forms.BooleanField(required=False,
310+
label=_lazy(u'Uses Flash:'),
311+
help_text=_lazy(u'Whether or not this app should be excluded for '
312+
u'devices without Flash support.'))
309313

310314
class Meta:
311315
model = Addon
312-
fields = ('name', 'slug', 'summary', 'tags', 'description',
316+
fields = ('flash', 'name', 'slug', 'summary', 'tags', 'description',
313317
'privacy_policy', 'homepage', 'support_url', 'support_email')
318+
319+
def save(self, *args, **kw):
320+
uses_flash = self.cleaned_data.get('flash')
321+
af = self.instance.get_latest_file()
322+
if af is not None:
323+
af.update(uses_flash=bool(uses_flash))
324+
325+
return super(AppDetailsBasicForm, self).save(*args, **kw)

mkt/submit/templates/submit/details.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ <h2 class="output">{{ addon.name }}</h2>
124124
{{ form_field(form_basic.support_email, hint=True) }}
125125
</div>
126126

127+
{{ form_field(form_basic.flash, hint=True) }}
128+
127129
{{ form_field(form_devices.device_types) }}
128130

129131
<div>

mkt/submit/tests/test_views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ def get_dict(self, **kw):
546546
'support_email': 'krupa+to+the+rescue@goodreads.com',
547547
'device_types': [self.dtype.id],
548548
'categories': [self.cat1.id],
549+
'flash': 'checked',
549550
}
550551
# Add the required screenshot.
551552
data.update(self.preview_formset({
@@ -569,6 +570,7 @@ def check_dict(self, data=None, expected=None):
569570
'summary': 'Hello!',
570571
'description': 'desc',
571572
'privacy_policy': 'XXX &lt;script&gt;alert("xss")&lt;/script&gt;',
573+
'uses_flash': 'True',
572574
}
573575
expected.update(expected)
574576

0 commit comments

Comments
 (0)