Sith/core/scss/finder.py

51 lines
1.5 KiB
Python
Raw Normal View History

2017-05-05 12:26:46 +00:00
#!/usr/bin/env python3
2023-04-06 11:08:42 +00:00
# -*- coding:utf-8 -*-
2017-05-05 12:26:46 +00:00
#
2023-04-06 11:08:42 +00:00
# Copyright 2023 © AE UTBM
# ae@utbm.fr / ae.info@utbm.fr
# All contributors are listed in the CONTRIBUTORS file.
2017-05-05 12:26:46 +00:00
#
2023-04-06 11:08:42 +00:00
# This file is part of the website of the UTBM Student Association (AE UTBM),
# https://ae.utbm.fr.
2017-05-05 12:26:46 +00:00
#
2023-04-06 11:08:42 +00:00
# You can find the whole source code at https://github.com/ae-utbm/sith3
2017-05-05 12:26:46 +00:00
#
2023-04-06 11:08:42 +00:00
# LICENSED UNDER THE GNU GENERAL PUBLIC LICENSE VERSION 3 (GPLv3)
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE
# OR WITHIN THE LOCAL FILE "LICENSE"
2017-05-05 12:26:46 +00:00
#
2023-04-06 11:08:42 +00:00
# PREVIOUSLY LICENSED UNDER THE MIT LICENSE,
# SEE : https://raw.githubusercontent.com/ae-utbm/sith3/master/LICENSE.old
# OR WITHIN THE LOCAL FILE "LICENSE.old"
2017-05-05 12:26:46 +00:00
#
import os
from collections import OrderedDict
2024-06-24 11:07:36 +00:00
2017-05-05 12:26:46 +00:00
from django.conf import settings
from django.contrib.staticfiles.finders import FileSystemFinder
from django.core.files.storage import FileSystemStorage
class ScssFinder(FileSystemFinder):
"""
Find static *.css files compiled on the fly
"""
2018-10-04 19:29:19 +00:00
2017-05-05 12:26:46 +00:00
locations = []
def __init__(self, apps=None, *args, **kwargs):
location = settings.STATIC_ROOT
if not os.path.isdir(location):
return
2018-10-04 19:29:19 +00:00
self.locations = [("", location)]
2017-05-05 12:26:46 +00:00
self.storages = OrderedDict()
filesystem_storage = FileSystemStorage(location=location)
filesystem_storage.prefix = self.locations[0][0]
self.storages[location] = filesystem_storage
def find(self, path, all=False):
2018-10-04 19:29:19 +00:00
if path.endswith(".css"):
2017-05-05 12:26:46 +00:00
return super(ScssFinder, self).find(path, all)
return []