serialize.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:hearcloud 作者: hearcloud 项目源码 文件源码
def serialize_file(instance, file_attr='file', thumbnail_attr='artwork'):
    obj = getattr(instance, file_attr)
    thumbnail = getattr(instance, thumbnail_attr)
    if thumbnail:
        thumbnail_url = thumbnail.url
    else:
        thumbnail_url = static('box/images/NoArtwork_Black.png')
    return {
        'url': obj.url,
        'name': order_name(obj.name),
        'type': mimetypes.guess_type(obj.path)[0],
        'thumbnailUrl': thumbnail_url,
        'size': obj.size,
        'deleteUrl': reverse('box:song-delete', kwargs={'username': instance.user.username, 'slug': instance.slug}),
        'deleteType': 'DELETE',
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号