当前位置: 首页>>代码示例>>Python>>正文


Python Image.add方法代码示例

本文整理汇总了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)
开发者ID:daymien,项目名称:pymyblog,代码行数:10,代码来源:test_models.py

示例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))
开发者ID:ajay05,项目名称:hacker-news-digest,代码行数:29,代码来源:test_database.py

示例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),
         )
开发者ID:daymien,项目名称:pymyblog,代码行数:30,代码来源:views.py


注:本文中的models.Image.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。