Performance: Replace inlinestyler with css_inline; Add drf-ujson (#2123)

This commit is contained in:
Raphael Michel
2021-06-13 21:20:18 +02:00
committed by GitHub
parent fb2827e9ab
commit c132ccd141
8 changed files with 27 additions and 14 deletions
+1 -1
View File
@@ -9,4 +9,4 @@ dist/
*.bak *.bak
pretix/static/jsi18n/ pretix/static/jsi18n/
node_modules/ node_modules/
.eggs/
+2 -2
View File
@@ -54,8 +54,8 @@ class SettingsSerializer(serializers.Serializer):
f = DEFAULTS[fname]['serializer_class']( f = DEFAULTS[fname]['serializer_class'](
**kwargs **kwargs
) )
f._label = form_kwargs.get('label', fname) f._label = str(form_kwargs.get('label', fname))
f._help_text = form_kwargs.get('help_text') f._help_text = str(form_kwargs.get('help_text'))
f.parent = self f.parent = self
self.fields[fname] = f self.fields[fname] = f
+6 -2
View File
@@ -26,6 +26,7 @@ from decimal import Decimal
from itertools import groupby from itertools import groupby
from smtplib import SMTPResponseException from smtplib import SMTPResponseException
import css_inline
from django.conf import settings from django.conf import settings
from django.core.mail.backends.smtp import EmailBackend from django.core.mail.backends.smtp import EmailBackend
from django.db.models import Count from django.db.models import Count
@@ -35,7 +36,6 @@ from django.utils.timezone import now
from django.utils.translation import ( from django.utils.translation import (
get_language, gettext_lazy as _, pgettext_lazy, get_language, gettext_lazy as _, pgettext_lazy,
) )
from inlinestyler.utils import inline_css
from pretix.base.i18n import ( from pretix.base.i18n import (
LazyCurrencyNumber, LazyDate, LazyExpiresDate, LazyNumber, LazyCurrencyNumber, LazyDate, LazyExpiresDate, LazyNumber,
@@ -174,7 +174,11 @@ class TemplateBasedMailRenderer(BaseHTMLMailRenderer):
htmlctx['ev'] = position.subevent or self.event htmlctx['ev'] = position.subevent or self.event
tpl = get_template(self.template_name) tpl = get_template(self.template_name)
body_html = inline_css(tpl.render(htmlctx)) body_html = tpl.render(htmlctx)
inliner = css_inline.CSSInliner(remove_style_tags=True)
body_html = inliner.inline(body_html)
return body_html return body_html
-2
View File
@@ -45,7 +45,6 @@ from email.utils import formataddr
from typing import Any, Dict, List, Sequence, Union from typing import Any, Dict, List, Sequence, Union
from urllib.parse import urljoin, urlparse from urllib.parse import urljoin, urlparse
import cssutils
import pytz import pytz
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@@ -79,7 +78,6 @@ from pretix.presale.ical import get_ical
logger = logging.getLogger('pretix.base.mail') logger = logging.getLogger('pretix.base.mail')
INVALID_ADDRESS = 'invalid-pretix-mail-address' INVALID_ADDRESS = 'invalid-pretix-mail-address'
cssutils.log.setLevel(logging.CRITICAL)
class TolerantDict(dict): class TolerantDict(dict):
+6 -2
View File
@@ -19,11 +19,11 @@
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see # You should have received a copy of the GNU Affero General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>. # <https://www.gnu.org/licenses/>.
# #
import css_inline
from django.conf import settings from django.conf import settings
from django.template.loader import get_template from django.template.loader import get_template
from django.utils.timezone import override from django.utils.timezone import override
from django_scopes import scope, scopes_disabled from django_scopes import scope, scopes_disabled
from inlinestyler.utils import inline_css
from pretix.base.i18n import language from pretix.base.i18n import language
from pretix.base.models import LogEntry, NotificationSetting, User from pretix.base.models import LogEntry, NotificationSetting, User
@@ -131,7 +131,11 @@ def send_notification_mail(notification: Notification, user: User):
} }
tpl_html = get_template('pretixbase/email/notification.html') tpl_html = get_template('pretixbase/email/notification.html')
body_html = inline_css(tpl_html.render(ctx))
body_html = tpl_html.render(ctx)
inliner = css_inline.CSSInliner(remove_style_tags=True)
body_html = inliner.inline(body_html)
tpl_plain = get_template('pretixbase/email/notification.txt') tpl_plain = get_template('pretixbase/email/notification.txt')
body_plain = tpl_plain.render(ctx) body_plain = tpl_plain.render(ctx)
+6 -1
View File
@@ -379,7 +379,12 @@ REST_FRAMEWORK = {
'oauth2_provider.contrib.rest_framework.OAuth2Authentication', 'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
), ),
'DEFAULT_RENDERER_CLASSES': ( 'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer', 'drf_ujson.renderers.UJSONRenderer',
),
'DEFAULT_PARSER_CLASSES': (
'drf_ujson.parsers.UJSONParser',
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser'
), ),
'TEST_REQUEST_RENDERER_CLASSES': [ 'TEST_REQUEST_RENDERER_CLASSES': [
'rest_framework.renderers.MultiPartRenderer', 'rest_framework.renderers.MultiPartRenderer',
+3 -3
View File
@@ -1,7 +1,7 @@
[flake8] [flake8]
ignore = N802,W503,E402,C901,E722,W504,E252,N812,N806,E741 ignore = N802,W503,E402,C901,E722,W504,E252,N812,N806,E741
max-line-length = 160 max-line-length = 160
exclude = migrations,.ropeproject,static,mt940.py,_static,build,make_testdata.py,*/testutils/settings.py,tests/settings.py,pretix/base/models/__init__.py,pretix/base/secretgenerators/pretix_sig1_pb2.py exclude = migrations,.ropeproject,static,mt940.py,_static,build,make_testdata.py,*/testutils/settings.py,tests/settings.py,pretix/base/models/__init__.py,pretix/base/secretgenerators/pretix_sig1_pb2.py,.eggs/*
max-complexity = 11 max-complexity = 11
[isort] [isort]
@@ -13,7 +13,7 @@ extra_standard_library = typing,enum,mimetypes
multi_line_output = 5 multi_line_output = 5
line_length = 79 line_length = 79
honor_noqa = true honor_noqa = true
skip = make_testdata.py,wsgi.py,bootstrap,celery_app.py,pretix/settings.py,tests/settings.py,pretix/testutils/settings.py skip_glob = make_testdata.py,wsgi.py,bootstrap,celery_app.py,pretix/settings.py,tests/settings.py,pretix/testutils/settings.py,.eggs/**
[tool:pytest] [tool:pytest]
DJANGO_SETTINGS_MODULE = tests.settings DJANGO_SETTINGS_MODULE = tests.settings
@@ -34,7 +34,7 @@ filterwarnings =
[coverage:run] [coverage:run]
source = pretix source = pretix
omit = */migrations/*,*/urls.py,*/tests/*,*/testdummy/*,*/admin.py,pretix/wsgi.py,pretix/settings.py omit = */migrations/*,*/urls.py,*/tests/*,*/testdummy/*,*/admin.py,pretix/wsgi.py,pretix/settings.py,.eggs/*
[coverage:report] [coverage:report]
exclude_lines = exclude_lines =
+3 -1
View File
@@ -166,6 +166,7 @@ setup(
'chardet<3.1.0,>=3.0.2', 'chardet<3.1.0,>=3.0.2',
'cryptography>=3.4.2', 'cryptography>=3.4.2',
'csscompressor', 'csscompressor',
'css-inline==0.7.*',
'defusedcsv>=1.1.0', 'defusedcsv>=1.1.0',
'dj-static', 'dj-static',
'Django==3.2.*', 'Django==3.2.*',
@@ -189,7 +190,7 @@ setup(
'django-scopes==1.2.*', 'django-scopes==1.2.*',
'django-statici18n==1.9.*', 'django-statici18n==1.9.*',
'djangorestframework==3.12.*', 'djangorestframework==3.12.*',
'inlinestyler==0.2.*', 'drf_ujson2==1.6.*',
'isoweek', 'isoweek',
'jsonschema', 'jsonschema',
'kombu==4.6.*', 'kombu==4.6.*',
@@ -253,6 +254,7 @@ setup(
'memcached': ['pylibmc'], 'memcached': ['pylibmc'],
'mysql': ['mysqlclient'], 'mysql': ['mysqlclient'],
}, },
setup_requires=['setuptools-rust'],
packages=find_packages(exclude=['tests', 'tests.*']), packages=find_packages(exclude=['tests', 'tests.*']),
include_package_data=True, include_package_data=True,