Skip to content

Commit 8902fb5

Browse files
authored
更新 context.py
1 parent b6aa013 commit 8902fb5

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

app/core/context.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,16 @@ def __directors_actors(tmdbinfo: dict) -> Tuple[List[dict], List[dict]]:
474474
self.names = info.get('names') or []
475475
# 剩余属性赋值
476476
for key, value in info.items():
477-
# 属性存在、值为空且类型一致则赋值
478-
if hasattr(self, key) and not getattr(self, key) and type(getattr(self, key)) == type(value):
477+
if not value:
478+
continue
479+
if not hasattr(self, key):
480+
continue
481+
current_value = getattr(self, key)
482+
if current_value:
483+
continue
484+
if current_value is None:
485+
setattr(self, key, value)
486+
elif type(current_value) == type(value):
479487
setattr(self, key, value)
480488

481489
def set_douban_info(self, info: dict):
@@ -607,8 +615,16 @@ def set_douban_info(self, info: dict):
607615
self.production_countries = [{"id": country, "name": country} for country in info.get("countries") or []]
608616
# 剩余属性赋值
609617
for key, value in info.items():
610-
# 属性存在、值为空且类型一致则赋值
611-
if hasattr(self, key) and not getattr(self, key) and type(getattr(self, key)) == type(value):
618+
if not value:
619+
continue
620+
if not hasattr(self, key):
621+
continue
622+
current_value = getattr(self, key)
623+
if current_value:
624+
continue
625+
if current_value is None:
626+
setattr(self, key, value)
627+
elif type(current_value) == type(value):
612628
setattr(self, key, value)
613629

614630
def set_bangumi_info(self, info: dict):

0 commit comments

Comments
 (0)