Renamed Addon fields to have underscores. Added methods to Addon, File and Version.

This commit is contained in:
Dave Dash 2010-02-02 12:22:24 -08:00
Родитель 8fc05f33c2
Коммит 0d683a977c
18 изменённых файлов: 597 добавлений и 213 удалений

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

@ -5,33 +5,33 @@ from .models import Addon, BlacklistedGuid, Feature, Category
class AddonAdmin(admin.ModelAdmin):
exclude = ('users',)
list_display = ('__unicode__', 'addontype', 'status', 'averagerating')
list_filter = ('addontype', 'status')
list_display = ('__unicode__', 'type', 'status', 'average_rating')
list_filter = ('type', 'status')
fieldsets = (
(None, {
'fields': ('name', 'guid', 'defaultlocale', 'addontype', 'status',
'higheststatus', 'nominationdate'),
'fields': ('name', 'guid', 'default_locale', 'type', 'status',
'highest_status', 'nomination_date'),
}),
('Details', {
'fields': ('summary', 'description', 'homepage', 'eula',
'privacypolicy', 'developercomments', 'icontype',
'privacy_policy', 'developer_comments', 'icon_type',
'the_reason', 'the_future'),
}),
('Support', {
'fields': ('supporturl', 'supportemail',
'fields': ('support_url', 'support_email',
'get_satisfaction_company', 'get_satisfaction_product'),
}),
('Stats', {
'fields': ('averagerating', 'bayesianrating', 'totalreviews',
'weeklydownloads', 'totaldownloads',
'fields': ('average_rating', 'bayesian_rating', 'total_reviews',
'weekly_downloads', 'total_downloads',
'average_daily_downloads', 'average_daily_users',
'sharecount'),
'share_count'),
}),
('Truthiness', {
'fields': ('inactive', 'trusted', 'viewsource', 'publicstats',
'prerelease', 'adminreview', 'sitespecific',
'externalsoftware', 'binary', 'dev_agreement',
'fields': ('inactive', 'trusted', 'view_source', 'public_stats',
'prerelease', 'admin_review', 'site_specific',
'external_software', 'binary', 'dev_agreement',
'show_beta'),
}),
('Money', {

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

@ -38,50 +38,50 @@
"fields": {
"dev_agreement": 1,
"eula": null,
"publicstats": 0,
"public_stats": 0,
"modified": "2010-01-06 18:16:38",
"weeklydownloads": 112297,
"sharecount": 16,
"adminreview": 0,
"weekly_downloads": 112297,
"share_count": 16,
"admin_review": 0,
"average_daily_downloads": 19684,
"show_beta": 1,
"supportemail": null,
"support_email": null,
"trusted": 1,
"averagerating": "3.98",
"average_rating": "3.98",
"locale_disambiguation": "",
"binary": 0,
"the_future": null,
"totalreviews": 1106,
"viewsource": 0,
"externalsoftware": 0,
"total_reviews": 1106,
"view_source": 0,
"external_software": 0,
"average_daily_users": 1343482,
"totaldownloads": 17046775,
"icontype": "image/png",
"total_downloads": 17046775,
"icon_type": "image/png",
"homepage": null,
"status": 4,
"description": null,
"target_locale": "",
"sitespecific": 0,
"supporturl": null,
"nominationdate": "2009-03-25 17:32:39",
"site_specific": 0,
"support_url": null,
"nomination_date": "2009-03-25 17:32:39",
"wants_contributions": 0,
"suggested_amount": "",
"privacypolicy": null,
"privacy_policy": null,
"prerelease": 0,
"guid": "piclens@cooliris.com",
"bayesianrating": 3.9810599999999998,
"bayesian_rating": 3.9810599999999998,
"get_satisfaction_company": "",
"name": null,
"created": "2007-08-23 23:55:32",
"paypal_id": "",
"annoying": 0,
"developercomments": null,
"developer_comments": null,
"summary": null,
"inactive": 0,
"get_satisfaction_product": "",
"addontype": 1,
"higheststatus": 4,
"defaultlocale": "en-US",
"type": 1,
"highest_status": 4,
"default_locale": "en-US",
"the_reason": null
}
},
@ -91,50 +91,50 @@
"fields": {
"dev_agreement": 1,
"eula": null,
"publicstats": 0,
"public_stats": 0,
"modified": "2010-01-06 18:16:38",
"weeklydownloads": 112297,
"sharecount": 16,
"adminreview": 0,
"weekly_downloads": 112297,
"share_count": 16,
"admin_review": 0,
"average_daily_downloads": 19684,
"show_beta": 1,
"supportemail": null,
"support_email": null,
"trusted": 1,
"averagerating": "3.98",
"average_rating": "3.98",
"locale_disambiguation": "",
"binary": 0,
"the_future": null,
"totalreviews": 1106,
"viewsource": 0,
"externalsoftware": 0,
"total_reviews": 1106,
"view_source": 0,
"external_software": 0,
"average_daily_users": 1343482,
"totaldownloads": 17046775,
"icontype": "image/png",
"total_downloads": 17046775,
"icon_type": "image/png",
"homepage": null,
"status": 4,
"description": null,
"target_locale": "",
"sitespecific": 0,
"supporturl": null,
"nominationdate": "2009-03-25 17:32:39",
"site_specific": 0,
"support_url": null,
"nomination_date": "2009-03-25 17:32:39",
"wants_contributions": 0,
"suggested_amount": "",
"privacypolicy": null,
"privacy_policy": null,
"prerelease": 0,
"guid": "fake@cooliris.com",
"bayesianrating": 3.9810599999999998,
"bayesian_rating": 3.9810599999999998,
"get_satisfaction_company": "",
"name": null,
"created": "2007-08-23 23:55:32",
"paypal_id": "",
"annoying": 0,
"developercomments": null,
"developer_comments": null,
"summary": null,
"inactive": 0,
"get_satisfaction_product": "",
"addontype": 1,
"higheststatus": 4,
"defaultlocale": "en-US",
"type": 1,
"highest_status": 4,
"default_locale": "en-US",
"the_reason": null
}
},

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

@ -1,4 +1,6 @@
from datetime import date
import time
from django.conf import settings
from django.db import models
@ -30,45 +32,57 @@ class Addon(amo.models.ModelBase):
guid = models.CharField(max_length=255, unique=True, null=True)
name = TranslatedField()
defaultlocale = models.CharField(max_length=10,
default=settings.LANGUAGE_CODE)
default_locale = models.CharField(max_length=10,
default=settings.LANGUAGE_CODE,
db_column='defaultlocale')
addontype = models.ForeignKey('AddonType')
type = models.ForeignKey('AddonType', db_column='addontype_id')
status = models.PositiveIntegerField(
choices=STATUS_CHOICES, db_index=True, default=0)
higheststatus = models.PositiveIntegerField(
highest_status = models.PositiveIntegerField(
choices=STATUS_CHOICES, default=0,
help_text="An upper limit for what an author can change.")
icontype = models.CharField(max_length=25, blank=True)
help_text="An upper limit for what an author can change.",
db_column='higheststatus')
icon_type = models.CharField(max_length=25, blank=True,
db_column='icontype')
homepage = TranslatedField()
supportemail = TranslatedField()
supporturl = TranslatedField()
support_email = TranslatedField(db_column='supportemail')
support_url = TranslatedField(db_column='supporturl')
description = TranslatedField()
summary = TranslatedField()
developercomments = TranslatedField()
developer_comments = TranslatedField(db_column='developercomments')
eula = TranslatedField()
privacypolicy = TranslatedField()
privacy_policy = TranslatedField(db_column='privacypolicy')
the_reason = TranslatedField()
the_future = TranslatedField()
averagerating = models.CharField(max_length=255, default=0)
bayesianrating = models.FloatField(default=0, db_index=True)
totalreviews = models.PositiveIntegerField(default=0)
weeklydownloads = models.PositiveIntegerField(default=0)
totaldownloads = models.PositiveIntegerField(default=0)
average_rating = models.CharField(max_length=255, default=0,
db_column='averagerating')
bayesian_rating = models.FloatField(default=0, db_index=True,
db_column='bayesianrating')
total_reviews = models.PositiveIntegerField(default=0,
db_column='totalreviews')
weekly_downloads = models.PositiveIntegerField(
default=0, db_column='weeklydownloads')
total_downloads = models.PositiveIntegerField(
default=0, db_column='totaldownloads')
average_daily_downloads = models.PositiveIntegerField(default=0)
average_daily_users = models.PositiveIntegerField(default=0)
sharecount = models.PositiveIntegerField(default=0, db_index=True)
share_count = models.PositiveIntegerField(default=0, db_index=True,
db_column='sharecount')
inactive = models.BooleanField(default=False, db_index=True)
trusted = models.BooleanField(default=False)
viewsource = models.BooleanField(default=False)
publicstats = models.BooleanField(default=False)
view_source = models.BooleanField(default=False, db_column='viewsource')
public_stats = models.BooleanField(default=False, db_column='publicstats')
prerelease = models.BooleanField(default=False)
adminreview = models.BooleanField(default=False)
sitespecific = models.BooleanField(default=False)
externalsoftware = models.BooleanField(default=False)
admin_review = models.BooleanField(default=False, db_column='adminreview')
site_specific = models.BooleanField(default=False,
db_column='sitespecific')
external_software = models.BooleanField(default=False,
db_column='externalsoftware')
binary = models.BooleanField(default=False,
help_text="Does the add-on contain a binary?")
dev_agreement = models.BooleanField(default=False,
@ -76,7 +90,8 @@ class Addon(amo.models.ModelBase):
wants_contributions = models.BooleanField(default=False)
show_beta = models.BooleanField(default=True)
nominationdate = models.DateTimeField(null=True)
nomination_date = models.DateTimeField(null=True,
db_column='nominationdate')
target_locale = models.CharField(max_length=255, db_index=True, blank=True,
help_text="For dictionaries and language packs")
locale_disambiguation = models.CharField(max_length=255, blank=True,
@ -91,7 +106,9 @@ class Addon(amo.models.ModelBase):
get_satisfaction_company = models.CharField(max_length=255, blank=True)
get_satisfaction_product = models.CharField(max_length=255, blank=True)
users = models.ManyToManyField('users.UserProfile', through='AddonUser')
authors = models.ManyToManyField('users.UserProfile', through='AddonUser')
objects = AddonManager()
objects = AddonManager()
@ -105,11 +122,46 @@ class Addon(amo.models.ModelBase):
return reverse('addons.detail', args=(self.id,))
def fetch_translations(self, ids, lang):
return translations_with_fallback(ids, lang, self.defaultlocale)
return translations_with_fallback(ids, lang, self.default_locale)
def reviews(self):
return Review.objects.filter(version__addon=self)
def get_current_version(self):
"""
Retrieves the latest public version of an addon.
"""
try:
return self.versions.filter(files__status=amo.STATUS_PUBLIC)[0]
except IndexError:
return None
def get_icon_url(self):
"""
Returns either the addon's icon url, or a default.
"""
if not self.icon_type:
if self.type_id == amo.ADDON_THEME:
return settings.STATIC_URL + '/img/theme.png'
else:
return settings.STATIC_URL + '/img/default_icon.png'
else:
return settings.ADDON_ICON_URL % (
self.id, int(time.mktime(self.modified.timetuple())))
def get_thumbnail_url(self):
"""
Returns the addon's thumbnail url or a default.
"""
try:
preview = self.preview_set.order_by(
'-highlight', 'created').all()[0]
return preview.get_thumbnail_url()
except IndexError:
return settings.STATIC_URL + '/img/no-preview.png'
class AddonCategory(models.Model):
addon = models.ForeignKey(Addon)
@ -240,3 +292,8 @@ class Preview(amo.models.ModelBase):
class Meta:
db_table = 'previews'
def get_thumbnail_url(self):
return (settings.PREVIEW_THUMBNAIL_URL %
(str(self.id)[0], self.id,
int(time.mktime(self.modified.timetuple()))))

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

@ -28,3 +28,42 @@ class TestAddonManager(test.TestCase):
featured = Addon.objects.featured(amo.THUNDERBIRD)[0]
eq_(featured.id, 2)
eq_(Addon.objects.featured(amo.THUNDERBIRD).count(), 1)
class TestAddonModels(test.TestCase):
# base/addons.json has an example addon
fixtures = ['base/addons.json']
def test_get_current_version(self):
"""
Tests that we get the current (latest public) version of an addon.
"""
a = Addon.objects.get(pk=3615)
eq_(a.get_current_version().id, 24007)
def test_icon_url(self):
"""
Tests for various icons.
1. Test for an icon that exists.
2. Test for default THEME icon.
3. Test for default non-THEM icon.
"""
a = Addon.objects.get(pk=3615)
a.get_icon_url().index('/en-US/firefox/images/addon_icon/3615/')
a = Addon.objects.get(pk=7172)
assert a.get_icon_url().endswith('/img/theme.png'), (
"No match for %s" % a.get_icon_url())
a = Addon.objects.get(pk=1)
assert a.get_icon_url().endswith('/img/default_icon.png')
def test_thumbnail_url(self):
"""
Test for the actual thumbnail URL if it should exist, or the no-preview
url.
"""
a = Addon.objects.get(pk=7172)
a.get_thumbnail_url().index('/img/uploads/previews/thumbs/2/25981.png')
a = Addon.objects.get(pk=1)
assert a.get_thumbnail_url().endswith('/img/no-preview.png'), (
"No match for %s" % a.get_thumbnail_url())

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

@ -41,11 +41,11 @@
"description": null,
"created": "2006-06-25 22:23:47",
"modified": "2009-12-11 15:34:35",
"adminreview": 0,
"defaultlocale": "en-US",
"admin_review": 0,
"default_locale": "en-US",
"status": 4,
"higheststatus": 4,
"addontype": 1,
"highest_status": 4,
"type": 1,
"name": null
}
},
@ -57,11 +57,11 @@
"description": null,
"created": "2006-06-25 22:23:47",
"modified": "2009-12-11 15:34:35",
"adminreview": 1,
"defaultlocale": "en-US",
"admin_review": 1,
"default_locale": "en-US",
"status": 4,
"higheststatus": 4,
"addontype": 1,
"highest_status": 4,
"type": 1,
"name": null
}
},
@ -73,11 +73,11 @@
"description": null,
"created": "2006-06-25 22:23:47",
"modified": "2009-12-11 15:34:35",
"adminreview": 1,
"defaultlocale": "en-US",
"admin_review": 1,
"default_locale": "en-US",
"status": 4,
"higheststatus": 4,
"addontype": 1,
"highest_status": 4,
"type": 1,
"name": null
}
},
@ -89,11 +89,11 @@
"description": null,
"created": "2006-06-25 22:23:47",
"modified": "2009-12-11 15:34:35",
"adminreview": 1,
"defaultlocale": "en-US",
"admin_review": 1,
"default_locale": "en-US",
"status": 4,
"higheststatus": 4,
"addontype": 1,
"highest_status": 4,
"type": 1,
"name": null
}
},

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

