本文整理汇总了Python中models.Image.save方法的典型用法代码示例。如果您正苦于以下问题:Python Image.save方法的具体用法?Python Image.save怎么用?Python Image.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleImagePopAdd
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def handleImagePopAdd(request, addForm, field, template="form/popmediaadd.html"):
if not request.method == "POST":
f = UploadForm()
ctx = {'form': f, 'field': field}
return render(request, template, ctx)
f = UploadForm(request.POST, request.FILES)
if not f.is_valid() and not request.FILES['file'].name.endswith('.svg'):
ctx = {'form': f, 'field': field}
return render(request, template, ctx)
file = request.FILES['file']
store_in_s3(file.name, file.read())
p = Image(url="http://%s.s3.amazonaws.com/%s" % (bucket, file.name))
if isinstance(request.user, AnonymousUser):
p.user = User.objects.get(username="Anonymous")
else:
p.user = User.objects.get(username=request.user)
if request.POST['artist']:
p.artist = User.objects.get(pk=request.POST['artist'])
p.save()
newObject = p
# Self destruction:
if newObject:
return HttpResponse('<script type="text/javascript">opener.dismissAddAnotherPopup(window, "%s", "%s");</script>' %\
(escape(newObject._get_pk_val()), escape(newObject)))
示例2: upload_image_for_match
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def upload_image_for_match(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
#title
tit = request.REQUEST.get("title", None)
#Sensor
lon = request.REQUEST.get('longitude', None)
lat = request.REQUEST.get('latitude', None)
azi = request.REQUEST.get("azimuth", None)
pit = request.REQUEST.get("pitch", None)
rol = request.REQUEST.get("roll", None)
#Image
image = Image(image_path = request.FILES['file'],
azimuth = azi,
pitch = pit,
roll = rol,
longitude = lon,
latitude = lat,
title = tit)
image.save()
'''match the image against the database'''
name = image.match()
obj = Object.objects.get(object_name = name)
#wrap object_url and object_name as json and return
return responseJson({'object_url':obj.img_path.name, 'object':obj.object_name})
else:
return fail()
else:
return fail()
示例3: user_add
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def user_add():
import bcrypt
PostForm = model_form(User)
form = PostForm(request.form)
if request.method == 'POST': #and form.validate():
#the following is described in flask-uploads documentation
filename = "" #store blank photo filename
#initialize default user photo
i = Image(image_path = 'default_image', is_profile=True)
if 'photo' in request.files:
filename = photos.save(request.files['photo'])
i = Image(image_path = filename, is_profile=True)
flash("Photo saved.")
i.save()
#hash password stored in database so that it is not viewable by people in Romania
hashed = bcrypt.hashpw(request.form["password"], bcrypt.gensalt())
u = User( email = request.form["email"],
first_name = request.form["first_name"],
last_name =request.form["last_name"],
password = hashed,
authenticated = False,
philosophy = request.form['philosophy'],
tags = request.form['tags'].split(','),
)
u.profile_picture= i
u.save()
return "done:" + request.form["email"] + " " + request.form["first_name"]+ " " + request.form["last_name"] + " " + '/_uploads/photos/'+i.image_path
else:
return render_template('add.html', form=form, cities = OccupyCity.objects.all())
示例4: receive
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def receive():
data = request.data
data = xmltodict.parse(data)['xml']
if data['MsgType'] == 'text':
return send_text(data['FromUserName'], 'hi')
if data['MsgType'] == 'image':
token = current_access_token()
file_url = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s' % (token, data['MediaId'])
file = requests.get(file_url, stream=True).raw
i = Image()
i.image = file
uuid = shortuuid.ShortUUID().random(length=6)
while Image.objects(iid=uuid):
uuid = shortuuid.ShortUUID().random(length=6)
i.iid = uuid
i.title = data['MediaId']
i.user = system_user
i.description = ''
i.tags = []
i.save()
return send_text(
data['FromUserName'], '업로드 성공, 사진주소:%s%s' % (
request.url_root[:-1], url_for('light-cms.image', iid=i.iid)
)
)
示例5: post_create_user
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [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])
示例6: create_image
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def create_image(self,request):
u = self.current_user(request)
if 'description' in request.POST:
image = list(Image.objects.filter(user=u))[-1:][0]
descr = request.POST['description']
image.description = descr
image.save()
return response('Description added to image successfully')
i = Image(link=self.upload_image(request),user=u)
i.save()
return response('Image created successfully')
示例7: process_uploaded_file
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def process_uploaded_file(self, uploaded, object, request):
# example:
title = request.POST.get('title', '') or uploaded.name
f = Image(image=uploaded, name=title)
f.save()
return {
'url': f.imagem(),
'thumbnail_url': f.imagem(),
'id': f.id,
'name': f.name,
}
示例8: load
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def load(hotelname, hoteladdress, hotelweb, latitude, longitude, description, imagelist, categorylist):
#itertools to work with multiple lists at once
for name, address, web, latit, longit, descr, category, images in itertools.izip(hotelname, hoteladdress, hotelweb, latitude, longitude, description, categorylist, imagelist):
#Strip HTML tags
descr = strip_tags(descr)
print "Saving: " + name
hotel = Hotel(name=name, web=web, body=descr, address=address, category=category[0],
latitude=latit, longitude=longit, stars=category[1])
hotel.save()
identifier = Hotel.objects.get(name=name)
urls =' '.join(images)
images = Image(hotel=identifier, url_image=urls)
images.save()
示例9: refresh
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [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)
示例10: store_set
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def store_set(self, set):
img = Image()
img.userId = self.user
img.url = set['url']
img.save()
name = "%d.%s" % (img.id, set['format'].lower())
size = set['sizes']
img.full.save(name, File(size['full']), save=False)
img.medium.save(name, File(size['medium']), save=False)
img.thumb.save(name, File(size['thumb']), save=False)
img.save()
return img
示例11: t065_Image
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def t065_Image(self):
"""Immagini"""
L.i("ImageTestData load start")
for el in TestData.listImages:
img = Image(
description = el['description'],
link = el['link'],
type = el['type'],
blob = el['blob']
)
self.images.append(img)
img.save()
L.i("ImageTestData ended")
return True
示例12: test_create
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def test_create(self):
"""
Simple test (without image file) to see if image can be created
"""
i = Image()
i.title = "Test"
i.description = "Long image image description"
i.description_short = "Short image description"
i.save()
db_i = Image.objects.get(pk=1)
self.assertEqual(i.title, db_i.title)
self.assertEqual(i.description, db_i.description)
self.assertEqual(i.description_short, db_i.description_short)
示例13: submit
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def submit(request):
recipe_form = SubmitRecipeForm()
image_form = SubmitRimageForm()
submitted = False
if request.method == 'POST':
name = request.POST.get('name')
steps=request.POST.get('steps')
ingredients=request.POST.get('ingredients')
image= request.POST.get('image')
obj= Recipe(name=name,steps=steps,ingredients=ingredients)
obj.save()
obj1 = Image(name=obj,image=image)
obj1.save()
submitted = True
return render(request, 'submit-form.html', {'recipe_form':recipe_form,'image_form':image_form,'submitted':submitted } )
示例14: multiuploader
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def multiuploader(request):
if request.method == 'POST':
log.info('received POST to main multiuploader view')
if request.FILES == None:
return HttpResponseBadRequest('Must have files attached!')
#getting file data for farther manipulations
file = request.FILES[u'files[]']
wrapped_file = UploadedFile(file)
filename = wrapped_file.name
file_size = wrapped_file.file.size
log.info ('Got file: "'+str(filename)+'"')
#writing file manually into model
#because we don't need form of any type.
image = Image()
image.title=str(filename)
image.image=file
image.save()
log.info('File saving done')
#getting url for photo deletion
file_delete_url = '/delete/'
#getting file url here
file_url = '/'
#getting thumbnail url using sorl-thumbnail
im = get_thumbnail(image, "80x80", quality=50)
thumb_url = im.url
#generating json response array
result = []
result.append({"name":filename,
"size":file_size,
"url":file_url,
"thumbnail_url":thumb_url,
"delete_url":file_delete_url+str(image.pk)+'/',
"delete_type":"POST",})
response_data = simplejson.dumps(result)
return HttpResponse(response_data, mimetype='application/json')
else: #GET
return render_to_response('multiuploader_main.html',
{'static_url':settings.MEDIA_URL,
'open_tv':u'{{',
'close_tv':u'}}'},
)
示例15: drop
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import save [as 别名]
def drop():
file = request.files['file']
i = Image()
i.title = file.filename
i.image = file
uuid = shortuuid.ShortUUID().random(length=6)
while Image.objects(iid=uuid):
uuid = shortuuid.ShortUUID().random(length=6)
i.iid = uuid
if login.current_user.is_active():
i.user = login.current_user._get_current_object()
else:
i.user = system_user
i.description = ''
i.tags = []
i.save()
return jsonify(id=uuid)