本文整理汇总了Python中models.Photo.description方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.description方法的具体用法?Python Photo.description怎么用?Python Photo.description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Photo
的用法示例。
在下文中一共展示了Photo.description方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: savePhoto
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import description [as 别名]
def savePhoto(self, galleryId, photoId, photoName, photoDescription, photoPosition, file):
photo = None
if(photoId):
photo = Photo.objects.get(id=photoId)
else:
gid = uuid.uuid1().__str__()
gid = gid.replace('-', '')
photo = Photo()
photo.id = gid
photo.name = photoName
photo.description = photoDescription
photo.position = photoPosition
photo.gallery_id = galleryId
if(file):
photoType = file.name.split('.')
photo.type = photoType[1] if photoType.__len__() == 2 else ''
destination = open(constant.upload_path + galleryId + '/' +
photo.id + '.' + photo.type, 'wb')
try:
for chunk in file.chunks():
destination.write(chunk)
finally:
destination.close()
photo.save()
示例2: load_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import description [as 别名]
def load_photo(request):
if request.method=='POST':
if request.FILES is None:
return HttpResponseBadRequest('No file[] found')
try:
id = int(request.POST['id'])
tournament = Tournament.objects.get(pk=id)
if tournament is None:
return HttpResponseBadRequest('Cannot find corresponding dress')
except:
return HttpResponseBadRequest('Cannot find id')
file = request.FILES[u'files[]']
if str(file).lower()[-4:] not in ['.jpg', 'jpeg', '.gif', '.png', '.bmp', '.ico',]:
return HttpResponseBadRequest('Only images allowed')
wrapped_file = UploadedFile(file)
filename = wrapped_file.name
file_size = wrapped_file.file.size
photo = Photo()
photo.tournament = tournament
photo.description = filename
photo.image = file
photo.save()
try:
im = get_thumbnail(photo.image, "200", quality=50)
thumb_url = im.url
except Exception, ex:
photo.delete()
return HttpResponseBadRequest('Cannot read thumbnail')
result = [{"name": filename,
"id": photo.id,
"size": file_size,
"url": photo.image.url,
"thumbnail_url": thumb_url,
}]
response_data = simplejson.dumps(result)
mimetype = 'text/plain'
if 'HTTP_ACCEPT_ENCODING' in request.META.keys():
if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
mimetype = 'application/json'
return HttpResponse(response_data, mimetype=mimetype)
示例3: post
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import description [as 别名]
def post(self, id=None):
if id:
photo = Photo.gql("WHERE id = :1", id).get()
else:
photo = Photo(content_type="image/jpg")
date_posted = utils.strptime_for_edit(self.request.get('date_posted'))
photo.title = self.request.get('title')
photo.id = get_photo_id(date_posted, self.request.get('slug'))
photo.location = self.request.get('location')
location_slug = utils.slug(photo.location)
location = db.Query(PhotoLocation).filter("id = ", location_slug).get()
if not location:
location = PhotoLocation(id=location_slug, name=photo.location)
location.put()
photo.location_ref = location
photo.categories = self.request.get('categories')
photo.categories_ref = []
for category_name in photo.categories.split(","):
category_name = category_name.strip()
category_slug = utils.slug(category_name)
category = db.Query(PhotoCategory).filter("id = ", category_slug).get()
if not category:
category = PhotoCategory(id=category_slug, name=category_name)
category.put()
photo.categories_ref.append(category.key())
photo.description = self.request.get('description')
photo.date_posted = date_posted
if self.request.get('file'):
photo.file = db.Blob(self.request.get('file'))
photo.thumbnail = images.resize(photo.file, 128, 128)
photo.put()
self.redirect(photo.get_url())