Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django pipeline POC #115

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ jobs:
- run: cp ~/project/.circleci/mysql_settings.py creme/local_settings.py
- run: python creme/manage.py migrate
- run: python creme/manage.py creme_populate
- run: python creme/manage.py generatemedia
- run: COVERAGE_PROCESS_START=setup.cfg coverage run --source creme/ creme/manage.py test --noinput --parallel=6
- run: coverage combine
- run: coverage html
Expand Down Expand Up @@ -146,7 +145,6 @@ jobs:
- run: cp ~/project/.circleci/pgsql_settings.py creme/local_settings.py
- run: python creme/manage.py migrate
- run: python creme/manage.py creme_populate
- run: python creme/manage.py generatemedia
- run: COVERAGE_PROCESS_START=setup.cfg coverage run --source creme/ creme/manage.py test --noinput --parallel=8
- run: coverage combine
- run: coverage html
Expand All @@ -169,7 +167,6 @@ jobs:
- run: cp ~/project/.circleci/sqlite3_settings.py creme/local_settings.py
- run: python creme/manage.py migrate
- run: python creme/manage.py creme_populate
- run: python creme/manage.py generatemedia
- run: COVERAGE_PROCESS_START=setup.cfg coverage run --source creme/ creme/manage.py test --noinput --parallel=8
- run: coverage combine
- run: coverage html
Expand Down Expand Up @@ -197,7 +194,6 @@ jobs:
- install-creme-system-packages
- install-py-dev-env
- run: cp ~/project/.circleci/circleci_settings.py creme/project_settings.py
- run: python creme/manage.py generatemedia
- install-node-env
- run:
name: Run javascript tests
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ django.wsgi

