Skip to content

Commit

Permalink
Merge branch 'dev' into handle-matomo-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D authored Sep 19, 2021
2 parents 60a2927 + fe854d9 commit 412bbde
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:
PYTHON_VERSION: "3.7"
MARIADB_VERSION: "10.4.10"
COVERALLS_VERSION: "2.2.0"
BLACK_VERSION: "21.4b1"
BLACK_VERSION: "21.8b0" # needs to be also updated in requirements-dev.txt and .pre-commit-config.yaml

# As GitHub Action does not allow environment variables
# to be used in services definitions, these are only for
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.8b0 # needs to be also updated in requirements-dev.txt and .github/workflows/ci.yml
hooks:
- id: black
language_version: python3
16 changes: 13 additions & 3 deletions assets/js/common/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
*/
class ZDSAjax {
constructor() {
this._crsf = document.querySelector("input[name='csrfmiddlewaretoken']").getAttribute('value')
const csrfInput = document.querySelector("input[name='csrfmiddlewaretoken']")
if (csrfInput !== null) {
this._crsf = csrfInput.getAttribute('value')
}
else {
this._csrf = null
}
}

get(url, dataCallback, errorCallback = (error) => console.error(error)) {
const headers = new Headers()
headers.append('Accept', 'application/json')
headers.append('X-CSRFToken', this._crsf)
if (this._csrf !== null) {
headers.append('X-CSRFToken', this._crsf)
}
headers.append('X-REQUESTED-WITH', 'XMLHttpRequest')
const init = {
method: 'GET',
Expand All @@ -38,7 +46,9 @@ class ZDSAjax {
_sendRequestWithData(jsonOrFormData, method, url, dataCallback, errorCallback) {
const headers = new Headers()
headers.append('Accept', 'application/json')
headers.append('X-CSRFToken', this._crsf)
if (this._csrf !== null) {
headers.append('X-CSRFToken', this._crsf)
}
headers.append('X-REQUESTED-WITH', 'XMLHttpRequest')
const init = {
method: method,
Expand Down
2 changes: 1 addition & 1 deletion assets/scss/components/_pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: flex;
flex-wrap: wrap;

margin: $length-20 0;
margin: $length-20 0 $length-20;

padding: 0;

Expand Down
2 changes: 1 addition & 1 deletion assets/scss/pages/_flexpage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $content-width: 1145px;

.flexpage-wrapper {
max-width: $content-width;
margin: 0 auto;
margin: 0 auto $length-20;
}

.flexpage-header {
Expand Down
14 changes: 3 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
[tool.black]
line-length = 120
exclude = '''
(
/(
node_modules
| \.venv
| build
| dist
| doc
)/
)
'''
extend-exclude = """
^/doc
"""
10 changes: 5 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-r requirements.txt

black==21.4b1 # penser à mettre à jour aussi .github/workflows/ci.yml
colorlog==5.0.1
django-debug-toolbar==3.2.1
black==21.8b0 # needs to be also updated in .github/workflows/ci.yml and .pre-commit-config.yaml
colorlog==6.4.1
django-debug-toolbar==3.2.2
django-extensions==3.1.3
Faker==8.2.1
pre-commit==2.13.0
Faker==8.12.1
pre-commit==2.15.0
PyYAML==5.4.1
selenium==3.141.0
Sphinx==3.5.3
Expand Down
4 changes: 2 additions & 2 deletions requirements-prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

gunicorn==20.1.0
mysqlclient==2.0.3
sentry-sdk==1.1.0
ujson==4.0.2
sentry-sdk==1.3.1
ujson==4.1.0
14 changes: 7 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
elasticsearch-dsl==5.4.0
elasticsearch==5.5.3
python-social-auth==0.3.6
social-auth-app-django==4.0.0
social-auth-app-django==5.0.0

# Explicit dependencies (references in code)
beautifulsoup4==4.9.3
django-crispy-forms==1.11.2
beautifulsoup4==4.10.0
django-crispy-forms==1.12.0
django-model-utils==4.1.1
django-munin==0.2.1
django-recaptcha==2.0.6
Expand All @@ -18,19 +18,19 @@ GitPython==3.1.14
google-api-python-client==1.12.8
homoglyphs==2.0.4
lxml==4.6.3
Pillow==8.2.0
Pillow==8.3.2
python-memcached==1.59
requests==2.25.1
requests==2.26.0
toml==0.10.2

# Api dependencies
django-cors-headers==3.7.0
django-cors-headers==3.8.0
django-filter==2.4.0
django-oauth-toolkit==1.5.0
django-rest-swagger==2.2.0
djangorestframework-xml==2.0.0
djangorestframework==3.12.4
drf-extensions==0.7.0
drf-extensions==0.7.1
dry-rest-permissions==0.1.10
oauth2client==4.1.3

Expand Down
2 changes: 1 addition & 1 deletion zds/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"propagate": False,
},
"zds": {
"level": "DEBUG", # Important because the default level is 'WARNING' or something like that
"level": "INFO",
"handlers": ["console"],
},
},
Expand Down
11 changes: 8 additions & 3 deletions zds/tutorialv2/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def __get_list(self, subcategories=None, tags=None, content_type=None, with_comm
# TODO: check if we can use ORM to do that
sub_query = """
SELECT COUNT(*)
FROM tutorialv2_contentreaction
FROM tutorialv2_contentreaction,utils_comment
WHERE tutorialv2_contentreaction.related_content_id=`tutorialv2_publishablecontent`.`id`
AND utils_comment.id=tutorialv2_contentreaction.comment_ptr_id
AND utils_comment.is_visible = TRUE
"""

queryset = queryset.extra(select={"count_note": sub_query})
Expand Down Expand Up @@ -235,10 +237,12 @@ def get_last_articles(self, number=0):
:return: list of last articles expanded with 'count_note' property that prefetches number of comments
:rtype: list
"""
sub_query = "SELECT COUNT(*) FROM {} WHERE {}={}".format(
"tutorialv2_contentreaction",
sub_query = "SELECT COUNT(*) FROM {} WHERE {}={} AND {}={} AND utils_comment.is_visible=TRUE".format(
"tutorialv2_contentreaction,utils_comment",
"tutorialv2_contentreaction.related_content_id",
"tutorialv2_publishedcontent.content_pk",
"utils_comment.id",
"tutorialv2_contentreaction.comment_ptr_id",
)
number = number or settings.ZDS_APP["article"]["home_number"]
all_contents = (
Expand All @@ -252,6 +256,7 @@ def get_last_articles(self, number=0):
.extra(select={"count_note": sub_query})
.order_by("-public_version__publication_date")[:number]
)

published = []
for content in all_contents:
content.public_version.content = content
Expand Down
4 changes: 2 additions & 2 deletions zds/tutorialv2/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,13 @@ def get_note_count(self):
"""Count all the reactions to this content. Warning, if you did not pre process this number, \
a query will be sent
:return: number of notes in the tutorial.
:return: number of notes in the content.
:rtype: int
"""
try:
return self.count_note
except AttributeError:
self.count_note = ContentReaction.objects.filter(related_content__pk=self.pk).count()
self.count_note = ContentReaction.objects.filter(related_content__pk=self.pk, is_visible=True).count()
return self.count_note

def get_last_note(self):
Expand Down
13 changes: 7 additions & 6 deletions zds/tutorialv2/publication_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,12 @@ def publish(self, md_file_path, base_name, **kwargs):
licence_logo = licences["copyright"]
licence_url = ""

replacement_image_url = str(settings.MEDIA_ROOT)
if not replacement_image_url.endswith("/") and settings.MEDIA_URL.endswith("/"):
replacement_image_url = str(settings.MEDIA_ROOT.parent)
if not replacement_image_url.endswith("/"):
replacement_image_url += "/"
elif replacement_image_url.endswith("/") and not settings.MEDIA_URL.endswith("/"):
replacement_image_url = replacement_image_url[:-1]
replaced_media_url = settings.MEDIA_URL
if replaced_media_url.startswith("/"):
replaced_media_url = replaced_media_url[1:]
exported = export_content(public_versionned_source, with_text=True)
# no title to avoid zmd to put it on the final latex
del exported["title"]
Expand All @@ -423,13 +424,13 @@ def publish(self, md_file_path, base_name, **kwargs):
license_url=licence_url,
smileys_directory=str(SMILEYS_BASE_PATH / "svg"),
images_download_dir=str(base_directory / "images"),
local_url_to_local_path=[settings.MEDIA_URL, replacement_image_url],
local_url_to_local_path=["/", replacement_image_url],
heading_shift=-1,
)
if content == "" and messages:
raise FailureDuringPublication(f"Markdown was not parsed due to {messages}")
zmd_class_dir_path = Path(settings.ZDS_APP["content"]["latex_template_repo"])

content.replace(replacement_image_url + replaced_media_url, replacement_image_url)
if zmd_class_dir_path.exists() and zmd_class_dir_path.is_dir():
with contextlib.suppress(FileExistsError):
zmd_class_link = base_directory / "zmdocument.cls"
Expand Down
6 changes: 4 additions & 2 deletions zds/tutorialv2/views/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ def get_queryset(self):
:return: list of contents with the right type
:rtype: list of zds.tutorialv2.models.database.PublishedContent
"""
sub_query = "SELECT COUNT(*) FROM {} WHERE {}={}".format(
"tutorialv2_contentreaction",
sub_query = "SELECT COUNT(*) FROM {} WHERE {}={} AND {}={} AND utils_comment.is_visible=TRUE".format(
"tutorialv2_contentreaction,utils_comment",
"tutorialv2_contentreaction.related_content_id",
"tutorialv2_publishablecontent.id",
"utils_comment.id",
"tutorialv2_contentreaction.comment_ptr_id",
)
queryset = PublishedContent.objects.filter(must_redirect=False)
# this condition got more complexe with development of zep13
Expand Down
26 changes: 19 additions & 7 deletions zds/utils/templatetags/emarkdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def log_args():
return "", {}, []


def render_markdown(md_input, *, on_error=None, **kwargs):
def render_markdown(md_input, *, on_error=None, disable_jsfiddle=True, **kwargs):
"""Render a markdown string.
Returns a tuple ``(rendered_content, metadata)``, where
Expand All @@ -102,7 +102,9 @@ def render_markdown(md_input, *, on_error=None, **kwargs):
(without any technical details).
"""
content, metadata, messages = _render_markdown_once(md_input, **kwargs)
opts = {"disable_jsfiddle": disable_jsfiddle}
opts.update(kwargs)
content, metadata, messages = _render_markdown_once(md_input, **opts)
if messages and on_error:
on_error([m["message"] for m in messages])
if content is not None:
Expand Down Expand Up @@ -145,11 +147,21 @@ def render_markdown_stats(md_input, **kwargs):

@register.filter(name="epub_markdown", needs_autoescape=False)
def epub_markdown(md_input, image_directory):
return emarkdown(
md_input,
output_format="epub",
images_download_dir=image_directory.absolute,
local_url_to_local_path=[settings.MEDIA_URL + "galleries/[0-9]+", image_directory.relative],
media_root = str(settings.MEDIA_ROOT)
if not media_root.endswith("/"):
media_root += "/"
replaced_media_url = settings.MEDIA_URL
if replaced_media_url.startswith("/"):
replaced_media_url = replaced_media_url[1:]
return (
emarkdown(
md_input,
output_format="epub",
images_download_dir=image_directory.absolute,
local_url_to_local_path=[settings.MEDIA_URL + "galleries/[0-9]+", image_directory.relative],
)
.replace('src"/', f'src="{media_root}')
.replace(f'src="{media_root}{replaced_media_url}', f'src="{media_root}')
)


Expand Down
2 changes: 1 addition & 1 deletion zmd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"zmarkdown": "10.1.2"
"zmarkdown": "10.1.3"
},
"engines": {
"node": ">=8.0.0"
Expand Down

0 comments on commit 412bbde

Please sign in to comment.