本文整理汇总了Python中mkt.webapps.models.Webapp.from_upload方法的典型用法代码示例。如果您正苦于以下问题:Python Webapp.from_upload方法的具体用法?Python Webapp.from_upload怎么用?Python Webapp.from_upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mkt.webapps.models.Webapp
的用法示例。
在下文中一共展示了Webapp.from_upload方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import from_upload [as 别名]
def create(self, request, *args, **kwargs):
uuid = request.DATA.get("upload", "")
if uuid:
is_packaged = True
else:
uuid = request.DATA.get("manifest", "")
is_packaged = False
if not uuid:
raise serializers.ValidationError("No upload or manifest specified.")
try:
upload = FileUpload.objects.get(uuid=uuid)
except FileUpload.DoesNotExist:
raise exceptions.ParseError("No upload found.")
if not upload.valid:
raise exceptions.ParseError("Upload not valid.")
if not request.user.read_dev_agreement:
log.info(u"Attempt to use API without dev agreement: %s" % request.user.pk)
raise exceptions.PermissionDenied("Terms of Service not accepted.")
if not (upload.user and upload.user.pk == request.user.pk):
raise exceptions.PermissionDenied("You do not own that app.")
# Create app, user and fetch the icon.
obj = Webapp.from_upload(upload, is_packaged=is_packaged)
AddonUser(addon=obj, user=request.user).save()
tasks.fetch_icon.delay(obj, obj.latest_version.all_files[0])
record_action("app-submitted", request, {"app-id": obj.pk})
log.info("App created: %s" % obj.pk)
data = AppSerializer(context=self.get_serializer_context()).to_native(obj)
return response.Response(data, status=201, headers={"Location": reverse("app-detail", kwargs={"pk": obj.pk})})
示例2: manifest
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp 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():
upload = form.cleaned_data['upload']
addon = Webapp.from_upload(upload, is_packaged=form.is_packaged())
if form.is_packaged():
validation = json.loads(upload.validation)
escalate_prerelease_permissions(
addon, validation, addon.latest_version)
# 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.user).save()
# Checking it once. Checking it twice.
AppSubmissionChecklist.objects.create(addon=addon, terms=True,
manifest=True, details=False)
# Create feature profile.
addon.latest_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, addon.latest_version.all_files[0])
return redirect('submit.app.details', addon.app_slug)
return render(request, 'submit/manifest.html',
{'step': 'manifest', 'features_form': features_form,
'form': form, 'PLATFORMS_NAMES': PLATFORMS_NAMES})
示例3: obj_create
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import from_upload [as 别名]
def obj_create(self, bundle, request, **kwargs):
form = UploadForm(bundle.data)
if not form.is_valid():
raise ValidationError(self.form_errors(form))
if not (OwnerAuthorization()
.is_authorized(request, object=form.obj)):
raise ImmediateHttpResponse(response=http.HttpUnauthorized())
plats = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
# Create app, user and fetch the icon.
bundle.obj = Webapp.from_upload(form.obj, plats)
AddonUser(addon=bundle.obj, user=request.amo_user).save()
tasks.fetch_icon.delay(bundle.obj)
log.info('App created: %s' % bundle.obj.pk)
return bundle
示例4: manifest
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp 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):
upload = form.cleaned_data['upload']
addon = Webapp.from_upload(upload, is_packaged=form.is_packaged())
file_obj = addon.latest_version.all_files[0]
if form.is_packaged():
validation = json.loads(upload.validation)
escalate_prerelease_permissions(
addon, validation, addon.latest_version)
addon.addondevicetype_set.get_or_create(
device_type=DEVICE_GAIA.id)
if addon.has_icon_in_manifest(file_obj):
# 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.user).save()
# Checking it once. Checking it twice.
AppSubmissionChecklist.objects.create(addon=addon, terms=True,
manifest=True, details=False)
# Create feature profile.
addon.latest_version.features.update(**features_form.cleaned_data)
tasks.fetch_icon.delay(addon.pk, file_obj.pk)
return redirect('submit.app.details', addon.app_slug)
return render(request, 'submit/manifest.html',
{'step': 'manifest', 'features_form': features_form,
'form': form})
示例5: create
# 需要导入模块: from mkt.webapps.models import Webapp [as 别名]
# 或者: from mkt.webapps.models.Webapp import from_upload [as 别名]
def create(self, request, *args, **kwargs):
uuid = request.data.get('upload', '')
if uuid:
is_packaged = True
else:
uuid = request.data.get('manifest', '')
is_packaged = False
if not uuid:
raise exceptions.ParseError(
'No upload or manifest specified.')
try:
upload = FileUpload.objects.get(uuid=uuid)
except FileUpload.DoesNotExist:
raise exceptions.ParseError('No upload found.')
if not upload.valid:
raise exceptions.ParseError('Upload not valid.')
if not request.user.read_dev_agreement:
log.info(u'Attempt to use API without dev agreement: %s'
% request.user.pk)
raise exceptions.PermissionDenied('Terms of Service not accepted.')
if not (upload.user and upload.user.pk == request.user.pk):
raise exceptions.PermissionDenied('You do not own that app.')
# Create app, user and fetch the icon.
try:
obj = Webapp.from_upload(upload, is_packaged=is_packaged)
except (serializers.ValidationError,
django_forms.ValidationError) as e:
raise exceptions.ParseError(unicode(e))
AddonUser(addon=obj, user=request.user).save()
tasks.fetch_icon.delay(obj.pk, obj.latest_version.all_files[0].pk)
record_action('app-submitted', request, {'app-id': obj.pk})
log.info('App created: %s' % obj.pk)
data = AppSerializer(
context=self.get_serializer_context(), instance=obj).data
return response.Response(
data, status=201,
headers={'Location': reverse('app-detail', kwargs={'pk': obj.pk})})