2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

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 # 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 # Web URL endpoint for served media files
MEDIA_URL = '/media/' MEDIA_URL = '/media/'

View File

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