本文整理汇总了Python中models.Image.filename方法的典型用法代码示例。如果您正苦于以下问题:Python Image.filename方法的具体用法?Python Image.filename怎么用?Python Image.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.filename方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import filename [as 别名]
def upload():
form = UploadForm()
if form.validate_on_submit():
try:
name = form.name.data
filename = images.save(form.image.data, folder=unicode(g.user.id))
#Checks if Image is new or exists before commit changes
image = Image.query.filter_by(name = form.name.data).first()
if image is None:
image = Image(name = name, filename = filename, uid=g.user.id)
message = "%r image uploaded." % name
else:
old_file = image.filename
image.filename = filename
message = "%r image changed." % name
db.session.add(image)
db.session.commit()
flash(message)
return redirect(url_for('index'))
except UploadNotAllowed:
flash("Not allowed to upload image")
else:
filename = None
return render_template('upload.html',
form = form,
filename = filename)
示例2: post_create_user
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import filename [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])
示例3: upload_file
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import filename [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 filename [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))