creme/media/upload/*/*
creme/media/static/*
_generated_media_names.py
creme/collected_statics/*
*.sqlite
*.db

Expand Down
18 changes: 6 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,11 @@ update-requirements:
pip install --upgrade -e .[dev]


## Upgrade the Python requirements, run the migrations, the creme_populate and generatemedia commands
## Upgrade the Python requirements, run the migrations and the creme_populate command
.PHONY: update
update: update-requirements
python creme/manage.py migrate
python creme/manage.py creme_populate
python creme/manage.py generatemedia


## Generate the media files
.PHONY: media
media:
python creme/manage.py generatemedia


## Run the Django test suite
Expand Down Expand Up @@ -74,11 +67,11 @@ karma-clean:

## Run the Javascript test suite
.PHONY: karma
karma: media karma-clean
karma: karma-clean
node_modules/.bin/karma start .karma.conf.js --browsers=FirefoxHeadless --targets=$(filter-out $@,$(MAKECMDGOALS))
@echo "file://$(shell pwd)/artifacts/karma_coverage/html/index.html"

karma-browsers: media karma-clean
karma-browsers: karma-clean
CHROME_BIN=/usr/bin/google-chrome \
node_modules/.bin/karma start .karma.conf.js \
--browsers=FirefoxHeadless,ChromiumHeadless,ChromeHeadless \
Expand All @@ -87,15 +80,15 @@ karma-browsers: media karma-clean

@echo "file://$(shell pwd)/artifacts/karma_coverage/html/index.html"

## Run the Javascript test suite in CI (generatemedia is supposed to be already done)
## Run the Javascript test suite in CI
.PHONY: karma-ci
karma-ci:
node_modules/.bin/karma start .circleci/.karma.conf.js --targets=$(filter-out $@,$(MAKECMDGOALS))


## Run the application
.PHONY: serve
serve: media
serve:
python creme/manage.py runserver


Expand Down Expand Up @@ -251,6 +244,7 @@ gettext-collect:
.PHONY: gettext-compile
gettext-compile:
django-admin.py compilemessages -l ${CREME_LANGUAGE}
python creme/manage.py i18n_javascript_catalog


## Print this message
Expand Down
1 change: 0 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ For an upgrade from Creme 1.8 :
Filling the DB tables:
Run the following commands in the root directory:
>> python creme/manage.py migrate
>> python creme/manage.py generatemedia
>> python creme/manage.py creme_populate

If you are upgrading from Creme 2.0, clean all existing sessions, for example like this:
Expand Down
6 changes: 3 additions & 3 deletions creme/billing/templates/billing/bricks/exporters.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends 'creme_core/bricks/base/table.html' %}
{% load i18n media creme_bricks %}
{% load i18n static creme_bricks %}

{% block brick_extra_class %}{{block.super}} billing-exporters-brick{% endblock %}

Expand Down Expand Up @@ -27,8 +27,8 @@
<span class="billing-exporter-name">{{exporter.verbose_name}}</span>
<div class="billing-exporter-screenshots">
{% for img_src in exporter.screenshots %}
<a onclick="creme.dialogs.image('{% media_url img_src %}').open();">
<img style="max-width:200px;max-height:200px;" src="{% media_url img_src %}"/>
<a onclick="creme.dialogs.image('{% static img_src %}').open();">
<img style="max-width:200px;max-height:200px;" src="{% static img_src %}"/>
</a>
{% endfor %}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% load media %}
{% load static %}
{% if widget.wrap_label %}<label{% if widget.attrs.id %} for="{{widget.attrs.id}}"{% endif %}>{% endif %}
{% include 'django/forms/widgets/input.html' %}
{% if widget.wrap_label %}
<div class="billing-exporter-choice">
<div class="billing-exporter-choice-images">
{% for img_src in widget.value.images %}
<a onclick="creme.dialogs.image('{% media_url img_src %}').open();">
<img style="max-width:{{widget.thumbnail_width}};max-height:{{widget.thumbnail_height}};" src="{% media_url img_src %}"/>
<a onclick="creme.dialogs.image('{% static img_src %}').open();">
<img style="max-width:{{widget.thumbnail_width}};max-height:{{widget.thumbnail_height}};" src="{% static img_src %}"/>
</a>
{% endfor %}
</div>
Expand Down
52 changes: 0 additions & 52 deletions creme/creme_core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,58 +88,6 @@ def __get_extending_app_configs(self):
AppConfig.get_extending_app_configs = __get_extending_app_configs


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

# TODO: remove when MediaGenerator is not used
class MediaGeneratorConfig(AppConfig):
name = 'mediagenerator'
verbose_name = 'Media generator' # _('Media generator')

def ready(self):
self._build_MEDIA_BUNDLES()
# self._fix_i18n_filter()

def _build_MEDIA_BUNDLES(self):
is_installed = apps.is_installed

MEDIA_BUNDLES = [
settings.CREME_I18N_JS,
[*settings.CREME_LIB_JS,
*(js for app, js in settings.CREME_OPTLIB_JS if is_installed(app)),
],
[*settings.CREME_CORE_JS,
*(js for app, js in settings.CREME_OPT_JS if is_installed(app)),
],
]

if settings.FORCE_JS_TESTVIEW:
MEDIA_BUNDLES.append(settings.TEST_CREME_LIB_JS)
MEDIA_BUNDLES.append(
[*settings.TEST_CREME_CORE_JS,
*(js for app, js in settings.TEST_CREME_OPT_JS if is_installed(app)),
]
)

MEDIA_BUNDLES += settings.CREME_OPT_MEDIA_BUNDLES

CREME_CSS = [
*settings.CREME_CORE_CSS,
*(css for app, css in settings.CREME_OPT_CSS if is_installed(app)),
]
MEDIA_BUNDLES.extend(
[
theme_dir + CREME_CSS[0],
*(
css_file if isinstance(css_file, dict) else f'{theme_dir}/{css_file}'
for css_file in CREME_CSS[1:]
),
] for theme_dir, theme_vb_name in settings.THEMES
)

settings.CREME_CSS = CREME_CSS # For compatibility (should not be useful)
settings.MEDIA_BUNDLES = MEDIA_BUNDLES


class ContentTypesConfig(VanillaContentTypesConfig):
def ready(self):
super().ready()
Expand Down
4 changes: 2 additions & 2 deletions creme/creme_core/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from django.contrib.contenttypes.models import ContentType
from django.db.models.query_utils import Q
from django.forms import widgets
from django.templatetags.static import static
from django.urls import reverse
from django.utils.translation import gettext as _
from django.utils.translation import gettext_lazy, pgettext, pgettext_lazy
Expand Down Expand Up @@ -968,8 +969,7 @@ def get_context(self, name, value, attrs):
final_attrs['plugin'] = 'tinymce'
final_attrs['plugin_options'] = json_dump({
'mode': 'textareas',
# 'script_url': f'{settings.MEDIA_URL}tiny_mce/tiny_mce.js',
'script_url': '/tiny_mce/tiny_mce.js', # See root urls.py
'script_url': static('/tiny_mce/tiny_mce.js'),
'convert_urls': False,
'theme': 'advanced',
'height': 300,
Expand Down
77 changes: 77 additions & 0 deletions creme/creme_core/management/commands/i18n_javascript_catalog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-

################################################################################
#
# Copyright (c) 2018-2020 Hybird
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################

import os

from django.apps import apps
from django.conf import settings
from django.core.management.base import BaseCommand, no_translations
from django.http import HttpRequest
from django.utils import translation
from django.views.i18n import JavaScriptCatalog


class Command(BaseCommand):
help = 'Build a static javascript translation catalog'

def handle_language(self, language_code):
with translation.override(language=language_code):
self.stdout.write(f"Building javascript catalog for language {language_code}...")

language_bidi = language_code.split('-')[0] in settings.LANGUAGES_BIDI

# Hybird FIX - Django1.10 version
# request = HttpRequest()
# request.GET['language'] = language

# Add a header and some JavaScript data
content = (
"// This file was auto-generated by the creme_core "
"i18n_javascript_catalog django command.\n\n"
f"var LANGUAGE_CODE = \"{language_code}\";\n"
f"var LANGUAGE_BIDI = {'true' if language_bidi else 'false'};\n"
)

packages = [app_config.name for app_config in apps.app_configs.values()]
catalog_view = JavaScriptCatalog(packages=packages)
content += catalog_view.get(HttpRequest()).content.decode()

# The hgettext() function just calls gettext() internally,
# but it won't get indexed by makemessages.
content += '\nwindow.hgettext = function(text) { return gettext(text); };\n'
# Add a similar hngettext() function
content += (
'window.hngettext = function(singular, plural, count) { '
'return ngettext(singular, plural, count); '
'};\n')

catalog_filepath = os.path.join(settings.STATIC_CORE_ROOT, f"{language_code}.js")
with open(catalog_filepath, "w") as fd:
fd.write(content)

@no_translations
def handle(self, **kwargs):
for language_code, language_name in settings.LANGUAGES:
self.handle_language(language_code)
24 changes: 12 additions & 12 deletions creme/creme_core/static/chantilly/creme_core/css/creme-ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ul.ui-layout.vbox li { position:relative; display:block; }
/*----------------------------------*/
.ui-creme-selectorlist > div.add {
background-repeat: no-repeat;
background-image: url("chantilly/images/add_16.png");
background-image: url("../../images/add_16.png");
padding-left: 20px;
min-height: 16px;
margin: 4px 0px 4px 0px;
Expand All @@ -76,7 +76,7 @@ ul.ui-layout.vbox li { position:relative; display:block; }
}

