Remove os usage in common (#3459)

* make sure STATIC_COLOR_THEMES_DIR resolves

* remove usage of os module for file operations
This commit is contained in:
Matthias Mair 2022-08-02 08:48:48 +02:00 committed by GitHub
parent ce8448467a
commit 9ca0d6b0a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 5 deletions

View File

@ -127,7 +127,7 @@ STATFILES_I18_PROCESSORS = [
]
# Color Themes Directory
STATIC_COLOR_THEMES_DIR = STATIC_ROOT.joinpath('css', 'color-themes')
STATIC_COLOR_THEMES_DIR = STATIC_ROOT.joinpath('css', 'color-themes').resolve()
# Web URL endpoint for served media files
MEDIA_URL = '/media/'

View File

@ -10,7 +10,6 @@ import hmac
import json
import logging
import math
import os
import uuid
from datetime import datetime, timedelta
from enum import Enum
@ -1775,15 +1774,15 @@ class ColorTheme(models.Model):
@classmethod
def get_color_themes_choices(cls):
"""Get all color themes from static folder."""
if not os.path.exists(settings.STATIC_COLOR_THEMES_DIR):
if not settings.STATIC_COLOR_THEMES_DIR.exists():
logger.error('Theme directory does not exsist')
return []
# Get files list from css/color-themes/ folder
files_list = []
for file in os.listdir(settings.STATIC_COLOR_THEMES_DIR):
files_list.append(os.path.splitext(file))
for file in settings.STATIC_COLOR_THEMES_DIR.iterdir():
files_list.append(file.stem)
# Get color themes choices (CSS sheets)
choices = [(file_name.lower(), _(file_name.replace('-', ' ').title()))