Skip to content

Commit

Permalink
bugfix:admin中更新应用信息后logo路径错误 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayuan929 committed Aug 31, 2022
1 parent 4113231 commit bf5f82e
Showing 1 changed file with 0 additions and 55 deletions.
55 changes: 0 additions & 55 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,61 +166,6 @@ def _del_exist_file(self, name):
if os.path.exists(_file):
os.remove(_file)

def save(self, *args, **kwargs):
"""
保存前修改 logo 存放路径
"""
if not self.logo:
return super(App, self).save(*args, **kwargs)
# 修改图片名称
logo_ext = ".png"
# 判断logo名称
if self.logo.name.find("\\") >= 0:
logo_name = APP_LOGO_IMG_RELATED + "\\" + str(self.code) + logo_ext
elif self.logo.name.find("/") >= 0:
logo_name = APP_LOGO_IMG_RELATED + "/" + str(self.code) + logo_ext
else:
logo_name = APP_LOGO_IMG_RELATED + "/" + str(self.code) + logo_ext
# 判断图片路径与旧图路径名称是否相同
if cmp(logo_name, self.logo.name):
logo_name = APP_LOGO_IMG_RELATED + "/" + str(self.code) + logo_ext
self._del_exist_file(logo_name)
# 指定图片名称
self.logo.name = APP_LOGO_IMG_RELATED + "/" + str(self.code) + logo_ext
# save操作
super(App, self).save(*args, **kwargs)

@property
def logo_url(self):
if self.logo:
return "%s?v=%s" % (self.logo.url, time.time())
else:
# 判断 以 app_code 命名的 logo 图片是否存在
logo_name = "%s/%s.png" % (APP_LOGO_IMG_RELATED, self.code)
logo_path = os.path.join(settings.MEDIA_ROOT, logo_name)
if os.path.exists(logo_path):
return "%s%s" % (settings.MEDIA_URL, logo_name)

# 判断是否是上传saas解压生成的文件, 存在的话使用之(saas内置应用上传包中带的logo)
logo_name = "%s/%s.png" % (SAAS_APP_LOGO_IMG_RELATED, self.code)
logo_path = os.path.join(settings.MEDIA_ROOT, logo_name)
if os.path.exists(logo_path):
return "%s%s" % (settings.MEDIA_URL, logo_name)

return "%simg/app_logo/default.png" % settings.STATIC_URL

@property
def get_logo_url(self):
if self.logo:
return "%s?v=%s" % (self.logo.url, time.time())
else:
# 判断 以 app_code 命名的 logo 图片是否存在
logo_name = "%s/%s.png" % (APP_LOGO_IMG_RELATED, self.code)
logo_path = os.path.join(settings.MEDIA_ROOT, logo_name)
if os.path.exists(logo_path):
return "%s%s" % (settings.MEDIA_URL, logo_name)
return "%simg/app_logo/default.png" % settings.STATIC_URL

def tag_name(self):
if self.tags and self.tags.name_display:
return self.tags.name_display
Expand Down

0 comments on commit bf5f82e

Please sign in to comment.