本文整理汇总了Python中mkt.developers.utils.check_upload函数的典型用法代码示例。如果您正苦于以下问题:Python check_upload函数的具体用法?Python check_upload怎么用?Python check_upload使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_upload函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_file
def clean_file(self):
file_ = self.cleaned_data.get("file", {})
file_obj = parse(file_)
errors, hash_ = check_upload(file_obj, self.upload_type, file_["type"])
if errors:
raise forms.ValidationError(errors)
self.hash_ = hash_
return file_
示例2: clean_file
def clean_file(self):
file_ = self.cleaned_data.get('file', {})
file_obj = parse(file_)
errors, hash_ = check_upload(file_obj, 'preview', file_['type'])
if errors:
raise forms.ValidationError(errors)
self.hash_ = hash_
return file_
示例3: test_promo_img_too_small
def test_promo_img_too_small(self):
with local_storage.open(get_image_path('preview.jpg')) as f:
errors, upload_hash = check_upload(f, 'promo_img', 'image/png')
ok_(errors)
ok_(upload_hash)
tmp_img_path = os.path.join(settings.TMP_PATH, 'promo_img',
upload_hash)
ok_(os.path.isfile(tmp_img_path))
示例4: test_promo_img_ok
def test_promo_img_ok(self):
with local_storage.open(get_image_path('game_1050.jpg')) as f:
errors, upload_hash = check_upload(f, 'promo_img', 'image/png')
ok_(not errors)
ok_(upload_hash)
tmp_img_path = os.path.join(settings.TMP_PATH, 'promo_img',
upload_hash)
ok_(private_storage.exists(tmp_img_path))
示例5: test_icon_ok
def test_icon_ok(self):
with local_storage.open(get_image_path('mozilla-sq.png')) as f:
errors, upload_hash = check_upload(f, 'icon', 'image/png')
ok_(not errors)
ok_(upload_hash)
tmp_img_path = os.path.join(settings.TMP_PATH, 'icon',
upload_hash)
ok_(os.path.isfile(tmp_img_path))
示例6: test_preview_too_small
def test_preview_too_small(self):
with local_storage.open(get_image_path('mkt_icon_72.png')) as f:
errors, upload_hash = check_upload(f, 'preview', 'image/png')
ok_(errors)
ok_(upload_hash)
tmp_img_path = os.path.join(settings.TMP_PATH, 'preview',
upload_hash)
ok_(private_storage.exists(tmp_img_path))
示例7: clean_promo_img
def clean_promo_img(self):
image = self.cleaned_data[self.upload_type]
errors, upload_hash = check_upload(image, self.upload_type,
image.content_type)
if errors:
log.info('Promo img errors: %s' % errors)
raise forms.ValidationError(errors)
self.upload_hash = upload_hash
return image
示例8: clean_file
def clean_file(self):
file_ = self.cleaned_data.get('file', {})
try:
if not set(['data', 'type']).issubset(set(file_.keys())):
raise forms.ValidationError('Type and data are required.')
except AttributeError:
raise forms.ValidationError('File must be a dictionary.')
file_obj = StringIO.StringIO(base64.b64decode(file_['data']))
errors, hash_ = check_upload(file_obj, 'graphic', file_['type'])
if errors:
raise forms.ValidationError(errors)
self.hash_ = hash_
return file_
示例9: ajax_upload_media
def ajax_upload_media(request, upload_type):
errors = []
upload_hash = ""
if "upload_image" in request.FILES:
upload_preview = request.FILES["upload_image"]
upload_preview.seek(0)
content_type = upload_preview.content_type
errors, upload_hash = check_upload(upload_preview, upload_type, content_type)
else:
errors.append(_("There was an error uploading your preview."))
if errors:
upload_hash = ""
return {"upload_hash": upload_hash, "errors": errors}
示例10: ajax_upload_media
def ajax_upload_media(request, upload_type):
errors = []
upload_hash = ''
if 'upload_image' in request.FILES:
upload_preview = request.FILES['upload_image']
upload_preview.seek(0)
content_type = upload_preview.content_type
errors, upload_hash = check_upload(upload_preview, upload_type,
content_type)
else:
errors.append(_('There was an error uploading your preview.'))
if errors:
upload_hash = ''
return {'upload_hash': upload_hash, 'errors': errors}
示例11: test_upload_type_not_recognized
def test_upload_type_not_recognized(self):
with self.assertRaises(ValueError):
check_upload([], 'graphic', 'image/jpg')
示例12: test_not_valid
def test_not_valid(self):
with self.assertRaises(ValueError):
check_upload([], 'graphic', 'image/jpg')
示例13: test_valid
def test_valid(self):
with storage.open(self.preview_image()) as f:
errors, hash = check_upload(f, 'preview', 'image/png')
assert not errors
示例14: test_valid
def test_valid(self):
with storage.open(get_image_path('preview.jpg')) as f:
errors, hash = check_upload(f, 'preview', 'image/png')
assert not errors