forked from mozilla/zamboni
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
417 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ build.py | |
*-all.js | ||
vendor | ||
.noseids | ||
tmp/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "files.platform", | ||
"fields": { | ||
"icontype": "", | ||
"modified": "2008-04-07 08:16:55", | ||
"created": "2007-03-05 13:09:27" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "files.platform", | ||
"fields": { | ||
"icontype": "", | ||
"modified": "2008-04-07 08:16:55", | ||
"created": "2007-03-05 13:09:27" | ||
} | ||
}, | ||
{ | ||
"pk": 3, | ||
"model": "files.platform", | ||
"fields": { | ||
"icontype": "", | ||
"modified": "2008-04-07 08:16:55", | ||
"created": "2007-03-05 13:09:27" | ||
} | ||
}, | ||
{ | ||
"pk": 4, | ||
"model": "files.platform", | ||
"fields": { | ||
"icontype": "", | ||
"modified": "2008-04-07 08:16:55", | ||
"created": "2007-03-05 13:09:27" | ||
} | ||
}, | ||
{ | ||
"pk": 5, | ||
"model": "files.platform", | ||
"fields": { | ||
"icontype": "", | ||
"modified": "2008-04-07 08:16:56", | ||
"created": "2007-03-05 13:09:27" | ||
} | ||
}, | ||
{ | ||
"pk": 6, | ||
"model": "files.platform", | ||
"fields": { | ||
"icontype": "", | ||
"modified": "2008-04-07 08:16:56", | ||
"created": "2007-03-05 13:09:27" | ||
} | ||
} | ||
] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,66 @@ | ||
import jingo | ||
from django.db import transaction | ||
|
||
import commonware.log | ||
from piston.handler import BaseHandler | ||
from piston.utils import rc, throttle | ||
from tower import ugettext as _ | ||
|
||
from addons.models import Addon | ||
from users.models import UserProfile | ||
from versions.forms import LicenseForm, XPIForm | ||
|
||
log = commonware.log.getLogger('z.api') | ||
|
||
|
||
class UserHandler(BaseHandler): | ||
allowed_methods = ('GET',) | ||
model = UserProfile | ||
fields = ('email',) | ||
|
||
def read(self, request): | ||
try: | ||
user = UserProfile.objects.get(user=request.user) | ||
return user | ||
except UserProfile.DoesNotExist: | ||
return None | ||
|
||
|
||
class AddonsHandler(BaseHandler): | ||
allowed_methods = ('POST',) | ||
model = Addon | ||
fields = ('id', 'name', ) | ||
exclude = ('highest_status', 'icon_type') | ||
|
||
# Custom handler so translated text doesn't look weird | ||
@classmethod | ||
def name(cls, addon): | ||
return addon.name.localized_string | ||
|
||
# We need multiple validation, so don't use @validate decorators. | ||
@transaction.commit_on_success | ||
@throttle(10, 60 * 60) # allow 10 addons an hour | ||
def create(self, request): | ||
license_form = LicenseForm(request.POST) | ||
|
||
if not license_form.is_valid(): | ||
resp = rc.BAD_REQUEST | ||
error = ', '.join(license_form.errors['__all__']) | ||
resp.write(': ' + | ||
# L10n: {0} is comma separated errors for license. | ||
_(u'Invalid license data provided: {0}').format(error)) | ||
log.debug(error) | ||
return resp | ||
|
||
new_file_form = XPIForm(request.POST, request.FILES) | ||
|
||
if not new_file_form.is_valid(): | ||
resp = rc.BAD_REQUEST | ||
resp.write(': ' + _('Addon did not validate.')) | ||
log.debug('Addon did not validate for %s' % request.amo_user) | ||
return resp | ||
|
||
license_id = license_form.get_id_or_create() | ||
|
||
a = new_file_form.create_addon(user=request.amo_user, | ||
license_id=license_id) | ||
return a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.