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


Python Photo.query方法代码示例

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


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

示例1: get

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

        if album:
            upload_url = blobstore.create_upload_url('/album/%s/upload-photo' % album_id)

            photo_query = Photo.query(
                ancestor=album.key
            )

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

            template_values = {
                'user': user,
                'album': album,
                'photos': photo_query.fetch(None),
                'comments': comments_query.fetch(None),
                'upload_url': upload_url,
            }

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

示例2: get_covered_albums

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import query [as 别名]
def get_covered_albums(query, fetch=None):
    albums = query.fetch(fetch)

    for album in albums:
        photos = Photo.query(
            ancestor=album.key
        ).order(-Photo.date_created).fetch(1)

        if photos:
            album.cover = photos[0].key
        else:
            album.cover = None

    return albums
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:16,代码来源:views.py

示例3: post

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

        if album.author == get_user().key:
            photos_query = Photo.query(
                ancestor=album.key
            )

            photos = photos_query.fetch(None)
            for photo in photos:
                delete_photo(photo)

            album.key.delete()

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

示例4: post

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import query [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.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。