本文整理汇总了Python中models.Image.add方法的典型用法代码示例。如果您正苦于以下问题:Python Image.add方法的具体用法?Python Image.add怎么用?Python Image.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_add
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import add [as 别名]
def test_add(self):
from models import Image
Image.add(name="Hallo.img")
img = Image.by_id(1)
self.assertEqual(1, img.id)
self.assertEqual("Hallo.img", img.name)
self.assertEqual("hallo.img", img.route)
示例2: test_image_deleted
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import add [as 别名]
def test_image_deleted(self):
img_id = Image.add(content_type='image/jpeg', raw_data='010101')
news = dict(
rank = 1,
title = 'title',
url = 'http://localhost/%s' % random.random(),
comhead = 'localhost',
score = '100',
author = 'poly',
author_link = 'http://localhost/',
submit_time = '10 hours ago',
comment_cnt = '100',
comment_url = 'http://localhost',
summary = 'Hello world!',
img_id = img_id
)
existing_keys = [n.url for n in StartupNews.query.all()]
pk = StartupNews.add(**news)
# Ensure saved
self.assertEqual(StartupNews.query.get(pk).url, pk)
self.assertEqual(Image.query.get(img_id).id, img_id)
StartupNews.remove_except(existing_keys)
# Ensure removed
self.assertIsNone(StartupNews.query.get(pk))
self.assertIsNone(Image.query.get(img_id))
示例3: add
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import add [as 别名]
def add(self):
request = self.request
form = ImageView.UploadForm(request.POST)
if request.method == 'POST' and form.validate():
# looks like we will us form here only for validation an html gen
# name = form.image.name doesn't work this way there is always 'image' as name
name = request.POST['image'].filename
path = os.path.join(os.path.dirname(__file__),'files', name)
in_file = request.POST['image'].file
with open(path, "w") as fd:
in_file.seek(0)
while 1:
data = in_file.read(2<<16)
if not data:
break
fd.write(data)
image = Image.add(name)
return HTTPFound(location=request.route_url(
'image_view',
id=image.id,
)
)
return dict(
form=form,
url=self.request.route_url('image_add'),
pages=Page.all(),
logged_in=authenticated_userid(self.request),
)