本文整理汇总了Python中models.Images类的典型用法代码示例。如果您正苦于以下问题:Python Images类的具体用法?Python Images怎么用?Python Images使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Images类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addImage
def addImage(mime,description,bf,name):
'Add Image'
image=Images(mime=mime,description=description,bf=bf,name=name)
image.size=len(image.bf)
image.filetype,image.width,image.height=getImageInfo(bf)
image.put()
return image
示例2: delete
def delete(self, id):
image = Images.first(id=id)
msg = "The image could not be deleted."
if image and Images.delete(image):
msg = "Image deleted"
cherrypy.session['flash'] = msg
raise cherrypy.HTTPRedirect('/images')
示例3: addImage
def addImage(name, mime,description,tag,bf):
'Add Image'
image=Images(name=name, mime=mime,description=description,tag=tag.split(','), bf=bf)
image.size=len(image.bf)
image.filetype,image.width,image.height=getImageInfo(bf)
image.put()
AddTags(image.tag)
return image
示例4: AddImageByUrl
def AddImageByUrl(url,fileName,tag):
result = urlfetch.fetch(url)
if result.status_code == 200:
name = fileName
mtype = result.headers.get('Content-Type', '')
bits = result.content
gf=GaeFile()
gf.open(name,mtype);
gf.write(bits)
id=gf.close()
image=Images(description="/media/?key="+str(id))
image.mime=result.headers.get('Content-Type', '')
image.filetype=image.mime
# if image.mime.find('image')==-1:
# return None
image.size=len(bits)
image.width=-1;
image.height=-1;
# image.name=fileName
# image.filetype,image.width,image.height=getImageInfo(image.bf)
image.tag=tag.split(',')
image.put()
AddTags(image.tag)
return image
else:
return None
示例5: addImage
def addImage(mime,description,bf):
'Add Image'
image=Images(mime=mime,description=description)
image.size=len(image.bf)
image.filetype,image.width,image.height=getImageInfo(bf)
image.put()
imageblob = ImageBlob(image=image, bf=bf)
imageblob.put()
prependToRSS([image])
return image
示例6: get
def get(self):
collector = CloudFetch.CloudFetch()
urllist = collector.getUrlList()
#url = 'http://www.technobuffalo.com/wp-content/uploads/2012/12/Google-Apps.jpeg'
#urllist = urllist.append(url)
images = Images.all()
for url in urllist:
bf = urllib.urlopen(url).read()
#bf=self.request.get("file")
if not bf:
return self.redirect('/')
#name=self.request.body_file.vars['file'].filename
#mime = self.request.body_file.vars['file'].headers['content-type']
#if mime.find('image')==-1:
# return self.redirect('/admin/upload/')
#description=self.request.get("description")
mime = 'image'
description = 'Fetched From Cloud'
name = url.split('/')[len(url.split('/'))-1]
#DETECT DUPLICATE
flag = False;
for i in images:
if(i.name == name):
flag = True
break
if(flag == True):
continue
image=methods.addImage( mime, description, bf, name)
self.redirect('/')
示例7: delImageByid
def delImageByid(id):
image=Images.get_by_id(int(id))
if image:
imageblob = db.GqlQuery("SELECT * FROM ImageBlob WHERE image = :1", image).get()
if imageblob:
imageblob.delete()
image.delete()
示例8: delImage
def delImage(key):
image=Images.get(key)
if image:
imageblob = db.GqlQuery("SELECT * FROM ImageBlob WHERE image = :1", image).get()
if imageblob:
imageblob.delete()
image.delete()
示例9: index
def index(self):
user_id = cherrypy.session.get('user.id')
vms = VirtualMachines.find(user_id=user_id)
env = dict(
virtual_machines=vms,
images=Images.all(),
instance_types=InstanceTypes.all()
)
return self.render("virtual_machines/index.html", self.crumbs, **env)
示例10: gallery
def gallery(request,imagename=None):
print imagename
if request.method == 'POST':
title = request.POST['pname']
img_data = request.POST['pdata']
p = Images(title = title, img_data = img_data)
p.save()
if request.method == 'GET':
image = Images.objects.filter(title = imagename)
for i in image:
data = i.img_data
print json.dumps(data)
t = get_template('paint.html')
html = t.render(Context({}))
if data:
html="""<script>var data=JSON.parse(' """+data+""" ');</script>"""+html
else:
html="""<script>alert("Image not found")</script>"""+html
return HttpResponse(html)
示例11: add
def add(self, **post):
image = Images.new(name="", backend_id="", description="")
if post:
fields = ['name', 'backend_id', 'description']
data = self._get_data('image', fields, post)
self._set_data(image, data)
if image.validates() and Images.add(image):
cherrypy.session['flash'] = "Image added"
raise cherrypy.HTTPRedirect('/images')
cherrypy.session['flash'] = 'Invalid data'
backend_images = Images.get_backend_images()
env = dict(
image = image,
backend_images = backend_images
)
return self.render("/images/add.html", crumbs=self.crumbs, **env)
示例12: edit
def edit(self, id, **post):
image = Images.first(id=id)
if not image:
cherrypy.session['flash'] = "404 Image Not Found"
raise cherrypy.HTTPRedirect('/images')
if post:
fields = ['name', 'backend_id', 'description']
data = self._get_data('image', fields, post)
if image.update(data, fields):
cherrypy.session['flash'] = "Image successfully updated."
raise cherrypy.HTTPRedirect('/images')
cherrypy.session['flash'] = 'Invalid data'
backend_images = Images.get_backend_images()
env=dict(image = image, backend_images=backend_images)
return self.render("/images/edit.html", crumbs=self.crumbs, **env)
示例13: add_image
def add_image(request):
form = ImageForm()
if request.POST:
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
image = request.FILES['image_file']
comment = form.cleaned_data['comment']
format = image.name.split('.')[-1]
p = Images(comment = comment, name = '',
useragent = request.META['HTTP_USER_AGENT'],
ip = request.META['REMOTE_ADDR'], views = 0 ,views_last_hour = 0,
md5 = 0, format = format)
p.save()
save_image(image, p.id)
return HttpResponseRedirect('/%s' % to_62(p.id))
else:
form = ImageForm()
return render_to_response("forms/add_image.html", {'form': form})
else:
return render_to_response("forms/add_image.html", {'form': form})
示例14: running
def running(self):
creds = cherrypy.session.get('credentials')
vms = VirtualMachines.all()
images = Images.all()
instances = VirtualMachines.get_instances(creds)
env = dict(
virtual_machines=vms,
instances=instances,
images=images,
)
return self.render("virtual_machines/running.html", self.crumbs,**env)
示例15: add_image
def add_image(request):
#last_image_id = Images.objects.order_by('-id')[0].id else last_image_id = 0
form = ImageForm()
if request.POST:
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
image = request.FILES['image_file']
save_image(image)
#thumb_image = thumbnail(image)
#save_image(thumb_image)
p = Images(comment=request.POST['comment'], name = file.name,
useragent=request.META['HTTP_USER_AGENT'],
ip=request.META['REMOTE_ADDR'], views=0, md5=0 )
p.save()
return HttpResponse(image.name)
#return render_to_response("forms/add_image.html", {'form': form})
else:
return render_to_response("forms/add_image.html", {'form': form})
else:
return render_to_response("forms/add_image.html", {'form': form})