本文整理汇总了Python中addons.models.Addon.from_upload方法的典型用法代码示例。如果您正苦于以下问题:Python Addon.from_upload方法的具体用法?Python Addon.from_upload怎么用?Python Addon.from_upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类addons.models.Addon
的用法示例。
在下文中一共展示了Addon.from_upload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_default_locale
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def test_default_locale(self):
# Make sure default_locale follows the active translation.
addon = Addon.from_upload(self.get_upload('search.xml'),
[self.platform])
eq_(addon.default_locale, 'en-US')
translation.activate('es-ES')
addon = Addon.from_upload(self.get_upload('search.xml'),
[self.platform])
eq_(addon.default_locale, 'es-ES')
translation.deactivate()
示例2: manifest
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def manifest(request):
form = forms.NewWebappForm(request.POST or None)
if request.method == "POST" and form.is_valid():
addon = Addon.from_upload(
form.cleaned_data["upload"], [Platform.objects.get(id=amo.PLATFORM_ALL.id)], is_packaged=form.is_packaged()
)
# Set the device type.
for device in form.get_devices():
addon.addondevicetype_set.get_or_create(device_type=device.id)
# Set the premium type, only bother if it's not free.
premium = form.get_paid()
if premium:
addon.update(premium_type=premium)
if addon.has_icon_in_manifest():
# Fetch the icon, do polling.
addon.update(icon_type="image/png")
tasks.fetch_icon.delay(addon)
else:
# In this case there is no need to do any polling.
addon.update(icon_type="")
AddonUser(addon=addon, user=request.amo_user).save()
# Checking it once. Checking it twice.
AppSubmissionChecklist.objects.create(addon=addon, terms=True, manifest=True)
return redirect("submit.app.details", addon.app_slug)
return jingo.render(
request, "submit/manifest.html", {"step": "manifest", "form": form, "DEVICE_LOOKUP": DEVICE_LOOKUP}
)
示例3: package
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def package(request):
form = forms.NewWebappForm(request.POST or None, is_packaged=True)
if request.method == 'POST' and form.is_valid():
addon = Addon.from_upload(
form.cleaned_data['upload'],
[Platform.objects.get(id=amo.PLATFORM_ALL.id)], is_packaged=True)
if addon.has_icon_in_manifest():
# Fetch the icon, do polling.
addon.update(icon_type='image/png')
tasks.fetch_icon.delay(addon)
else:
# In this case there is no need to do any polling.
addon.update(icon_type='')
AddonUser(addon=addon, user=request.amo_user).save()
AppSubmissionChecklist.objects.create(addon=addon, terms=True,
manifest=True)
return redirect('submit.app.details', addon.app_slug)
return jingo.render(request, 'submit/upload.html', {
'form': form,
'step': 'manifest',
})
示例4: test_search_version
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def test_search_version(self):
addon = Addon.from_upload(self.get_upload('search.xml'),
[self.platform])
v = addon.versions.get()
eq_(v.version, datetime.now().strftime('%Y%m%d'))
eq_(v.files.get().platform_id, amo.PLATFORM_ALL.id)
eq_(v.files.get().status, amo.STATUS_UNREVIEWED)
示例5: obj_create
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def obj_create(self, bundle, request, **kwargs):
form = UploadForm(bundle.data)
if not request.amo_user.read_dev_agreement:
log.info(u'Attempt to use API without dev agreement: %s'
% request.amo_user.pk)
response = http.HttpUnauthorized()
response.content = json.dumps({'reason':
'Terms of service not accepted.'})
raise ImmediateHttpResponse(response=response)
if not form.is_valid():
raise self.form_errors(form)
if not (OwnerAuthorization()
.is_authorized(request, object=form.obj)):
raise ImmediateHttpResponse(response=http.HttpForbidden())
plats = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
# Create app, user and fetch the icon.
bundle.obj = Addon.from_upload(form.obj, plats,
is_packaged=form.is_packaged)
AddonUser(addon=bundle.obj, user=request.amo_user).save()
self._icons_and_images(bundle.obj)
record_action('app-submitted', request, {'app-id': bundle.obj.pk})
log.info('App created: %s' % bundle.obj.pk)
return bundle
示例6: create
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def create(self, request):
if not waffle.flag_is_active(request, 'accept-webapps'):
return rc.BAD_REQUEST
form = NewManifestForm(request.POST)
if form.is_valid():
# This feels like an awful lot of work.
# But first upload the file and do the validation.
upload = FileUpload.objects.create()
tasks.fetch_manifest(form.cleaned_data['manifest'], upload.pk)
# We must reget the object here since the above has
# saved changes to the object.
upload = FileUpload.uncached.get(pk=upload.pk)
# Check it validated correctly.
if settings.VALIDATE_ADDONS:
validation = json.loads(upload.validation)
if validation['errors']:
response = rc.BAD_REQUEST
response.write(validation)
return response
# Fetch the addon, the icon and set the user.
addon = Addon.from_upload(upload,
[Platform.objects.get(id=amo.PLATFORM_ALL.id)])
tasks.fetch_icon(addon)
AddonUser(addon=addon, user=request.amo_user).save()
addon.update(status=amo.STATUS_PENDING if
settings.WEBAPPS_RESTRICTED else amo.STATUS_PUBLIC)
else:
return _form_error(form)
return addon
示例7: test_xpi_version
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def test_xpi_version(self):
addon = Addon.from_upload(self.get_upload('extension.xpi'),
[self.platform])
v = addon.versions.get()
eq_(v.version, '0.1')
eq_(v.files.get().platform_id, self.platform.id)
eq_(v.files.get().status, amo.STATUS_UNREVIEWED)
示例8: manifest
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def manifest(request):
# TODO: Have decorator handle the redirection.
user = UserProfile.objects.get(pk=request.user.id)
if not user.read_dev_agreement:
# And we start back at one...
return redirect('submit.app')
form = forms.NewWebappForm(request.POST or None)
if request.method == 'POST' and form.is_valid():
data = form.cleaned_data
plats = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
addon = Addon.from_upload(data['upload'], plats)
if addon.has_icon_in_manifest():
# Fetch the icon, do polling.
addon.update(icon_type='image/png')
tasks.fetch_icon.delay(addon)
else:
# In this case there is no need to do any polling.
addon.update(icon_type='')
AddonUser(addon=addon, user=request.amo_user).save()
# Checking it once. Checking it twice.
AppSubmissionChecklist.objects.create(addon=addon, terms=True,
manifest=True)
return redirect('submit.app.details', addon.app_slug)
return jingo.render(request, 'submit/manifest.html', {
'step': 'manifest',
'form': form,
})
示例9: test_xpi_for_multiple_platforms
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def test_xpi_for_multiple_platforms(self):
platforms = [Platform.objects.get(pk=amo.PLATFORM_LINUX.id),
Platform.objects.get(pk=amo.PLATFORM_MAC.id)]
addon = Addon.from_upload(self.get_upload('extension.xpi'),
platforms)
v = addon.versions.get()
eq_(sorted([f.platform.id for f in v.all_files]),
sorted([p.id for p in platforms]))
示例10: manifest
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def manifest(request):
form = forms.NewWebappForm(request.POST or None, request=request)
features_form = forms.AppFeaturesForm(request.POST or None)
features_form_valid = (True if not waffle.switch_is_active('buchets')
else features_form.is_valid())
if (request.method == 'POST' and form.is_valid()
and features_form_valid):
with transaction.commit_on_success():
addon = Addon.from_upload(
form.cleaned_data['upload'],
[Platform.objects.get(id=amo.PLATFORM_ALL.id)],
is_packaged=form.is_packaged())
# Set the device type.
for device in form.get_devices():
addon.addondevicetype_set.get_or_create(
device_type=device.id)
# Set the premium type, only bother if it's not free.
premium = form.get_paid()
if premium:
addon.update(premium_type=premium)
if addon.has_icon_in_manifest():
# Fetch the icon, do polling.
addon.update(icon_type='image/png')
else:
# In this case there is no need to do any polling.
addon.update(icon_type='')
AddonUser(addon=addon, user=request.amo_user).save()
# Checking it once. Checking it twice.
AppSubmissionChecklist.objects.create(addon=addon, terms=True,
manifest=True)
# Create feature profile.
if waffle.switch_is_active('buchets'):
addon.current_version.features.update(
**features_form.cleaned_data)
# Call task outside of `commit_on_success` to avoid it running before
# the transaction is committed and not finding the app.
tasks.fetch_icon.delay(addon)
return redirect('submit.app.details', addon.app_slug)
return jingo.render(request, 'submit/manifest.html', {
'step': 'manifest',
'features_form': features_form,
'form': form,
'DEVICE_LOOKUP': DEVICE_LOOKUP
})
示例11: test_xpi_attributes
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def test_xpi_attributes(self):
addon = Addon.from_upload(self.get_upload('extension.xpi'),
[self.platform])
eq_(addon.name, 'xpi name')
eq_(addon.guid, '[email protected]')
eq_(addon.type, amo.ADDON_EXTENSION)
eq_(addon.status, amo.STATUS_NULL)
eq_(addon.homepage, 'http://homepage.com')
eq_(addon.summary, 'xpi description')
eq_(addon.description, None)
eq_(addon.slug, 'xpi-name')
示例12: test_search_attributes
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def test_search_attributes(self):
addon = Addon.from_upload(self.get_upload('search.xml'),
[self.platform])
eq_(addon.name, 'search tool')
eq_(addon.guid, None)
eq_(addon.type, amo.ADDON_SEARCH)
eq_(addon.status, amo.STATUS_NULL)
eq_(addon.homepage, None)
eq_(addon.description, None)
eq_(addon.slug, 'search-tool')
eq_(addon.summary, 'Search Engine for Firefox')
示例13: submit_addon
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def submit_addon(request, step):
if DEV_AGREEMENT_COOKIE not in request.COOKIES:
return redirect('devhub.submit.1')
form = forms.NewAddonForm(request.POST or None)
if request.method == 'POST':
if form.is_valid():
data = form.cleaned_data
addon = Addon.from_upload(data['upload'], data['platforms'])
AddonUser(addon=addon, user=request.amo_user).save()
SubmitStep.objects.create(addon=addon, step=3)
return redirect('devhub.submit.3', addon.slug)
return jingo.render(request, 'devhub/addons/submit/upload.html',
{'step': step, 'new_addon_form': form})
示例14: manifest
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def manifest(request):
form = forms.NewWebappForm(request.POST or None, request=request)
features_form = forms.AppFeaturesForm(request.POST or None)
features_form_valid = features_form.is_valid()
if request.method == "POST" and form.is_valid() and features_form_valid:
with transaction.commit_on_success():
addon = Addon.from_upload(
form.cleaned_data["upload"],
[Platform.objects.get(id=amo.PLATFORM_ALL.id)],
is_packaged=form.is_packaged(),
)
# Set the device type.
for device in form.get_devices():
addon.addondevicetype_set.get_or_create(device_type=device.id)
# Set the premium type, only bother if it's not free.
premium = form.get_paid()
if premium:
addon.update(premium_type=premium)
if addon.has_icon_in_manifest():
# Fetch the icon, do polling.
addon.update(icon_type="image/png")
else:
# In this case there is no need to do any polling.
addon.update(icon_type="")
AddonUser(addon=addon, user=request.amo_user).save()
# Checking it once. Checking it twice.
AppSubmissionChecklist.objects.create(addon=addon, terms=True, manifest=True, details=False)
# Create feature profile.
addon.current_version.features.update(**features_form.cleaned_data)
# Call task outside of `commit_on_success` to avoid it running before
# the transaction is committed and not finding the app.
tasks.fetch_icon.delay(addon)
return redirect("submit.app.details", addon.app_slug)
return render(
request,
"submit/manifest.html",
{"step": "manifest", "features_form": features_form, "form": form, "DEVICE_LOOKUP": DEVICE_LOOKUP},
)
示例15: obj_create
# 需要导入模块: from addons.models import Addon [as 别名]
# 或者: from addons.models.Addon import from_upload [as 别名]
def obj_create(self, bundle, request, **kwargs):
form = UploadForm(bundle.data)
if not form.is_valid():
raise self.form_errors(form)
if not (OwnerAuthorization().is_authorized(request, object=form.obj)):
raise ImmediateHttpResponse(response=http.HttpForbidden())
plats = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
# Create app, user and fetch the icon.
bundle.obj = Addon.from_upload(form.obj, plats, is_packaged=form.is_packaged)
AddonUser(addon=bundle.obj, user=request.amo_user).save()
self._icons_and_images(bundle.obj)
log.info("App created: %s" % bundle.obj.pk)
return bundle