Skip to content
This repository has been archived by the owner on Jun 30, 2019. It is now read-only.

Commit

Permalink
Merge 94fc6e4 into d6ecbfb
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Dec 29, 2018
2 parents d6ecbfb + 94fc6e4 commit b133dfb
Show file tree
Hide file tree
Showing 10 changed files with 367 additions and 297 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 2.3a0 (WIP)
- Model 支持 `create_by_display` 工厂函数
- 给 BaseModel 添加 `__getattribute__` 方法
- 给 NBaseModel 和 XBaseModel 移除 `__getattribute__` 方法和
`_detail_fields` 类属性

## 2.2 (2018-12-28)
- 发一个 2.2 的正式版(经过测试,相对稳定)

Expand All @@ -25,7 +31,6 @@
## 2.2a0 (2018-11-06)
- 给 library 添加 `list_song_standby` 接口
- **BREAKING CHANGE**: 修改本地音乐 ID 计算方法

## 2.1 (2018-10-08)
- 修复 XUserModel 的问题
- 完善接口文档
Expand Down
29 changes: 29 additions & 0 deletions examples/model_display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import logging

from fuocore.netease.models import NSongModel

logging.basicConfig()
logger = logging.getLogger('fuocore')
logger.setLevel(logging.DEBUG)


def test_model_display():
song = NSongModel.create_by_display(
identifier=254548,
title='成全',
artists_name='刘若英')
assert song.album_name_display == ''
assert song.title_display == '成全'
print(song.url, song.title)
assert song.album_name_display != ''


def main():
test_model_display()


if __name__ == '__main__':
main()
22 changes: 6 additions & 16 deletions fuocore/local/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,15 @@ class Meta:
allow_get = True
provider = provider

def __getattribute__(self, name):
cls = type(self)
value = object.__getattribute__(self, name)
if name in cls._detail_fields and value is None:
logger.debug('Field %s value is None, get model detail first.' % name)
obj = cls.get(self.identifier)
for field in cls._detail_fields:
setattr(self, field, getattr(obj, field))
value = object.__getattribute__(self, name)
elif name in cls._detail_fields and not value:
logger.debug('Field %s value is not None, but is %s' % (name, value))
return value


class LSongModel(SongModel, LBaseModel):
class Meta:
fields = ('disc', 'genre', 'date', 'track', 'cover', 'desc')
fields_no_get = ('lyric', )

@classmethod
def get(cls, identifier):
return cls.meta.provider.library._songs.get(identifier)
return cls.meta.provider.library.get_song(identifier)

@classmethod
def list(cls, identifier_list):
Expand All @@ -50,15 +40,15 @@ class LAlbumModel(AlbumModel, LBaseModel):

@classmethod
def get(cls, identifier):
return cls.meta.provider.library._albums.get(identifier)
return cls.meta.provider.library.get_album(identifier)


class LArtistModel(ArtistModel, LBaseModel):
_detail_fields = ('songs',)

@classmethod
def get(cls, identifier):
return cls.meta.provider.library._artists.get(identifier)
return cls.meta.provider.library.get_artist(identifier)


class LSearchModel(SearchModel, LBaseModel):
Expand Down
Loading

0 comments on commit b133dfb

Please sign in to comment.