当前位置: 首页>>代码示例>>Python>>正文


Python Photo.get_by_id方法代码示例

本文整理汇总了Python中models.Photo.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.get_by_id方法的具体用法?Python Photo.get_by_id怎么用?Python Photo.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Photo的用法示例。


在下文中一共展示了Photo.get_by_id方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_photo

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
def get_photo(photo_id):
    logger.debug('get photo id: %d' % photo_id)
    photo = Photo.get_by_id(photo_id)
    logger.debug('found photo name: %s' % photo.name)
    response = make_response(photo.thumbnail)
    response.headers['Content-Type'] = 'image/jpeg'
    return response
开发者ID:ashimali,项目名称:baltipic,代码行数:9,代码来源:main.py

示例2: render_photo

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
		def render_photo(self, id):
			photo = Photo.get_by_id(int(id))
			blobKey = photo.blobKey
		
			if blobKey:
				blobinfo = blobstore.get(blobKey)
				
				if blobinfo:
					aspect = 'h'
					img = images.Image(blob_key=blobKey)
					img.rotate(180)
					thumbnail = img.execute_transforms(output_encoding=images.JPEG)
					if img.width > img.height:
						pass
					else:
						aspect = 'v'
					img = images.Image(blob_key=blobKey)
					if aspect == 'h':
						img.resize(width=505)
					else:
						img.resize(width=355)
					thumbnail = img.execute_transforms(output_encoding=images.JPEG)
					return thumbnail
				return
			self.error(404)
开发者ID:paulcarvill,项目名称:caption-competition,代码行数:27,代码来源:main.py

示例3: get

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
    def get(self, album_id, photo_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )
        photo = Photo.get_by_id(
            int(photo_id),
            parent=album.key
        )

        image_url = '%s/album/%s/photo/%s' % (
            self.request.host_url,
            album.key.integer_id(),
            photo.key.integer_id()
        )

        comments_query = Comment.query(
            Comment.parent == photo.key
        ).order(-Comment.date_created)

        comments = comments_query.fetch(None)

        template_values = {
            'image_url': image_url,
            'photo': photo,
            'album': album,
            'comments': comments,
        }

        self.render_template('view_photo.html', template_values)
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:32,代码来源:views.py

示例4: delete_photo

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
def delete_photo(photo_id):
    logger.debug('delete photo id: %d' % photo_id)
    photo = Photo.get_by_id(photo_id)
    logger.debug('delete photo name: %s' % photo.name)
    db.delete(photo)
    response = make_response('OK', 200)
    return response
开发者ID:ashimali,项目名称:baltipic,代码行数:9,代码来源:main.py

示例5: get_file

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
def get_file(file_id):
    logger.debug('find file id: %d' % file_id)
    file = Photo.get_by_id(file_id)
    logger.debug(file.name)
    response = make_response(file.full_image)
    response.headers['Content-Disposition'] = "attachment; filename=%s" % file.name
    return response
开发者ID:ashimali,项目名称:baltipic,代码行数:9,代码来源:main.py

示例6: copy_image_to_lightbox

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
def copy_image_to_lightbox():
    lightboxId = int(request.json['lightboxId'])
    photoId = int(request.json['photoId'])
    logger.debug('copy image id %s lightbox id %s' % (photoId, lightboxId))
    #user = users.get_current_user()
    lightbox = Lightbox.get_by_id(lightboxId)
    original = Photo.get_by_id(photoId)
    copied = clone_entity(original, lightbox=lightbox)
    copied.put()
    return jsonify(lightbox={"id": lightbox.key().id(), "photos": [copied.key().id()]})
开发者ID:ashimali,项目名称:baltipic,代码行数:12,代码来源:main.py

示例7: get

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
    def get(self, album_id, photo_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )
        photo = Photo.get_by_id(
            int(photo_id),
            parent=album.key
        )

        # All possible options
        height = self.request.get('height')
        width = self.request.get('width')
        rotate = self.request.get('rotate')
        lucky = self.request.get('lucky')
        hflip = self.request.get('hflip')

        if height or width or rotate or hflip:
            try:
                img = images.Image(blob_key=photo.blob_info_key)

                height = None if not height else int(height)
                width = None if not width else int(width)
                rotate = None if not rotate else int(rotate)
                lucky = None if not lucky else bool(lucky)
                hflip = None if not hflip else bool(hflip)

                if width and height:
                    # Resizing always preserves aspect ratio
                    img.resize(height=height, width=width)
                elif width:
                    img.resize(width=width)
                elif height:
                    img.resize(height=height)

                if rotate:
                    img.rotate(rotate)

                if hflip:
                    img.horizontal_flip()

                if lucky:
                    img.im_feeling_lucky()

                img = img.execute_transforms(output_encoding=images.PNG)

                self.response.headers['Content-Type'] = 'image/png'
                self.response.write(img)
            except Exception as e:
                self.response.write('Unable to process request: %s' % e.message)
        else:
            self.send_blob(blobstore.BlobInfo.get(photo.blob_info_key))
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:54,代码来源:photos.py