.ui-creme-selectorlist button[type="button"].ui-creme-actionbutton {
background-image: url("chantilly/images/add_16.png");
background-image: url("../../images/add_16.png");
padding-left: 20px;
}

Expand Down Expand Up @@ -174,7 +174,7 @@ ul.ui-layout.vbox li { position:relative; display:block; }
vertical-align: middle;
}

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

/*----------------------------------*/
.ui-dialog-scrollbackground {
Expand All @@ -187,14 +187,14 @@ ul.ui-layout.vbox li { position:relative; display:block; }

/*----------------------------------*/
.ui-creme-jqueryplot[widget="ui-creme-jqueryplot"] {
background-image: url("chantilly/images/image_64.png");
background-image: url("../../images/image_64.png");
background-repeat: no-repeat;
background-position: 50% 50%;
background-color: white;
}

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

.ui-creme-jqueryplot.widget-active[widget="ui-creme-jqueryplot"][status="valid"] {
Expand Down Expand Up @@ -247,7 +247,7 @@ ul.ui-layout.vbox li { position:relative; display:block; }
}

.ui-creme-jqueryplot .jqplot-target .jqplot-actions button[name="capture"] {
background-image: url("chantilly/images/image_22.png");
background-image: url("../../images/image_22.png");
}

/*----------------------------------*/
Expand Down Expand Up @@ -294,22 +294,22 @@ button[type="button"].ui-creme-actionbutton[disabled]:hover {
}

button[type="button"].ui-creme-actionbutton[name=create] {
background-image: url("chantilly/images/add_16.png");
background-image: url("../../images/add_16.png");
padding-left: 20px;
}

button[type="button"].ui-creme-actionbutton[name=delete] {
background-image: url("chantilly/images/delete_16.png");
background-image: url("../../images/delete_16.png");
padding-left: 20px;
}

button[type="button"].ui-creme-actionbutton[name=reset] {
background-image: url("chantilly/images/delete_16.png");
background-image: url("../../images/delete_16.png");
padding-left: 20px;
}

ul.ui-creme-actionbuttonlist li button[type="button"].ui-creme-actionbutton[name=edit] {
background-image: url("chantilly/images/edit_16.png");
background-image: url("../../images/edit_16.png");
padding-left: 20px;
}

Expand All @@ -332,13 +332,13 @@ span.ui-creme-datepicker-trigger {
}

.toggle-icon {
background-image: url("chantilly/images/expanded.gif");
background-image: url("../../images/expanded.gif");
background-repeat: no-repeat;
background-position: center;
}

.toggle-icon.toggle-collapsed, .toggle-collapsed .toggle-icon {
background-image: url("chantilly/images/expandme.gif");
background-image: url("../../images/expandme.gif");
background-repeat: no-repeat;
background-position: center;
}
Expand Down
Loading