@ -50,8 +50,8 @@ class TestFlagged(test_utils.TestCase):
response = self.client.post(url, {'addon_id': ['1', '2']}, follow=True)
self.assertRedirects(response, url)
assert not Addon.objects.get(id=1).adminreview
assert not Addon.objects.get(id=2).adminreview
assert not Addon.objects.get(id=1).admin_review
assert not Addon.objects.get(id=2).admin_review
addons = response.context['addons']
eq_(len(addons), 1)

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

@ -12,11 +12,11 @@ from versions.models import Version
@admin.site.admin_view
def flagged(request):
addons = Addon.objects.filter(adminreview=True).order_by('-created')
addons = Addon.objects.filter(admin_review=True).order_by('-created')
if request.method == 'POST':
ids = map(int, request.POST.getlist('addon_id'))
Addon.objects.filter(id__in=ids).update(adminreview=False)
Addon.objects.filter(id__in=ids).update(admin_review=False)
# The sql update doesn't invalidate anything, do it manually.
invalid = [addon for addon in addons if addon.id in ids]
Addon.objects.invalidate(*invalid)

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

@ -59,9 +59,9 @@
"pk": 4,
"model": "addons.addon",
"fields": {
"addontype": 1,
"type": 1,
"status": 4,
"higheststatus": 4,
"highest_status": 4,
"description": null,
"modified": "2008-05-22 11:59:13",
"name": null,

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

@ -0,0 +1,310 @@
[
{
"pk": 1,
"model": "translations.translation",
"fields": {
"id": 1,
"locale": "en-US",
"localized_string": "ALL",
"created": "2001-01-01 13:14:15"
}
},
{
"pk": 1,
"model": "files.platform",
"fields": {
"name": 1,
"icontype": "",
"modified": "2008-04-07 08:16:55",
"created": "2007-03-05 13:09:27"
}
},
{
"pk": 1,
"model": "addons.addontype",
"fields": {
"modified": "2009-02-06 08:42:28",
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 2,
"model": "addons.addontype",
"fields": {
"modified": "2009-02-06 08:42:28",
"created": "2006-08-21 23:53:24"
}
},
{
"pk": 15000,
"model": "translations.translation",
"fields": {
"locale": "en-US",
"created": "2007-03-05 13:10:42",
"id": 15000,
"modified": "2009-03-26 07:41:10",
"localized_string": "Delicious Bookmarks"
}
},
{
"pk": 29034,
"model": "translations.translation",
"fields": {
"locale": "en-US",
"created": "2007-03-05 13:10:42",
"id": 15002,
"modified": "2009-04-29 11:20:57",
"localized_string": "This extension integrates your browser with Delicious (http://delicious.com), the leading social bookmarking service on the Web. It does this by augmenting the bookmarking functionality in Firefox with an enhanced experience that offers the following advantages:\r\n\r\n- Search and browse your Delicious bookmarks\r\n- Keep up to date on your Network and Links For You\r\n- Access your bookmarks from any computer at any time\r\n- Keep your bookmarks organized using tags\r\n- Share your bookmarks with friends or anyone on the Web\r\n- Import your existing Firefox bookmarks\r\n\r\nWe've also included a Classic Mode for those who want the basic Delicious buttons without any sync or search features. This option is available when you install the add-on, and can be accessed later from the Delicious menu in Firefox.\r\n\r\nFor a product tour and more details about this extension, please visit:\r\nhttp://delicious.com/help/quicktour/firefox\r\n\r\nFor product feedback, commentary & enhancement requests, please post to our discussion group, found here:\r\nhttp://tech.groups.yahoo.com/group/delicious-firefox-extension/\r\n\r\nor try the Delicious support forums:\r\n\r\nhttp://support.delicious.com/\r\n"
}
},
{
"pk": 3615,
"model": "addons.addon",
"fields": {
"dev_agreement": 1,
"public_stats": 0,
"modified": "2009-10-21 09:58:52",
"weekly_downloads": 20178,
"share_count": 5,
"admin_review": 0,
"average_daily_downloads": 5928,
"show_beta": 1,
"trusted": 1,
"average_rating": "3.02",
"binary": 0,
"total_reviews": 389,
"view_source": 0,
"external_software": 0,
"average_daily_users": 493241,
"total_downloads": 5175276,
"icon_type": "image/png",
"status": 4,
"description": 15002,
"site_specific": 1,
"nomination_date": "2009-03-26 07:41:12",
"wants_contributions": 0,
"prerelease": 0,
"guid": "{2fa4ed95-0317-4c6a-a74c-5f3e3912c1f9}",
"bayesian_rating": 3.06941,
"name": 15000,
"created": "2006-10-23 12:57:41",
"paypal_id": "",
"annoying": 0,
"inactive": 0,
"type": 1,
"highest_status": 4,
"default_locale": "en-US"
}
},
{
"pk": 24007,
"model": "versions.version",
"fields": {
"license": null,
"created": "2006-10-23 12:57:41",
"approvalnotes": "",
"modified": "2006-10-23 19:22:18",
"version": "1.0.43",
"addon": 3615
}
},
{
"pk": 1,
"model": "versions.version",
"fields": {
"license": null,
"created": "2006-10-24 12:00:00",
"approvalnotes": "",
"modified": "2006-10-24 12:00:01",
"version": "1.2",
"addon": 3615
}
},
{
"pk": 2,
"model": "versions.version",
"fields": {
"addon": 3615,
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 1,
"model": "applications.application",
"fields": {
"guid": "{3550f703-e582-4d05-9a08-453d09bdfdc6}",
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 18,
"model": "applications.application",
"fields": {
"guid": "{3550f703-e582-4d05-9a08-453d09bdfdc6}",
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 200,
"model": "applications.appversion",
"fields": {
"application": 1,
"version": "1",
"version_int": 1,
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 201,
"model": "applications.appversion",
"fields": {
"application": 1,
"version": "2",
"version_int": 2,
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 202,
"model": "applications.appversion",
"fields": {
"application": 18,
"version": "1",
"version_int": 1,
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 203,
"model": "applications.appversion",
"fields": {
"application": 18,
"version": "2",
"version_int": 2,
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 20,
"model": "versions.applicationsversions",
"fields": {
"application": 1,
"version": 2,
"min": 200,
"max": 201
}
},
{
"pk": 21,
"model": "versions.applicationsversions",
"fields": {
"application": 18,
"version": 2,
"min": 202,
"max": 203
}
},
{
"pk": 11993,
"model": "files.file",
"fields": {
"status": 4,
"codereview": 0,
"hash": "sha256:5b5aaf7b38e332cc95d92ba759c01c3076b53a840f6c16e01dc272eefcb29566",
"created": "2007-03-05 13:19:15",
"modified": "2007-04-04 12:30:11",
"filename": "del.icio.us_bookmarks-1.0.43-fx.xpi",
"platform": 1,
"version": 24007,
"datestatuschanged": null,
"size": 169
}
},
{
"pk": 1,
"model": "files.file",
"fields": {
"status": 1,
"codereview": 0,
"hash": "sha256:5b5aaf7b38e332cc95d92ba759c01c3076b53a840f6c16e01dc272eefcb29566",
"created": "2007-03-05 13:19:15",
"modified": "2007-04-04 12:30:11",
"filename": "del.icio.us_bookmarks-1.2-fx.xpi",
"platform": 1,
"version": 1,
"datestatuschanged": null,
"size": 169
}
},
{
"pk": 129780,
"model": "translations.translation",
"fields": {
"locale": "en-US",
"created": "2007-03-05 13:10:42",
"id": 129780,
"modified": "2009-03-26 07:41:10",
"localized_string": "macos theme"
}
},
{
"pk": 7172,
"model": "addons.addon",
"fields": {
"dev_agreement": 1,
"view_source": 0,
"total_downloads": 751302,
"inactive": 0,
"average_daily_downloads": 1325,
"show_beta": 1,
"trusted": 0,
"binary": 0,
"guid": "{00352F14-3F76-4e4d-ACFF-9976D7E4B3B9}",
"weekly_downloads": 7523,
"paypal_id": "",
"average_rating": "4.56",
"wants_contributions": 0,
"average_daily_users": 66334,
"bayesian_rating": 4.5321899999999999,
"share_count": 2,
"public_stats": 1,
"status": 4,
"default_locale": "en-US",
"prerelease": 0,
"admin_review": 0,
"external_software": 0,
"highest_status": 4,
"name": 129780,
"created": "2008-05-01 00:59:36",
"type": 2,
"annoying": 0,
"modified": "2009-09-22 01:49:51",
"site_specific": 0,
"total_reviews": 346,
"nomination_date": "2009-03-21 09:17:07"
}
},
{
"pk": 1,
"model": "addons.addon",
"fields": {
"type": 1,
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 25981,
"model": "addons.preview",
"fields": {
"caption": null,
"filetype": "image/png",
"created": "2008-09-15 01:30:44",
"modified": "2008-09-15 01:30:44",
"thumbtype": "image/png",
"highlight": 0,
"addon": 7172
}
}
]

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

@ -1,3 +1,4 @@
from django.conf import settings
from django.db import models
import amo.models
@ -8,7 +9,7 @@ from translations.fields import TranslatedField
class File(amo.models.ModelBase):
STATUS_CHOICES = amo.STATUS_CHOICES.items()
version = models.ForeignKey(Version)
version = models.ForeignKey(Version, related_name='files')
platform = models.ForeignKey('Platform')
filename = models.CharField(max_length=255, default='')
size = models.PositiveIntegerField(default=0)
@ -21,6 +22,9 @@ class File(amo.models.ModelBase):
class Meta(amo.models.ModelBase.Meta):
db_table = 'files'
def get_absolute_url(self, src):
return settings.FILES_URL % (self.id, self.filename, src)
class Approval(amo.models.ModelBase):

18
apps/files/tests.py Normal file
Просмотреть файл

@ -0,0 +1,18 @@
from django import test
from files.models import File
class TestFile(test.TestCase):
"""
Tests the methods of the File model.
"""
fixtures = ['base/addons.json']
def test_get_absolute_url(self):
f = File.objects.get(id=11993)
src = "crystalmethod"
assert f.get_absolute_url(src).endswith(
'downloads/file/11993/'
'del.icio.us_bookmarks-1.0.43-fx.xpi?src=crystalmethod')

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

@ -59,9 +59,9 @@
"pk": 4,
"model": "addons.addon",
"fields": {
"addontype": 1,
"type": 1,
"status": 4,
"higheststatus": 4,
"highest_status": 4,
"description": null,
"modified": "2008-05-22 11:59:13",
"name": null,

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

@ -1,110 +0,0 @@
[
{
"pk": 1,
"model": "files.platform",
"fields": {
"icontype": "",
"modified": "2008-04-07 08:16:55",
"created": "2007-03-05 13:09:27"
}
},
{
"pk": 1,
"model": "addons.addontype",
"fields": {
"modified": "2009-02-06 08:42:28",
"created": "2006-08-21 23:53:19"
}
},
{
"pk": 15000,
"model": "translations.translation",
"fields": {
"locale": "en-US",
"created": "2007-03-05 13:10:42",
"id": 15000,
"modified": "2009-03-26 07:41:10",
"localized_string": "Delicious Bookmarks"
}
},
{
"pk": 29034,
"model": "translations.translation",
"fields": {
"locale": "en-US",
"created": "2007-03-05 13:10:42",
"id": 15002,
"modified": "2009-04-29 11:20:57",
"localized_string": "This extension integrates your browser with Delicious (http://delicious.com), the leading social bookmarking service on the Web. It does this by augmenting the bookmarking functionality in Firefox with an enhanced experience that offers the following advantages:\r\n\r\n- Search and browse your Delicious bookmarks\r\n- Keep up to date on your Network and Links For You\r\n- Access your bookmarks from any computer at any time\r\n- Keep your bookmarks organized using tags\r\n- Share your bookmarks with friends or anyone on the Web\r\n- Import your existing Firefox bookmarks\r\n\r\nWe've also included a Classic Mode for those who want the basic Delicious buttons without any sync or search features. This option is available when you install the add-on, and can be accessed later from the Delicious menu in Firefox.\r\n\r\nFor a product tour and more details about this extension, please visit:\r\nhttp://delicious.com/help/quicktour/firefox\r\n\r\nFor product feedback, commentary & enhancement requests, please post to our discussion group, found here:\r\nhttp://tech.groups.yahoo.com/group/delicious-firefox-extension/\r\n\r\nor try the Delicious support forums:\r\n\r\nhttp://support.delicious.com/\r\n"
}
},
{
"pk": 3615,
"model": "addons.addon",
"fields": {
"dev_agreement": 1,
"publicstats": 0,
"modified": "2009-10-21 09:58:52",
"weeklydownloads": 20178,
"sharecount": 5,
"adminreview": 0,
"average_daily_downloads": 5928,
"show_beta": 1,
"trusted": 1,
"averagerating": "3.02",
"binary": 0,
"totalreviews": 389,
"viewsource": 0,
"externalsoftware": 0,
"average_daily_users": 493241,
"totaldownloads": 5175276,
"icontype": "image/png",
"status": 4,
"description": 15002,
"sitespecific": 1,
"nominationdate": "2009-03-26 07:41:12",
"wants_contributions": 0,
"prerelease": 0,
"guid": "{2fa4ed95-0317-4c6a-a74c-5f3e3912c1f9}",
"bayesianrating": 3.06941,
"name": 15000,
"created": "2006-10-23 12:57:41",
"paypal_id": "",
"annoying": 0,
"inactive": 0,
"addontype": 1,
"higheststatus": 4,
"defaultlocale": "en-US"
}
},
{
"pk": 24007,
"model": "versions.version",
"fields": {
"license": null,
"created": "2006-10-23 12:57:41",
"approvalnotes": "",
"modified": "2006-10-23 19:22:18",
"version": "1.0.43",
"addon": 3615
}
},
{
"pk": 11993,
"model": "files.file",
"fields": {
"status": 4,
"codereview": 0,
"hash": "sha256:5b5aaf7b38e332cc95d92ba759c01c3076b53a840f6c16e01dc272eefcb29566",
"created": "2007-03-05 13:19:15",
"modified": "2007-04-04 12:30:11",
"filename": "del.icio.us_bookmarks-1.0.43-fx.xpi",
"platform": 1,
"version": 24007,
"datestatuschanged": null,
"size": 169
}
}
]

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

@ -39,7 +39,7 @@ def test_convert_version():
class SphinxTest(TransactionTestCase):
fixtures = ["search/sphinx.json"]
fixtures = ["base/addons.json"]
sphinx = True
def setUp(self):

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

@ -1,3 +1,5 @@
import collections
from django.db import models
import amo.models
@ -18,6 +20,33 @@ class Version(amo.models.ModelBase):
class Meta(amo.models.ModelBase.Meta):
db_table = 'versions'
ordering = ['-created']
def get_compatible_apps(self):
"""
Looks at the current version and gives us a list of namedtuples of
Application, Min and Max version.
"""
compat_list = []
Compatibility = collections.namedtuple(
'Compatibility', 'application max min')
avs = self.applicationsversions_set.select_related().all()
[compat_list.append(Compatibility(
av.application, av.max.version, av.min.version)) for av in avs]
return compat_list
def get_supported_platforms(self):
"""
Looks at the current version and gives us a list of supported versions.
"""
platforms = []
[platforms.append(file.platform.name) for file in
self.files.all()]
return list(set(platforms))
class License(amo.models.ModelBase):
@ -62,3 +91,4 @@ class ApplicationsVersions(models.Model):
class Meta:
db_table = u'applications_versions'
unique_together = (("application", "version"),)

25
apps/versions/tests.py Normal file
Просмотреть файл

@ -0,0 +1,25 @@
from django import test
import amo
from versions.models import Version
class TestVersion(test.TestCase):
"""
Test methods of the version class.
"""
fixtures = ['base/addons.json']
def test_get_compatible_apps(self):
v = Version.objects.get(pk=2)
assert any([c.application.id == amo.FIREFOX.id for c in
v.get_compatible_apps()]), "Missing Firefox >_<"
assert any([c.application.id == amo.THUNDERBIRD.id for c in
v.get_compatible_apps()]), "Missing Thunderbird \o/"
def test_get_supported_platforms(self):
v = Version.objects.get(pk=24007)
assert any(os.localized_string == 'ALL' for os in
v.get_supported_platforms())

@ -1 +1 @@
Subproject commit 383790ef0ceff7ba0dd17430f3fa8403acce5642
Subproject commit f4fa4f889da938bd2476834517cc412665af8ebd

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

@ -216,3 +216,14 @@ SPHINX_SEARCHD = 'searchd'
SPHINX_CONFIG_PATH = path('configs/sphinx/sphinx.conf')
SPHINX_HOST = '127.0.0.1'
SPHINX_PORT = 3312
# URL paths
# paths for images, e.g. mozcdn.com/amo or '/static'
STATIC_URL = SITE_URL
ADDON_ICON_URL = "%s/%s/%s/images/addon_icon/%%d/%%s" % (
STATIC_URL, LANGUAGE_CODE, DEFAULT_APP)
PREVIEW_THUMBNAIL_URL = (STATIC_URL +
'/img/uploads/previews/thumbs/%s/%d.png?modified=%d')
# paths for uploaded extensions
FILES_URL = STATIC_URL + "/downloads/file/%d/%s?src=%s"