本文整理汇总了Python中models.Images.first方法的典型用法代码示例。如果您正苦于以下问题:Python Images.first方法的具体用法?Python Images.first怎么用?Python Images.first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Images
的用法示例。
在下文中一共展示了Images.first方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from models import Images [as 别名]
# 或者: from models.Images import first [as 别名]
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')
示例2: edit
# 需要导入模块: from models import Images [as 别名]
# 或者: from models.Images import first [as 别名]
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)
示例3: start
# 需要导入模块: from models import Images [as 别名]
# 或者: from models.Images import first [as 别名]
def start(self, **post):
if post:
self._validate_start_post_data(post)
creds = cherrypy.session.get('credentials')
image = Images.first(id=post['image.id'])
instance_type = self._get_instance_type(post)
self._validate_start_args(image, instance_type)
vm = VirtualMachines.new(status="new")
if VirtualMachines.add(vm):
if not vm.start_instance(image, instance_type, creds):
cherrypy.session['flash'] = 'The virtual machine could not be started.'
raise cherrypy.HTTPRedirect("/virtual_machines")
else:
cherrypy.session['flash'] = 'Missing image id.'
raise cherrypy.HTTPRedirect("/virtual_machines")