Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

migrate theme licenses (bug 792112)

  • Loading branch information...
commit ab7fa296361d78d5b635c17a5e7dbf75182ddb07 1 parent 51fb938
@cvan cvan authored
View
10 apps/addons/forms.py
@@ -517,7 +517,7 @@ class ThemeForm(ThemeFormBase):
max_length=250, required=False)
tags = forms.CharField(required=False)
- license = forms.TypedChoiceField(choices=amo.PERSONA_LICENSES_IDS,
+ license = forms.TypedChoiceField(choices=amo.PERSONA_LICENSES_CHOICES,
coerce=int, empty_value=None, widget=forms.HiddenInput,
error_messages={'required': _lazy(u'A license must be selected.')})
header = forms.FileField(required=False)
@@ -582,7 +582,7 @@ def save(self, commit=False):
p.accentcolor = data['accentcolor'].lstrip('#')
if data['textcolor']:
p.textcolor = data['textcolor'].lstrip('#')
- p.license_id = data['license']
+ p.license = data['license']
p.submit = datetime.now()
p.author = user.name
p.display_username = user.username
@@ -608,7 +608,7 @@ class EditThemeForm(AddonFormBase):
tags = forms.CharField(required=False)
accentcolor = ColorField(required=False)
textcolor = ColorField(required=False)
- license = forms.TypedChoiceField(choices=amo.PERSONA_LICENSES_IDS,
+ license = forms.TypedChoiceField(choices=amo.PERSONA_LICENSES_CHOICES,
coerce=int, empty_value=None, widget=forms.HiddenInput,
error_messages={'required': _lazy(u'A license must be selected.')})
@@ -638,7 +638,7 @@ def __init__(self, *args, **kw):
self.initial['accentcolor'] = '#' + persona.accentcolor
if persona.textcolor:
self.initial['textcolor'] = '#' + persona.textcolor
- self.initial['license'] = persona.license_id
+ self.initial['license'] = persona.license
cats = sorted(Category.objects.filter(type=amo.ADDON_PERSONA,
weight__gte=0),
@@ -657,7 +657,7 @@ def save(self):
# Update Persona-specific data.
persona_data = {
- 'license_id': int(data['license']),
+ 'license': int(data['license']),
'accentcolor': data['accentcolor'].lstrip('#'),
'textcolor': data['textcolor'].lstrip('#'),
'display_username': self.request.amo_user.username
View
5 apps/addons/models.py
@@ -27,6 +27,7 @@
from addons.utils import get_featured_ids, get_creatured_ids
+import amo
import amo.models
import mkt.constants
from amo.decorators import use_master
@@ -1605,10 +1606,10 @@ class Persona(caching.CachingMixin, models.Model):
display_username = models.CharField(max_length=32, null=True)
submit = models.DateTimeField(null=True)
approve = models.DateTimeField(null=True)
-
movers = models.FloatField(null=True, db_index=True)
popularity = models.IntegerField(null=False, default=0, db_index=True)
- license = models.ForeignKey('versions.License', null=True)
+ license = models.PositiveIntegerField(choices=amo.PERSONA_LICENSES_CHOICES,
+ null=True, blank=True)
objects = caching.CachingManager()
View
5 apps/addons/templates/addons/mobile/persona_detail_table.html
@@ -13,14 +13,13 @@
<tr class="meta-stats">
<th>{{ _('Daily Users') }}</th>
<td>
- <strong class="downloads">{{
- persona.popularity|numberfmt }}</strong>
+ <strong class="downloads">{{ persona.popularity|numberfmt }}</strong>
</td>
</tr>
{% if persona.license %}
<tr>
<th>{{ _('License') }}</th>
- <td>{{ license_link(persona.license) }}</td>
+ <td>{{ license_link(amo.PERSONA_LICENSES_IDS[persona.license]) }}</td>
</tr>
{% endif %}
</tbody>
View
5 apps/addons/templates/addons/persona_detail_table.html
@@ -18,14 +18,13 @@
<tr class="meta-stats">
<th>{{ _('Daily Users') }}</th>
<td>
- <strong class="downloads">{{
- persona.popularity|numberfmt }}</strong>
+ <strong class="downloads">{{ persona.popularity|numberfmt }}</strong>
</td>
</tr>
{% if persona.license %}
<tr>
<th>{{ _('License') }}</th>
- <td>{{ license_link(persona.license) }}</td>
+ <td>{{ license_link(amo.PERSONA_LICENSES_IDS[persona.license]) }}</td>
</tr>
{% endif %}
</tbody>
View
6 apps/amo/helpers.py
@@ -382,13 +382,13 @@ def shuffle(sequence):
@register.function
def license_link(license):
- """Link to a code license, incl. icon where applicable."""
+ """Link to a code license, including icon where applicable."""
if not license:
return ''
- if not license.builtin:
+ if not getattr(license, 'builtin', True):
return _('Custom License')
- t = env.get_template('amo/license_link.html').render({'license': license})
+ t = env.get_template('amo/license_link.html').render(license=license)
return jinja2.Markup(t)
View
24 apps/amo/tests/test_helpers.py
@@ -299,6 +299,30 @@ def test_license_link(self):
s = ''.join([s.strip() for s in s.split('\n')])
eq_(s, ex)
+ def test_theme_license_link(self):
+ s = render('{{ license_link(lic) }}', {'lic': amo.LICENSE_COPYRIGHT})
+
+ ul = PyQuery(s)('.license')
+ eq_(ul.find('.icon').length, 1)
+ eq_(ul.find('.icon.copyr').length, 1)
+
+ text = ul.find('.text')
+ eq_(text.find('a').length, 0)
+ eq_(text.text(), 'All Rights Reserved')
+
+ s = render('{{ license_link(lic) }}', {'lic': amo.LICENSE_CC_BY_NC_SA})
+
+ ul = PyQuery(s)('.license')
+ eq_(ul.find('.icon').length, 3)
+ eq_(ul.find('.icon.cc-attrib').length, 1)
+ eq_(ul.find('.icon.cc-noncom').length, 1)
+ eq_(ul.find('.icon.cc-share').length, 1)
+
+ link = ul.find('.text a')
+ eq_(link.find('a').length, 0)
+ eq_(link.text(), 'Some rights reserved')
+ eq_(link.attr('href'), amo.LICENSE_CC_BY_NC_SA.url)
+
def test_license_link_xss(self):
mit = License.objects.create(
name='<script>', builtin=6, url='<script>')
View
92 apps/constants/licenses.py
@@ -1,93 +1,65 @@
-from lib.licenses import license_text
-from tower import ugettext_lazy as _
+from tower import ugettext_lazy as _lazy
# Built-in Licenses
class _LicenseBase(object):
"""Base class for built-in licenses."""
- shortname = None
- icons = None # CSS classes. See zamboni.css for a list.
- linktext = None # Link text distinct from full license name.
- on_form = True
-
- @classmethod
- def text(cls):
- return cls.shortname and license_text(cls.shortname) or None
+ icons = '' # CSS classes. See zamboni.css for a list.
+ some_rights = True
class LICENSE_COPYRIGHT(_LicenseBase):
- id = 7
- name = _(u'All Rights Reserved')
+ id = 1
+ name = _lazy(u'All Rights Reserved')
+ icons = 'copyr'
+ some_rights = False
url = None
- shortname = None
- icons = ('copyr',)
- on_form = False
-
-
-class LICENSE_CC_BY_NC_SA(_LicenseBase):
- id = 8
- name = _(u'Creative Commons Attribution-NonCommercial-Share Alike 3.0')
- linktext = _(u'Some rights reserved')
- url = 'http://creativecommons.org/licenses/by-nc-sa/3.0/'
- shortname = None
- icons = ('cc-attrib', 'cc-noncom', 'cc-share')
- on_form = False
-# TODO(cvan): Need migrations for these licenses.
class LICENSE_CC_BY(_LicenseBase):
- id = 9
- name = _(u'Creative Commons Attribution 3.0')
- linktext = _(u'Some rights reserved')
+ id = 2
+ name = _lazy(u'Creative Commons Attribution 3.0')
url = 'http://creativecommons.org/licenses/by/3.0/'
- shortname = None
- icons = ('cc-attrib',)
- on_form = False
+ icons = 'cc-attrib'
class LICENSE_CC_BY_NC(_LicenseBase):
- id = 10
- name = _(u'Creative Commons Attribution-NonCommercial 3.0')
- linktext = _(u'Some rights reserved')
+ id = 3
+ icons = 'cc-attrib cc-noncom'
+ name = _lazy(u'Creative Commons Attribution-NonCommercial 3.0')
url = 'http://creativecommons.org/licenses/by-nc/3.0/'
- shortname = None
- icons = ('cc-attrib', 'cc-noncom')
- on_form = False
class LICENSE_CC_BY_NC_ND(_LicenseBase):
- id = 11
- name = _(u'Creative Commons Attribution-NonCommercial-NoDerivs 3.0')
- linktext = _(u'Some rights reserved')
+ id = 4
+ icons = 'cc-attrib cc-noncom cc-noderiv'
+ name = _lazy(u'Creative Commons Attribution-NonCommercial-NoDerivs 3.0')
url = 'http://creativecommons.org/licenses/by-nc-nd/3.0/'
- shortname = None
- icons = ('cc-attrib', 'cc-noncom', 'cc-noderiv')
- on_form = False
+
+
+class LICENSE_CC_BY_NC_SA(_LicenseBase):
+ id = 5
+ icons = 'cc-attrib cc-noncom cc-share'
+ name = _lazy(u'Creative Commons Attribution-NonCommercial-Share Alike 3.0')
+ url = 'http://creativecommons.org/licenses/by-nc-sa/3.0/'
class LICENSE_CC_BY_ND(_LicenseBase):
- id = 12
- name = _(u'Creative Commons Attribution-NoDerivs 3.0')
- linktext = _(u'Some rights reserved')
+ id = 6
+ icons = 'cc-attrib cc-noderiv'
+ name = _lazy(u'Creative Commons Attribution-NoDerivs 3.0')
url = 'http://creativecommons.org/licenses/by-nd/3.0/'
- shortname = None
- icons = ('cc-attrib', 'cc-noderiv')
- on_form = False
class LICENSE_CC_BY_SA(_LicenseBase):
- id = 13
- name = _(u'Creative Commons Attribution-ShareAlike 3.0')
- linktext = _(u'Some rights reserved')
+ id = 7
+ icons = 'cc-attrib cc-share'
+ name = _lazy(u'Creative Commons Attribution-ShareAlike 3.0')
url = 'http://creativecommons.org/licenses/by-sa/3.0/'
- shortname = None
- icons = ('cc-attrib', 'cc-share')
- on_form = False
-PERSONA_LICENSES = (LICENSE_CC_BY, LICENSE_CC_BY_NC,
+PERSONA_LICENSES = (LICENSE_COPYRIGHT, LICENSE_CC_BY, LICENSE_CC_BY_NC,
LICENSE_CC_BY_NC_ND, LICENSE_CC_BY_NC_SA, LICENSE_CC_BY_ND,
LICENSE_CC_BY_SA)
-
-PERSONA_LICENSES = (LICENSE_COPYRIGHT,) + PERSONA_LICENSES
-PERSONA_LICENSES_IDS = [(l.id, l) for l in PERSONA_LICENSES]
+PERSONA_LICENSES_CHOICES = [(l.id, l) for l in PERSONA_LICENSES]
+PERSONA_LICENSES_IDS = dict(PERSONA_LICENSES_CHOICES)
View
14 apps/devhub/tests/test_forms.py
@@ -367,7 +367,7 @@ def test_success(self, save_persona_image_mock,
self.assertSetEqual(addon.tags.values_list('tag_text', flat=True),
data['tags'].split(', '))
eq_(persona.persona_id, 0)
- eq_(persona.license_id, data['license'])
+ eq_(persona.license, data['license'])
eq_(persona.accentcolor, data['accentcolor'].lstrip('#'))
eq_(persona.textcolor, data['textcolor'].lstrip('#'))
eq_(persona.author, self.request.amo_user.name)
@@ -415,10 +415,9 @@ def populate(self):
self.cat = Category.objects.create(
type=amo.ADDON_PERSONA, name='xxxx')
self.instance.addoncategory_set.create(category=self.cat)
- self.license = License.objects.create(id=amo.LICENSE_CC_BY.id)
+ self.license = amo.LICENSE_CC_BY.id
Persona.objects.create(persona_id=0, addon_id=self.instance.id,
- license_id=self.license.id, accentcolor='C0FFEE',
- textcolor='EFFFFF')
+ license=self.license, accentcolor='C0FFEE', textcolor='EFFFFF')
Tag(tag_text='sw').save_tag(self.instance)
Tag(tag_text='ag').save_tag(self.instance)
@@ -426,7 +425,7 @@ def get_dict(self, **kw):
data = {
'accentcolor': '#C0FFEE',
'category': self.cat.id,
- 'license': self.license.id,
+ 'license': self.license,
'name': unicode(self.instance.name),
'slug': self.instance.slug,
'summary': self.instance.summary.id,
@@ -443,11 +442,10 @@ def test_initial(self):
def save_success(self):
other_cat = Category.objects.create(type=amo.ADDON_PERSONA)
- other_license = License.objects.create(id=amo.LICENSE_CC_BY_NC_SA.id)
self.data = {
'accentcolor': '#EFF0FF',
'category': other_cat.id,
- 'license': other_license.id,
+ 'license': amo.LICENSE_CC_BY_NC_SA.id,
'name': 'All Day I Dream About Swag',
'slug': 'swag-lifestyle',
'summary': 'ADIDAS',
@@ -467,7 +465,7 @@ def test_success(self):
eq_(unicode(self.instance.persona.accentcolor),
self.data['accentcolor'].lstrip('#'))
eq_(self.instance.categories.all()[0].id, self.data['category'])
- eq_(self.instance.persona.license.id, self.data['license'])
+ eq_(self.instance.persona.license, self.data['license'])
eq_(unicode(self.instance.name), self.data['name'])
eq_(unicode(self.instance.summary), self.data['summary'])
self.assertSetEqual(
View
20 media/js/impala/persona_creation.js
@@ -28,41 +28,41 @@
var licensesByClass = {
'copyr': {
- 'id': 7,
+ 'id': 1,
'name': gettext('All Rights Reserved')
},
'cc-attrib': {
- 'id': 9,
+ 'id': 2,
'name': gettext('Creative Commons Attribution 3.0'),
'url': 'http://creativecommons.org/licenses/by/3.0/'
},
'cc-attrib cc-noncom': {
- 'id': 10,
+ 'id': 3,
'name': gettext('Creative Commons Attribution-NonCommercial 3.0'),
'url': 'http://creativecommons.org/licenses/by-nc/3.0/'
},
'cc-attrib cc-noncom cc-noderiv': {
- 'id': 11,
+ 'id': 4,
'name': gettext('Creative Commons Attribution-NonCommercial-NoDerivs 3.0'),
'url': 'http://creativecommons.org/licenses/by/3.0/'
},
'cc-attrib cc-noncom cc-share': {
- 'id': 8,
+ 'id': 5,
'name': gettext('Creative Commons Attribution-NonCommercial-Share Alike 3.0'),
'url': 'http://creativecommons.org/licenses/by-nc-sa/3.0/'
},
'cc-attrib cc-noderiv': {
- 'id': 12,
+ 'id': 6,
'name': gettext('Creative Commons Attribution-NoDerivs 3.0'),
'url': 'http://creativecommons.org/licenses/by-nd/3.0/'
},
'cc-attrib cc-share': {
- 'id': 13,
+ 'id': 7,
'name': gettext('Creative Commons Attribution-ShareAlike 3.0'),
'url': 'http://creativecommons.org/licenses/by/3.0/'
}
};
- // Build an object for lookups by id: {{7: 'copyr'}, {9: 'cc-attrib'}, ...}.
+ // Build an object for lookups by id: {{1: 'copyr'}, {2: 'cc-attrib'}, ...}.
var licenseClassesById = _.object(_.map(licensesByClass, function(v, k) {
return [v.id, k];
}));
@@ -118,7 +118,7 @@
$form.delegate('input[name="cc-attrib"]', 'change', function() {
// Toggle the other license options based on whether the copyright license is selected.
- toggleCopyr($licenseField.val() == 7);
+ toggleCopyr(+$licenseField.val() == licensesByClass.copyr.id);
}).delegate('#persona-license-list input[type=radio][name=license]', 'change', function() {
// Upon selecting license from advanced menu, change it in the Q/A format.
$('.noncc.disabled').removeClass('disabled');
@@ -132,7 +132,7 @@
// Default to copyright license.
if (!$licenseField.val()) {
- $licenseField.val('7');
+ $licenseField.val(licensesByClass.copyr.id);
}
$('input[data-cc="copyr"]').trigger('change');
View
26 migrations/555-theme-licenses.sql
@@ -0,0 +1,26 @@
+-- Instead of a foreign-key relationship, `license` corresponds to an ID
+-- for a license constant.
+alter table personas drop foreign key personas_ibfk_4;
+
+alter table personas change column license license int(11) unsigned null;
+
+-- All Rights Reserved
+update personas set license = 1 where license in (7, 1034);
+
+-- Creative Commons Attribution 3.0
+update personas set license = 2 where license = 9;
+
+-- Creative Commons Attribution-NonCommercial 3.0
+update personas set license = 3 where license = 10;
+
+-- Creative Commons Attribution-NonCommercial-NoDerivs 3.0
+update personas set license = 4 where license = 11;
+
+-- Creative Commons Attribution-Noncommercial-Share Alike 3.0
+update personas set license = 5 where license in (8, 1035);
+
+-- Creative Commons Attribution-NoDerivs 3.0
+update personas set license = 6 where license = 12;
+
+-- Creative Commons Attribution-ShareAlike 3.0
+update personas set license = 7 where license = 13;
Please sign in to comment.
Something went wrong with that request. Please try again.