示例8: get

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
 def get(self, type, id):
   photo = Photo.get_by_id(int(id))
   if photo:
     self.response.headers.add_header('Expires', 'Thu, 01 Dec 2014 16:00')
     self.response.headers['Cache-Control'] = 'public, max-age=366000'
     #self.response.headers['Content-type'] = self.get_content_type(photo.name)
     # TODO: tell image type by looking at its name or read the image file header
     self.response.headers['Content-type'] = 'image/png'
     if type == 'image':
       self.response.out.write(photo.image)
     elif type == "thumb":
       self.response.out.write(photo.thumb)
     else:
       self.error(500)
   else:
     self.error(404)
开发者ID:tchaikov,项目名称:beanfs,代码行数:18,代码来源:image.py

示例9: post

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
    def post(self, album_id, photo_id):
        album = Album.get_by_id(
            int(album_id),
            parent=DEFAULT_DOMAIN_KEY
        )
        photo = Photo.get_by_id(
            int(photo_id),
            parent=album.key
        )

        if photo.author == get_user().key:
            delete_photo(photo)

            self.redirect('/album/%s/view' % album_id)
        else:
            self.raise_error('500')
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:18,代码来源:views.py

示例10: post

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import get_by_id [as 别名]
    def post(self):
       user_id = self.request.get('user_id')
       event_id = self.request.get('event_id')
       event = Event.get_by_id(int(event_id))
       operation = self.request.get('operation')
       if (operation == "load"):
          if (user_id == event.userId):

             template_values = {
                 'event': event
             }

             template = JINJA_ENVIRONMENT.get_template('event_update.html')
             self.response.write(template.render(template_values))
          else:
             template = JINJA_ENVIRONMENT.get_template('index.html')
             self.response.write(template.render())
       elif (operation == "people_for_event"):
            user_id = self.request.get('user_id')
            event_id = int(self.request.get('event_id'))
            event = Event.get_by_id(event_id)

            event_people = []
            for person_id in event.event_people:
                person = Person.get_by_id(int(person_id))
                event_people.append({"person_id": person_id, "display_name": person.display_name,
                                   "image_url": person.image_url })
            event_people_set = set(event.event_people)

            person_keys = (Person.query(Person.userId == user_id).fetch(keys_only=True))
            all_people = []
            for key in person_keys:
                all_people.append(key.id())
            clean_people = [x for x in all_people if x not in event_people_set]
            all_people = []
            for person_id in clean_people:
                person = Person.get_by_id(int(person_id))
                all_people.append({"person_id": person_id, "display_name": person.display_name,
                                   "image_url": person.image_url })

            event_sharing_set = set(event.event_sharing)
            my_key = Person.query(Person.plus_id == user_id).get(keys_only=True)
            event_sharing_set.add(my_key.id())
            available_sharing = []
            for key in person_keys:
                available_sharing.append(key.id())
            clean_sharing = [x for x in available_sharing if x not in event_sharing_set]
            available_sharing = []
            for person_id in clean_sharing:
                person = Person.get_by_id(int(person_id))
                available_sharing.append({"person_id": person_id, "display_name": person.display_name,
                                           "image_url": person.image_url, "email": person.email })
            event_sharing = []
            for person_id in event.event_sharing:
                person = Person.get_by_id(int(person_id))
                event_sharing.append({"person_id": person_id, "display_name": person.display_name,
                                        "image_url": person.image_url, "email": person.email })

            ret_data = { "all_people": all_people, "event_people": event_people, 
                         "available_sharing": available_sharing, "event_sharing": event_sharing }

            self.response.write(json.dumps(ret_data))
       elif (operation == "photos_for_event"):
            user_id = self.request.get('user_id')
            event_id = self.request.get('event_id')
            event = Event.get_by_id(int(event_id))

            photo_keys = (Photo.query(Photo.userId == user_id).fetch(keys_only=True))
            event_photos_set = set(event.event_photos)

            event_photos = []
            for photo_id in event.event_photos:
                photo = Photo.get_by_id(int(photo_id))
                event_photos.append({"photo_id": photo_id, "drive_id": photo.drive_id, 
                                       "thumbnailLink": photo.thumbnailLink })

            all_photos = []
            for photo_key in photo_keys:
                all_photos.append(photo_key.id())
            clean_photos = [x for x in all_photos if x not in event_photos_set]

            all_photos = []
            for photo_id in clean_photos:
                photo = Photo.get_by_id(int(photo_id))
                all_photos.append({"photo_id": photo_id, "drive_id": photo.drive_id, 
                                     "thumbnailLink": photo.thumbnailLink })
            ret_data = { "all_photos": all_photos, "event_photos": event_photos }

            self.response.write(json.dumps(ret_data))
       elif (operation == "change_people"):
            person_id = int(self.request.get('person_id'))
            change_to = self.request.get('change_to')
            if (change_to == "connected"):
                event.event_people.append(person_id)
                event.put()
            else:
               if person_id in event.event_people:
                   event.event_people.remove(person_id)
                   event.put()
               else:
#.........这里部分代码省略.........
开发者ID:ripplesphere,项目名称:sample_code,代码行数:103,代码来源:event_update.py


注:本文中的models.Photo.get_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。