本文整理汇总了Python中models.Image类的典型用法代码示例。如果您正苦于以下问题:Python Image类的具体用法?Python Image怎么用?Python Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_add
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())
示例2: transfer_s3_structure_to_db
def transfer_s3_structure_to_db(name, path, parent_directory, is_dir=False):
if parent_directory is not None:
par_dir = Directory.get(Directory.key == parent_directory)
else:
par_dir = FakeDirectory()
par_dir.id = None
if is_dir:
try:
Directory.get(Directory.key == path)
return False
except DoesNotExist:
Directory.create(
name = name,
key = path,
parent_directory = par_dir.id
)
return True
else:
try:
Image.get(Image.key == path)
return False
except DoesNotExist:
Image.create(
name = name,
key = path,
directory = par_dir.id
)
return True
示例3: receive
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)
)
)
示例4: test_create_image
def test_create_image(self):
i = Image(slug="broom", icon_set="fugue", path="icons/fugue/broom.png")
i.put()
self.assertEquals(i.slug, "broom")
self.assertEquals(i.icon_set, "fugue")
self.assertEquals(i.path, "icons/fugue/broom.png")
self.assertEquals(i.absolute_url(), "/images/icons/fugue/broom.png")
示例5: get_contents
def get_contents(self):
db_id = Directory.get(Directory.key == self.key).id
directories = Directory.select().where(Directory.parent_directory == db_id)
has_probes = False
try:
has_probes = Directory.get(Directory.key == directories
.first().key).images.first()
except:
pass
if has_probes:
directories = [DirectoryTree(d.name, d.key).get_contents() for d in directories]
self.directories = [d.serialized for d in directories]
else:
self.directories = [DirectoryTree(d.name, d.key).serialized for d in directories]
self.images = [image.serialized for image in Image.select().where(Image.directory == db_id)]
if self.images:
stack_title = self.key[:-1]
try:
stack_id = Stack.get(Stack.title == stack_title).id
except models.DoesNotExist:
images = Image.select().where(Image.directory == db_id)
stack = models.Stack.create(title=stack_title)
for image in images:
try:
models.StackImage.create(stack=stack, image = image.id)
except Exception as ex:
print ex
stack_id = stack.id
self.stack_id = stack_id
return self
示例6: upload
def upload():
with open('data.csv') as f:
reader = csv.DictReader(f)
for row in reader:
try:
s = Store()
print row['name'], row['images'], row['types']
if re.search("\[.*\]", row['reference']):
row['place_id'] = row['scope']
row['scope'] = row['latlng']
row['latlng'] = row['address']
row['address'] = row['photos']
row['photos'] = row['reference']
print row['name'], row['images'], row['types']
s.tags = json.loads(row['types'])
s.point = db.GeoPt(*eval(row['latlng']))
s.reference = row['reference'] and row['reference'][0] or ""
s.address = row['address']
s.name = row['name']
for img in eval(row['images']):
image = Image()
image.image = img
image.put()
s.imgs.append(image)
except Exception as e:
pass
finally:
s.put()
示例7: upload
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)
示例8: create_tables
def create_tables():
from models import Image, Imageuri, ImageFragment, Metadata, Annotation
Image.create_table()
Imageuri.create_table()
ImageFragment.create_table()
Metadata.create_table()
Annotation.create_table()
示例9: upload_image_for_match
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()
示例10: get
def get(self, hash, extension=None):
q = Album.all().filter('hash =', hash)
album = q.get()
if album:
if extension:
return self.error(404)
q = Image.all().filter('album =', album)
return self.response.out.write(render_template('album.html', {
'name': album.name,
'images': q,
}))
q = Image.all().filter('hash =', hash)
image = q.get()
if image:
if not extension:
return self.response.out.write(render_template('image.html',
{ 'image': image }))
elif image.extension == extension:
return write_image(self, image.image_data, extension)
else:
return self.error(404)
return self.error(404)
示例11: post
def post(self):
if not setup_occurred():
Status.load_defaults()
Image.load_defaults()
api.invalidate_cache()
finish_setup()
self.redirect("/admin")
示例12: post
def post(self, user, account, group_id):
group = get_image_group_or_404(self, group_id)
# FIXME: admins!
if group.owner.key() != account.key():
return render_json_response(self, {"error": "access-denied"})
file_name = self.request.headers["X-File-Name"]
data = self.request.body
mime_type = mimetypes.guess_type(file_name)[0]
if not mime_type.startswith("image/"):
return render_json_response(self, {"error": "wrong-file-type"})
img = images.Image(data)
imgdata = ImageData(data=data)
imgdata.put()
image = Image(
file_name=file_name,
width=img.width,
height=img.height,
mime_type=mime_type,
group=group,
data=imgdata,
digest=hashlib.sha1(data).hexdigest(),
)
image.put()
memcache.delete(group.memcache_key())
return render_json_response(self, {"name": image.file_name})
示例13: setUp
def setUp(self):
super(StatusInstanceTest, self).setUp()
image = Image(icon_set="fugue", slug="cross-circle",
path="fugue/cross-circle.png")
image.put()
self.status = Status(name="Foo", slug="foo", description="bar",
image="cross-circle")
self.status.put()
示例14: test_add
def test_add(self):
from models import Image
Image.add(name="Hallo.img")
img = Image.by_id(1)
self.assertEqual(1, img.id)
self.assertEqual("Hallo.img", img.name)
self.assertEqual("hallo.img", img.route)
示例15: gallery
def gallery(id=None):
# Get gallery images associated with feed #id
if id is None:
images = Image.select()
else:
images = Image.select().where(Feed.id == id).paginate(1, 50)
return render_template("gallery.html",
images=images)