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


Python Photo.image方法代码示例

本文整理汇总了Python中models.Photo.image方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.image方法的具体用法?Python Photo.image怎么用?Python Photo.image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Photo的用法示例。


在下文中一共展示了Photo.image方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_photo

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import image [as 别名]
def load_photo(request):
    if request.method=='POST':
        if request.FILES is None:
            return HttpResponseBadRequest('No file[] found')

        try:
            id = int(request.POST['id'])
            tournament = Tournament.objects.get(pk=id)
            if tournament is None:
                return HttpResponseBadRequest('Cannot find corresponding dress')
        except:
            return HttpResponseBadRequest('Cannot find id')            
            
        file = request.FILES[u'files[]']
        
        if str(file).lower()[-4:] not in ['.jpg', 'jpeg', '.gif', '.png', '.bmp', '.ico',]:
            return HttpResponseBadRequest('Only images allowed')
        
        wrapped_file = UploadedFile(file)
        filename = wrapped_file.name
        file_size = wrapped_file.file.size
    
        photo = Photo()        
        photo.tournament = tournament
        photo.description = filename
        photo.image = file
        photo.save()

        try:
            im = get_thumbnail(photo.image, "200", quality=50)
            thumb_url = im.url
        except Exception, ex:
            photo.delete()
            return HttpResponseBadRequest('Cannot read thumbnail')   
    
        result = [{"name": filename,
                   "id": photo.id,
                   "size": file_size,
                   "url": photo.image.url,
                   "thumbnail_url": thumb_url,
                   }]
        response_data = simplejson.dumps(result)

        mimetype = 'text/plain'
        if 'HTTP_ACCEPT_ENCODING' in request.META.keys():
            if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
                mimetype = 'application/json'
        return HttpResponse(response_data, mimetype=mimetype)
开发者ID:antofik,项目名称:Python,代码行数:50,代码来源:views.py

示例2: upload

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import image [as 别名]
def upload(req):
    if req.method == "POST":
        pf = PhotoForm(req.POST, req.FILES)
        if pf.is_valid():
            # 获取表单信息
            title = pf.cleaned_data['title']
            image = pf.cleaned_data['image']
            # 写入数据库
            photo = Photo()
            uid = req.session['user_id']
            iid = 1#req.session['item_id']
            photo.title = title
            photo.image = image
            photo.uid = uid
            photo.iid = iid
            photo.save()
            return HttpResponseRedirect('/online/photolist/')
    else:
        pf = PhotoForm()
        return render_to_response('upload.html', {'pf': pf}, context_instance=RequestContext(req))
开发者ID:sweetlipa,项目名称:album,代码行数:22,代码来源:views.py

示例3: test_image_palette

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import image [as 别名]
    def test_image_palette(self):
        """
        Test images uploading to the correct location.
        """

        IMAGE_FILE = "test_images/22.jpg"
        p = Photo()
        p.image = IMAGE_FILE
        p.shot_date="2010-10-10"
        p.save()

        # are the palette colors correct?
        # this test will break when/if the palette generation
        # algorithm is changed, obviously.
        self.failUnlessEqual( p.suggest0, "262624" )
        self.failUnlessEqual( p.suggest1, "797a7a" )
        self.failUnlessEqual( p.suggest2, "373835" )
        self.failUnlessEqual( p.suggest3, "111210" )
        self.failUnlessEqual( p.suggest4, "525251" )
        self.failUnlessEqual( p.suggest5, "090908" )
        self.failUnlessEqual( p.suggest6, "1a1b19" )
        self.failUnlessEqual( p.suggest7, "bbb8b3" )
开发者ID:mwcz,项目名称:phyton,代码行数:24,代码来源:tests.py


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