Skip to content

Commit cdd2eac

Browse files
committed
Creme staticfiles
1 parent 26cc042 commit cdd2eac

File tree

100 files changed

+1639
-19028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1639
-19028
lines changed

.circleci/circleci_settings.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@
2121
'creme.mobile',
2222
])
2323

24-
GENERATED_MEDIA_NAMES_FILE = BASE_DIR / '_generated_media_names.py'
25-
# NB: "creme_project" same name in config.yml
26-
GENERATED_MEDIA_NAMES_MODULE = 'creme_project._generated_media_names'
27-
28-
MEDIA_ROOT = BASE_DIR / 'media' / 'upload'
2924
STATIC_ROOT = BASE_DIR / 'media' / 'static'
30-
25+
MEDIA_ROOT = BASE_DIR / 'media' / 'upload'
3126
# JOBMANAGER_BROKER = 'redis://@localhost:6379/0'
3227

3328
GEOLOCATION_TOWNS = [

.circleci/config.yml

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ commands:
9797
description: Setup Creme static resources
9898
steps:
9999
- run: creme generatemedia --settings=<< pipeline.parameters.instance_directory >>.settings
100+
- run: creme collectstatic --settings=<< pipeline.parameters.instance_directory >>.settings --no-input
100101

101102
setup-creme-unit-tests:
102103
description: Setup Creme database
@@ -109,6 +110,7 @@ commands:
109110
- run: creme migrate --settings=<< pipeline.parameters.instance_directory >>.settings
110111
- run: creme creme_populate --settings=<< pipeline.parameters.instance_directory >>.settings
111112
- run: creme generatemedia --settings=<< pipeline.parameters.instance_directory >>.settings
113+
- run: creme collectstatic --settings=<< pipeline.parameters.instance_directory >>.settings --no-input
112114

113115
run-creme-unit-tests:
114116
description: Run Creme unit tests

.dockerignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
__pycache__/
2-
*.py[cod]
1+
**/__pycache__/
2+
**/*.py[cod]
33

44
.git/
55
.githooks/
@@ -11,7 +11,6 @@ __pycache__/
1111
# creme/media/upload/*/*
1212
# creme/media/static/*
1313
# creme/local_settings.py
14-
# creme/_generated_media_names.py
1514
# *.sqlite
1615
# *.db
1716

.eslintignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
**/*.min.js
12
**/js/jquery/1.11/*
23
**/js/jquery/1.12/*
34
**/js/jquery/2.x/*
@@ -16,7 +17,7 @@
1617
**/js/jquery/ui/*
1718
**/js/lib/underscore/*
1819
**/js/lib/momentjs/*
19-
**/js/lib/leaflet*.js
20+
**/js/lib/leaflet/*
2021
**/js/lib/editor/*
2122
**/js/lib/Sortable/*
2223
**/js/lib/Select2/*
@@ -28,4 +29,4 @@
2829
**/sketch/js/lib/filesaver-*.js
2930
!**/sketch/js/lib/d3-radial-axis.js
3031
**/tiny_mce/**
31-
**/media/static/**
32+
**/media/static/**

Dockerfile

+12-8
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,23 @@ USER creme_user
3030
COPY docker/docker_settings.py /srv/creme/docker_settings.py
3131
ENV DJANGO_SETTINGS_MODULE docker_settings
3232

33+
COPY --chown=creme_user:creme_user . /srv/creme/src
3334

34-
RUN --mount=type=bind,source=.,target=/tmp/src \
35-
--mount=type=cache,target=/srv/creme/.cache,uid=1001 \
36-
set -eux; \
35+
RUN set -eux; \
3736
mkdir -p /srv/creme/logs; \
38-
mkdir -p /srv/creme/data; \
39-
cp -r /tmp/src /srv/creme/src; \
37+
mkdir -p /srv/creme/data;
38+
39+
RUN --mount=type=cache,target=/srv/creme/.cache,uid=1001 \
40+
set -eux; \
4041
python3 -m venv /srv/creme/venv; \
4142
/srv/creme/venv/bin/pip install --cache-dir=/srv/creme/.cache/pip --upgrade pip setuptools wheel; \
4243
/srv/creme/venv/bin/pip install --cache-dir=/srv/creme/.cache/pip /srv/creme/src[mysql,pgsql]; \
43-
/srv/creme/venv/bin/pip install --cache-dir=/srv/creme/.cache/pip --upgrade uWSGI supervisor; \
44-
rm -rf /srv/creme/src; \
45-
/srv/creme/venv/bin/creme generatemedia;
44+
/srv/creme/venv/bin/pip install --cache-dir=/srv/creme/.cache/pip --upgrade uWSGI supervisor;
45+
46+
RUN set -eux; \
47+
/srv/creme/venv/bin/creme generatemedia; \
48+
/srv/creme/venv/bin/creme collectstatic; \
49+
rm -rf /srv/creme/src;
4650

4751
ENV PATH /srv/creme:/srv/creme/venv/bin:$PATH
4852

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ ifeq (${DJANGO_SETTINGS_MODULE},)
6666
endif
6767
$(eval CREME_MEDIA ?= $(shell creme print_settings --settings=${DJANGO_SETTINGS_MODULE} --skip-checks --no-color STATIC_ROOT --format value))
6868
creme generatemedia --settings=${DJANGO_SETTINGS_MODULE}
69+
creme collectstatic --noinput
6970

7071

7172
## Run the Django test suite

creme/billing/templates/billing/bricks/exporters.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends 'creme_core/bricks/base/table.html' %}
2-
{% load i18n media creme_bricks %}
2+
{% load i18n static creme_bricks %}
33
{% load url from creme_core_tags %}
44

55
{% block brick_extra_class %}{{block.super}} billing-exporters-brick{% endblock %}
@@ -24,8 +24,8 @@
2424
<span class="billing-exporter-name">{{exporter.verbose_name}}</span>
2525
<div class="billing-exporter-screenshots">
2626
{% for img_src in exporter.screenshots %}
27-
<a onclick="creme.dialogs.image('{% media_url img_src %}').open();">
28-
<img style="max-width:200px;max-height:200px;" src="{% media_url img_src %}"/>
27+
<a onclick="creme.dialogs.image('{% static img_src %}').open();">
28+
<img style="max-width:200px;max-height:200px;" src="{% static img_src %}"/>
2929
</a>
3030
{% endfor %}
3131
</div>

creme/billing/templates/billing/forms/widgets/exporter-option.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
{% load media %}
1+
{% load static %}
22
{% if widget.wrap_label %}<label{% if widget.attrs.id %} for="{{widget.attrs.id}}"{% endif %}>{% endif %}
33
{% include 'django/forms/widgets/input.html' %}
44
{% if widget.wrap_label %}
55
<div class="billing-exporter-choice">
66
<div class="billing-exporter-choice-images">
77
{% for img_src in widget.value.images %}
8-
<a onclick="creme.dialogs.image('{% media_url img_src %}').open();">
9-
<img style="max-width:{{widget.thumbnail_width}};max-height:{{widget.thumbnail_height}};" src="{% media_url img_src %}"/>
8+
<a onclick="creme.dialogs.image('{% static img_src %}').open();">
9+
<img style="max-width:{{widget.thumbnail_width}};max-height:{{widget.thumbnail_height}};" src="{% static img_src %}"/>
1010
</a>
1111
{% endfor %}
1212
</div>

creme/creme_core/apps.py

-50
Original file line numberDiff line numberDiff line change
@@ -93,56 +93,6 @@ def __get_extending_app_configs(self):
9393

9494
# Hooking of AppConfig [end] ------------
9595

96-
# TODO: remove when MediaGenerator is not used
97-
class MediaGeneratorConfig(AppConfig):
98-
name = 'mediagenerator'
99-
verbose_name = 'Media generator' # _('Media generator')
100-
101-
def ready(self):
102-
self._build_MEDIA_BUNDLES()
103-
104-
def _build_MEDIA_BUNDLES(self):
105-
is_installed = apps.is_installed
106-
107-
MEDIA_BUNDLES = [
108-
settings.CREME_I18N_JS,
109-
[
110-
*settings.CREME_LIB_JS,
111-
*(js for app, js in settings.CREME_OPTLIB_JS if is_installed(app)),
112-
],
113-
[
114-
*settings.CREME_CORE_JS,
115-
*(js for app, js in settings.CREME_OPT_JS if is_installed(app)),
116-
],
117-
]
118-
119-
if settings.FORCE_JS_TESTVIEW:
120-
MEDIA_BUNDLES.append(settings.TEST_CREME_LIB_JS)
121-
MEDIA_BUNDLES.append([
122-
*settings.TEST_CREME_CORE_JS,
123-
*(js for app, js in settings.TEST_CREME_OPT_JS if is_installed(app)),
124-
])
125-
126-
MEDIA_BUNDLES += settings.CREME_OPT_MEDIA_BUNDLES
127-
128-
CREME_CSS = [
129-
*settings.CREME_CORE_CSS,
130-
*(css for app, css in settings.CREME_OPT_CSS if is_installed(app)),
131-
]
132-
MEDIA_BUNDLES.extend(
133-
[
134-
theme_dir + CREME_CSS[0],
135-
*(
136-
css_file if isinstance(css_file, dict) else f'{theme_dir}/{css_file}'
137-
for css_file in CREME_CSS[1:]
138-
),
139-
] for theme_dir, theme_vb_name in settings.THEMES
140-
)
141-
142-
settings.CREME_CSS = CREME_CSS # For compatibility (should not be useful)
143-
settings.MEDIA_BUNDLES = MEDIA_BUNDLES
144-
145-
14696
class ContentTypesConfig(VanillaContentTypesConfig):
14797
def ready(self):
14898
super().ready()

creme/creme_core/conf/project_template/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ syntax: glob
77
*/media/static/*
88

99
*/local_settings.py
10-
*/_generated_media_names.py
1110
*.sqlite3
1211

1312
# Python package

creme/creme_core/conf/project_template/project_name/settings.py-tpl

-11
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ TIME_ZONE = 'Europe/London'
4444
# For example:
4545
# INSTALLED_APPS.remove('creme.tickets')
4646

47-
# Path to the python file generated by the command 'generatemedia' which
48-
# contains the names of the final assets (with MD5 hashing).
49-
# The folder containing the generated file must be WRITABLE.
50-
# You can leave it commented if you have ONLY ONE creme project in the
51-
# current virtualenv (in this case the path of the file will look like
52-
# '/path_to_virtualenv/bin/_generated_media_names.py', which is generally OK).
53-
GENERATED_MEDIA_NAMES_FILE = BASE_DIR / '_generated_media_names.py'
54-
55-
# Python module corresponding to GENERATED_MEDIA_NAMES_FILE
56-
GENERATED_MEDIA_NAMES_MODULE = '{{ project_name }}._generated_media_names'
57-
5847
# Absolute filesystem path to the directory that will hold user-uploaded files,
5948
# and files that are generated dynamically (CSV, PDF...).
6049
# Must be writable of course.

creme/creme_core/conf/project_template/setup.cfg-tpl

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ use_parentheses = True
5151
[flake8]
5252
exclude =
5353
*/migrations/*
54-
_generated_media_names.py
5554
max-line-length = 99
5655
ignore =
5756
# Multiple spaces before operator

creme/creme_core/gui/icons.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from django.db.models import Model
2525
from django.utils.html import format_html
2626

27+
from ..staticfiles import get_staticfile_url
2728
from ..utils.media import get_creme_media_url
2829

2930
if TYPE_CHECKING:
@@ -268,22 +269,22 @@ def get_icon_by_name(name: str,
268269

269270
def _get_image_url():
270271
try:
271-
return get_creme_media_url(theme, f'images/{name}_{size_px}.png')
272+
return get_staticfile_url(f'{theme}/images/{name}_{size_px}.png', verify=True)
272273
except KeyError:
273274
pass
274275

275276
try:
276-
return get_creme_media_url(theme, f'images/{name}.png')
277+
return get_staticfile_url(f'{theme}/images/{name}.png', verify=True)
277278
except KeyError:
278279
pass
279280

280281
try:
281-
return get_creme_media_url(theme, f'images/{name}_{size_px}.gif')
282+
return get_staticfile_url(f'{theme}/images/{name}_{size_px}.gif', verify=True)
282283
except KeyError:
283284
pass
284285

285286
try:
286-
return get_creme_media_url(theme, f'images/{name}.gif')
287+
return get_staticfile_url(f'{theme}/images/{name}.gif', verify=True)
287288
except KeyError:
288289
pass
289290

@@ -338,7 +339,7 @@ def get_4_model(self,
338339
path = path_fmt % {'size': size_px}
339340

340341
try:
341-
url = get_creme_media_url(theme, path)
342+
url = get_staticfile_url(f"{theme}/{path}", verify=True)
342343
except KeyError:
343344
logger.warning('Missing image: %s', path)
344345

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
3+
from django.apps import apps
4+
from django.conf import settings
5+
from django.contrib.staticfiles import finders
6+
from django.core.management.base import BaseCommand
7+
8+
from creme.creme_core.staticfiles import (
9+
I18NCatalog,
10+
JavaScriptBundle,
11+
StyleSheetBundle,
12+
)
13+
14+
15+
class Command(BaseCommand):
16+
help = 'Generate media files'
17+
18+
BUNDLERS = {
19+
"javascript": JavaScriptBundle,
20+
"stylesheet": StyleSheetBundle,
21+
}
22+
23+
def create_destination(self):
24+
os.makedirs(settings.CREME_STATICFILES_TMP_DIRECTORY, exist_ok=True)
25+
26+
def bundle_i18n(self):
27+
for language_code, _ in settings.LANGUAGES:
28+
catalog = I18NCatalog(language_code)
29+
catalog.save(destination=settings.CREME_STATICFILES_TMP_DIRECTORY)
30+
31+
def bundle_staticfiles(self):
32+
for bundle in settings.CREME_STATICFILES_BUNDLES:
33+
bundler_class = self.BUNDLERS[bundle["type"]]
34+
bundler = bundler_class(filename=bundle["filename"])
35+
for app_name, filepaths in bundle["files"].items():
36+
if apps.is_installed(app_name):
37+
for filepath in filepaths:
38+
bundler.add(filepath, finders.find(filepath))
39+
bundler.save(destination=settings.CREME_STATICFILES_TMP_DIRECTORY)
40+
41+
def handle(self, **options):
42+
self.create_destination()
43+
self.bundle_staticfiles()
44+
self.bundle_i18n()

creme/creme_core/static/chantilly/creme_core/css/creme-ui.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ ul.ui-creme-widget.is-readonly li {
179179
vertical-align: middle;
180180
}
181181

182-
.ui-creme-overlay.overlay-active[status="wait"] { background-image: url("chantilly/images/wait.gif"); }
182+
.ui-creme-overlay.overlay-active[status="wait"] { background-image: url("../../images/wait.gif"); }
183183

184184
/*----------------------------------*/
185185
.ui-dialog-scrollbackground {

creme/creme_core/static/chantilly/creme_core/css/creme.css

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ td p {
212212
/* Page header and top areas - end */
213213

214214
.wait {
215-
list-style-image : url(chantilly/images/wait.gif);
215+
list-style-image : url("../../images/wait.gif");
216216
}
217217

218218
.main-content {
@@ -282,7 +282,7 @@ td p {
282282
}
283283

284284
.successlist li {
285-
list-style-image: url(chantilly/images/ok_16.png);
285+
list-style-image: url(../../images/ok_16.png);
286286
padding-top: 3px;
287287
}
288288

@@ -297,7 +297,7 @@ td p {
297297
}
298298

299299
.infolist li {
300-
list-style-image: url(chantilly/images/info_16.png);
300+
list-style-image: url(../../images/info_16.png);
301301
padding-top: 3px;
302302
}
303303

@@ -466,7 +466,7 @@ a[data-action] details {
466466
font-weight: 600;
467467

468468
background-color: hsl(197, 24%, 27%);
469-
background-image: url(common/images/creme-pattern.png);
469+
background-image: url(../../../common/images/creme-pattern.png);
470470
background-position: left -30px;
471471
}
472472

creme/creme_core/static/chantilly/creme_core/css/popover.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
.popover.popover-picture .picture-wait {
247247
width: 50px;
248248
height: 50px;
249-
background-image: url("icecream/images/wait.gif");
249+
background-image: url("../../images/wait.gif");
250250
background-repeat: no-repeat;
251251
background-position: 50% 50%;
252252
}

creme/creme_core/static/creme_core/js/lib/underscore/underscore-1.13.2.js

-1
Original file line numberDiff line numberDiff line change
@@ -2039,4 +2039,3 @@
20392039
return _;
20402040

20412041
})));
2042-
//# sourceMappingURL=underscore-umd.js.map
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/* globals media_url */
22
/* eslint no-unused-vars: "off" */
3+
function static_url(url) {
4+
return window.STATIC_URL + url;
5+
};
6+
37
function creme_media_url(url) {
4-
return media_url((window.THEME_NAME || '') + "/" + url);
8+
return static_url((window.THEME_NAME || '') + "/" + url);
59
};

0 commit comments

Comments
 (0)