本文整理汇总了Python中models.Image.parent_segment_id方法的典型用法代码示例。如果您正苦于以下问题:Python Image.parent_segment_id方法的具体用法?Python Image.parent_segment_id怎么用?Python Image.parent_segment_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.parent_segment_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import parent_segment_id [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))