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


Python Photo.generate_photo_id方法代码示例

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


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

示例1: migrate_photo

# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import generate_photo_id [as 别名]
def migrate_photo(old_buckets, s3_bucket, photo):
    print "Migrating photo: " + str(photo)
    old_photo_bucket = find_photo_bucket(old_buckets, photo.photo_id)

    new_subdomain = choose_random_subdomain()
    new_storage_id = Photo.generate_photo_id()
    print "New subdomain: " + new_subdomain
    print "New storage_id: " + new_storage_id

    def upload(ext):
        filename = os.path.join(settings.LOCAL_PHOTO_BUCKETS_BASE_PATH, old_photo_bucket, photo.photo_id + ext)
        print "Uploading: " + filename

        key = Key(s3_bucket, new_storage_id + ext)
        key.metadata = {"Content-Type": "image/jpeg"}
        key.set_contents_from_filename(filename)
        key.close()

    upload(".jpg")
    for ext in all_photo_extensions:
        upload("_" + ext + ".jpg")

    photo.subdomain = new_subdomain
    photo.storage_id = new_storage_id
    photo.save(update_fields=["subdomain", "storage_id"])
开发者ID:shotvibe,项目名称:shotvibe-web,代码行数:27,代码来源:photos_s3_migration.py

示例2: add_youtube_photo

# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import generate_photo_id [as 别名]
def add_youtube_photo(client_upload_id, storage_id, author, album, now, youtube_id):
    def get_next_album_index(album):
        album_index_q = Photo.objects.filter(album=album).aggregate(Max("album_index"))

        max_album_index = album_index_q["album_index__max"]
        if max_album_index is None:
            return 0
        else:
            return max_album_index + 1

    success = False
    while not success:
        try:
            with transaction.atomic():
                next_album_index = get_next_album_index(album)
                p, created = Photo.objects.get_or_create(
                    storage_id=storage_id,
                    defaults={
                        "photo_id": Photo.generate_photo_id(),
                        "media_type": Photo.MEDIA_TYPE_YOUTUBE,
                        "client_upload_id": client_upload_id,
                        "subdomain": Photo.choose_random_subdomain(),
                        "date_created": now,
                        "author": author,
                        "album": album,
                        "album_index": next_album_index,
                        "youtube_id": youtube_id,
                    },
                )
        except IntegrityError:
            # This will happen if there is a collision with a duplicate
            # 'album_index' from a concurrent request
            success = False
        else:
            success = True
    if created:
        if not in_testing_mode():
            # Update the photo servers:
            for photo_server in PhotoServer.objects.filter(subdomain=p.subdomain, unreachable=False):
                # TODO We should use concurrent requests for this

                num_retries = 5
                initial_retry_time = 4

                try:
                    request_with_n_retries(
                        num_retries,
                        initial_retry_time,
                        lambda: photo_server_set_photos(photo_server.photos_update_url, photo_server.auth_key, [p]),
                    )
                except requests.exceptions.RequestException:
                    # TODO Log this
                    photo_server.set_unreachable()

        album.save_revision(now, True)

        photos_added_to_album.send(sender=None, photos=[p.photo_id], by_user=author, to_album=album)
开发者ID:shotvibe,项目名称:shotvibe-web,代码行数:59,代码来源:photo_operations.py


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