diff --git a/app/contexts/settings.py b/app/contexts/settings.py index 5101c726..c81941af 100644 --- a/app/contexts/settings.py +++ b/app/contexts/settings.py @@ -7,77 +7,3 @@ logger = logging.getLogger('app.logger') # Make the SETTINGS object available to all templates def load(request=None): return {'SETTINGS': Setting.objects.first()} - -# Helper functions for libsass - -def theme(color): - """Return a theme color from the currently selected theme""" - try: - return getattr(load()['SETTINGS'].theme, color) - except Exception as e: - logger.warning("Cannot load configuration from theme(): " + e.message) - return "blue" # dah buh dih ah buh daa.. - - -def complementary(hexcolor): - """Returns complementary RGB color - Example: complementaryColor('#FFFFFF') --> '#000000' - """ - if hexcolor[0] == '#': - hexcolor = hexcolor[1:] - rgb = (hexcolor[0:2], hexcolor[2:4], hexcolor[4:6]) - comp = ['%02X' % (255 - int(a, 16)) for a in rgb] - return '#' + ''.join(comp) - - -def scaleby(hexcolor, scalefactor, ignore_value = False): - """ - Scales a hex string by ``scalefactor``, but is color dependent, unless ignore_value is True - scalefactor is now always between 0 and 1. A value of 0.8 - will cause bright colors to become darker and - dark colors to become brigther by 20% - """ - - def calculate(hexcolor, scalefactor): - """ - Scales a hex string by ``scalefactor``. Returns scaled hex string. - To darken the color, use a float value between 0 and 1. - To brighten the color, use a float value greater than 1. - - >>> colorscale("#DF3C3C", .5) - #6F1E1E - >>> colorscale("#52D24F", 1.6) - #83FF7E - >>> colorscale("#4F75D2", 1) - #4F75D2 - """ - - def clamp(val, minimum=0, maximum=255): - if val < minimum: - return minimum - if val > maximum: - return maximum - return int(val) - - hexcolor = hexcolor.strip('#') - - if scalefactor < 0 or len(hexcolor) != 6: - return hexcolor - - r, g, b = int(hexcolor[:2], 16), int(hexcolor[2:4], 16), int(hexcolor[4:], 16) - - r = clamp(r * scalefactor) - g = clamp(g * scalefactor) - b = clamp(b * scalefactor) - - return "#%02x%02x%02x" % (r, g, b) - - - hexcolor = hexcolor.strip('#') - scalefactor = abs(float(scalefactor.value)) - scalefactor = min(1.0, max(0, scalefactor)) - - r, g, b = int(hexcolor[:2], 16), int(hexcolor[2:4], 16), int(hexcolor[4:], 16) - value = max(r, g, b) - - return calculate(hexcolor, scalefactor if ignore_value or value >= 127 else 2 - scalefactor) diff --git a/app/models/theme.py b/app/models/theme.py index 232dc42b..28aa7367 100644 --- a/app/models/theme.py +++ b/app/models/theme.py @@ -7,6 +7,8 @@ from django.db import models from colorfield.fields import ColorField from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ +from django.core.cache import cache +from django.core.cache.utils import make_template_fragment_key from webodm import settings @@ -54,14 +56,5 @@ def theme_post_save(sender, instance, created, **kwargs): def update_theme_css(): - """ - Touch theme.scss to invalidate its cache and force - compressor to regenerate it - """ - - theme_file = os.path.join('app', 'static', 'app', 'css', 'theme.scss') - try: - Path(theme_file).touch() - logger.info("Regenerate cache for {}".format(theme_file)) - except: - logger.warning("Failed to touch {}".format(theme_file)) \ No newline at end of file + key = make_template_fragment_key("theme_css") + cache.delete(key) \ No newline at end of file diff --git a/app/templates/app/base.html b/app/templates/app/base.html index 8ed5296f..b8b9405a 100644 --- a/app/templates/app/base.html +++ b/app/templates/app/base.html @@ -1,7 +1,7 @@ - {% load i18n static settings compress plugins %} + {% load i18n cache static settings plugins %} '#000000' + """ + if hexcolor[0] == '#': + hexcolor = hexcolor[1:] + rgb = (hexcolor[0:2], hexcolor[2:4], hexcolor[4:6]) + comp = ['%02X' % (255 - int(a, 16)) for a in rgb] + return '#' + ''.join(comp) + +@register.simple_tag +def scaleby(hexcolor, scalefactor, ignore_value = False): + """ + Scales a hex string by ``scalefactor``, but is color dependent, unless ignore_value is True + scalefactor is now always between 0 and 1. A value of 0.8 + will cause bright colors to become darker and + dark colors to become brigther by 20% + """ + + def calculate(hexcolor, scalefactor): + """ + Scales a hex string by ``scalefactor``. Returns scaled hex string. + To darken the color, use a float value between 0 and 1. + To brighten the color, use a float value greater than 1. + + >>> colorscale("#DF3C3C", .5) + #6F1E1E + >>> colorscale("#52D24F", 1.6) + #83FF7E + >>> colorscale("#4F75D2", 1) + #4F75D2 + """ + + def clamp(val, minimum=0, maximum=255): + if val < minimum: + return minimum + if val > maximum: + return maximum + return int(val) + + hexcolor = hexcolor.strip('#') + + if scalefactor < 0 or len(hexcolor) != 6: + return hexcolor + + r, g, b = int(hexcolor[:2], 16), int(hexcolor[2:4], 16), int(hexcolor[4:], 16) + + r = clamp(r * scalefactor) + g = clamp(g * scalefactor) + b = clamp(b * scalefactor) + + return "#%02x%02x%02x" % (r, g, b) + + + hexcolor = hexcolor.strip('#') + scalefactor = abs(float(scalefactor)) + scalefactor = min(1.0, max(0, scalefactor)) + + r, g, b = int(hexcolor[:2], 16), int(hexcolor[2:4], 16), int(hexcolor[4:], 16) + value = max(r, g, b) + + return calculate(hexcolor, scalefactor if ignore_value or value >= 127 else 2 - scalefactor) + +@register.simple_tag +def scalebyiv(hexcolor, scalefactor): + return scaleby(hexcolor, scalefactor, True) \ No newline at end of file diff --git a/package.json b/package.json index 042ae9df..083eac4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "WebODM", - "version": "2.4.0", + "version": "2.4.1", "description": "User-friendly, extendable application and API for processing aerial imagery.", "main": "index.js", "scripts": { diff --git a/requirements.txt b/requirements.txt index d132caeb..6c927890 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ Django==2.2.27 django-appconf==1.0.2 django-codemirror2==0.2 django-colorfield==0.1.15 -django-compressor==2.2 django-cors-headers==3.0.2 django-filter==2.4.0 django-guardian==1.4.9 diff --git a/webodm/settings.py b/webodm/settings.py index 18fb2f09..8c8e0dcc 100644 --- a/webodm/settings.py +++ b/webodm/settings.py @@ -114,7 +114,6 @@ INSTALLED_APPS = [ 'colorfield', 'imagekit', 'codemirror2', - 'compressor', 'app', 'nodeodm', ] @@ -199,7 +198,6 @@ STATICFILES_DIRS = [ STATICFILES_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', - 'compressor.finders.CompressorFinder', ] # File Uploads @@ -334,41 +332,6 @@ JWT_AUTH = { 'JWT_EXPIRATION_DELTA': datetime.timedelta(hours=6), } -# Compressor -COMPRESS_PRECOMPILERS = ( - ('text/x-scss', 'django_libsass.SassCompiler'), -) -COMPRESS_ENABLED = True -COMPRESS_MTIME_DELAY = 0 - -# Sass -def theme(color): - from app.contexts.settings import theme as f - return f(color) - - -def complementary(color): - from app.contexts.settings import complementary as f - return f(color) - - -def scaleby(color, n): - from app.contexts.settings import scaleby as f - return f(color, n) - - -def scalebyiv(color, n): - from app.contexts.settings import scaleby as f - return f(color, n, True) - - -LIBSASS_CUSTOM_FUNCTIONS = { - 'theme': theme, - 'complementary': complementary, - 'scaleby': scaleby, - 'scalebyiv': scalebyiv -} - # Celery CELERY_BROKER_URL = os.environ.get('WO_BROKER', 'redis://localhost') CELERY_RESULT_BACKEND = os.environ.get('WO_BROKER', 'redis://localhost') @@ -389,6 +352,12 @@ CACHES = { } } } +if DEBUG: + CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.dummy.DummyCache', + } + } # Number of minutes a processing node hasn't been seen # before it should be considered offline