本文整理汇总了Python中models.Image.name方法的典型用法代码示例。如果您正苦于以下问题:Python Image.name方法的具体用法?Python Image.name怎么用?Python Image.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_create_user
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import name [as 别名]
def post_create_user(sender, instance, created, **kwargs):
print "Post save emited for", instance
users = User.objects.filter(username="user_template")
if created and len(users) > 0:
user_template = users[0]
print "user_template", user_template
user = instance
image_types = ImageType.objects.filter(user=user_template)
print "image_types", image_types
print 'mkdir {0}{1}'.format(BASE_DIR+'/segment/static/uploads/',str(user_template.id),str(user.id))
os.popen('cp -a {0}{1} {0}{2}'.format(BASE_DIR+'/segment/static/uploads/',str(user_template.id),str(user.id)))
for image_type in image_types:
print "imagetype", image_type
#folder_random_name = get_random_name()
#print 'mkdir {0}{1}/{2}'.format(BASE_DIR+'/segment/static/uploads/',str(user.id),folder_random_name)
#os.popen('mkdir {0}{1}/{2}'.format(BASE_DIR+'/segment/static/uploads/',str(user.id),folder_random_name))
#os.popen('mkdir {0}{1}/{2}/segments'.format(BASE_DIR+'/segment/static/uploads/',str(user.id),folder_random_name))
#os.popen('mkdir {0}{1}/{2}/segments'.format(BASE_DIR+'/segment/static/uploads/',str(user.id),folder_random_name))
it = ImageType()
it.name=image_type.name
it.user = user
it.folder = image_type.folder
it.save()
it.users_shared.add(user)
tags = Tag.objects.filter(image_type=image_type)
for tag in tags:
t = Tag()
t.name = tag.name
t.image_type = it
t.save()
images = Image.objects.filter(image_type=image_type)
print "images", images
for image in images:
i = Image()
i.name = image.name
i.image_type = it
i.filename = str(image.filename).replace('/'+str(user_template.id)+'/','/'+str(user.id)+'/')
#print 'cp "{0}{1}" "{2}{3}"'.format(BASE_DIR+'/segment/static/',str(image.filename),BASE_DIR+'/segment/static/' ,str(i.filename))
#os.popen('cp "{0}{1}" "{2}{3}"'.format(BASE_DIR+'/segment/static/',str(image.filename),BASE_DIR+'/segment/static/' ,str(i.filename)))
i.parent_segment = image.parent_segment
i.save()
segments = Segment.objects.filter(image=image)
print "image id", image.id, "segments", len(segments), segments
for segment in segments:
s = Segment()
s.x1 = segment.x1
s.y1 = segment.y1
s.x2 = segment.x2
s.y2 = segment.y2
s.image = i
s.filename = str(segment.filename).replace('/'+str(user_template.id)+'/','/'+str(user.id)+'/')
#print 'cp "{0}{1}" "{2}{3}"'.format(BASE_DIR+'/segment/static/',str(segment.filename),BASE_DIR+'/segment/static/',str(s.filename))
#os.popen('cp "{0}{1}" "{2}{3}"'.format(BASE_DIR+'/segment/static/',str(segment.filename),BASE_DIR+'/segment/static/',str(s.filename)))
s.save()
for tag in segment.tags.all():
tag_new = Tag.objects.filter(image_type=it,name=tag.name)
s.tags.add(tag_new[0])
示例2: refresh
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import name [as 别名]
def refresh(self, request=None):
""" Update image list from local configuration """
LOG.info("Refreshing image db")
images_cleanup()
for s in DockerManager().list_images():
instance = Image()
instance.name = s['name']
instance.version = s['version']
instance.dockerfile = s['dockerfile']
instance.system = s['system']
instance.tag = s['tag']
instance.save()
return self.list(None)
示例3: upload_file
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import name [as 别名]
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = '%s%s' % (str(uuid.uuid1()), mimetypes.guess_extension(file.mimetype, strict=False))
print filename
save_file(file.stream, filename, file.mimetype)
image = Image()
image.name = 'test'
image.filename = filename
image.mimetype = file.mimetype
current_app.db_session.add(image)
current_app.db_session.commit()
return render_template('add.html')
示例4: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import name [as 别名]
def post(self):
post = self.request.POST
kind=post['kind']
if kind== 'taglineform':
properties = GeneralSiteProperties.all().get()
if properties == None:
properties = GeneralSiteProperties(tag_line=post['tagline'])
properties.put()
else:
properties.tag_line = post['tagline']
properties.put()
elif kind=="image_upload":
if(self.request.get("picture")):
try:
if('resize' in post):
pictureImage = Image(picture=images.resize(self.request.get("picture"),int(post['height']), int(post['width'])),
name="no-name",title=" ",alt=" ")
else:
pictureImage = Image(picture=self.request.get("picture"),name="no-name",title=" ",alt=" ")
if(post['alias']!=""):
replace=True
name=post['alias']
for other_image in Image.all():
if other_image.name == name :
replace=False
self.admin_message="You cannot use %s as an alias as it is used for another image" % name
if replace :
pictureImage.name=name
if(post['title']!=""):
pictureImage.name=post['title']
if(post['alt']!=""):
pictureImage.name=post['alt']
pictureImage.put()
self.admin_message = 'Image uploaded'
except RequestTooLargeError:
self.admin_message = 'Image not uploaded - too large'
except TypeError:
self.admin_message = 'Width and Height have to be integers'
else:
self.admin_message = 'You need to actually select a picture!'
kind='image'
else :
things_deleted = 0
for entry_key in self.request.POST.getall('delete_entry'):
try:
entry_key = Key(entry_key)
except BadKeyError:
# Wrong syntax for a key, move on to next key.
continue
if(kind=='news'):
thing = NewsArticleNew.get(entry_key)
elif(kind=='talk'):
thing = TalkNew.get(entry_key)
elif(kind=='hack'):
thing = Hack.get(entry_key)
if thing:
thing.delete()
things_deleted += 1
# Else, not article has this key.
self.admin_message = '%d %s(s) deleted.' % (things_deleted,self.thing_descriptors.get(kind))
self.render_template('admin',
{'news_list' : NewsArticleNew.all().order('-date'),
'talk_list' : TalkNew.all().order('-date'),
'hack_list' : Hack.all().order('-date'),
'image_list' : Image.all(),
'image_height' : self.image_height,
'image_width' : self.image_width,
'members': Member.all(),
'message' : self.admin_message,
'tabselect':kind})
示例5: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import name [as 别名]
def post(self,request):
id_image=zoom=''
if 'image' in request.POST:
id_image = request.POST['image']
image = Image.objects.get(id=id_image)
path_segments = BASE_DIR+'/segment/static/uploads/%s/%s/segments/'%(request.user.id,image.image_type.folder)
if not os.path.exists(path_segments):
os.makedirs(path_segments)
draw_segments='false'
if 'zoom' in request.POST:
zoom = float(request.POST['zoom'])
if 'draw_segments' in request.POST:
draw_segments = request.POST['draw_segments']
if 'btn_return' in request.POST:
return HttpResponseRedirect('/limages/')
if 'btn_create_segment' in request.POST:
post = save_new_tags(request,image)
form_segment = SegmentForm(post)
if form_segment.is_valid():
try:
#TODO primer crear imatge i dsp guardar segment, no a l'inreves
segment = form_segment.save() #commit=False
filename = 'segment_'+str(id_image)+"_"+str(segment.id)+'.jpg'
segment.filename = 'uploads/%s/%s/segments/%s'%(request.user.id,image.image_type.folder,filename)
segment.save()
x1=int(request.POST['x1'])
y1=int(request.POST['y1'])
x2=int(request.POST['x2'])
y2=int(request.POST['y2'])
image = Image.objects.get(id=id_image)
image_path = BASE_DIR+'/segment/static/'+str(image.filename)
i = PIL.Image.open(image_path)
filepath_segment = path_segments +filename
i.crop((x1,y1,x2,y2)).save(filepath_segment)
segment = form_segment.save()
except:
traceback.print_exc()
elif 'btn_generate_images' in request.POST:
form_generate_images = GenerateImagesForm(user=request.user,image=image,data=request.POST)
if form_generate_images.is_valid():
tags = request.POST['tags']
segments = Segment.objects.filter(tags=tags,image_id=id_image)
for segment in segments:
image = Image()
image.name = segment.filename.split('/')[4].split('.jpg')[0]
image.filename = segment.filename
image.image_type_id = request.POST['image_type']
image.parent_segment_id = segment.id
image.save()
elif 'btn_remove_segment' in request.POST:
id_segment = request.POST['selected_row']
segment = Segment.objects.get(id = id_segment)
if segment:
filepath = path_segments+'segment_'+str(id_image)+"_"+str(segment.id)+'.jpg'
if os.path.isfile(filepath):
os.remove(filepath)
segment.delete()
elif 'btn_zoom_in' in request.POST:
if zoom < 5:
zoom = zoom+0.2
return HttpResponseRedirect('/segment_image/?id='+id_image+'&zoom='+str(zoom)+'&draw_segments='+str(draw_segments))
elif 'btn_zoom_out' in request.POST:
if zoom > 0.2:
zoom = zoom-0.2
return HttpResponseRedirect('/segment_image/?id='+id_image+'&zoom='+str(zoom)+'&draw_segments='+str(draw_segments))
return HttpResponseRedirect('/segment_image/?id='+id_image+'&zoom='+str(zoom)+'&draw_segments='+str(draw_segments))