Skip to content

Commit 7868518

Browse files
author
Agus Makmun
committed
fix: custom MARTOR_UPLOAD_URL not working #210
1 parent fdadca8 commit 7868518

19 files changed

+109
-160
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ MARTOR_IMGUR_API_KEY = 'your-api-key'
120120
MARTOR_MARKDOWNIFY_FUNCTION = 'martor.utils.markdownify' # default
121121
MARTOR_MARKDOWNIFY_URL = '/martor/markdownify/' # default
122122

123-
# Delay in miliseconds to update editor preview when in living mode.
123+
# Delay in milliseconds to update editor preview when in living mode.
124124
MARTOR_MARKDOWNIFY_TIMEOUT = 0 # update the preview instantly
125125
# or:
126126
MARTOR_MARKDOWNIFY_TIMEOUT = 1000 # default
@@ -242,7 +242,7 @@ admin.site.register(YourModel, YourModelAdmin)
242242

243243
#### Template Renderer
244244

245-
Simply safely parse markdown content as html ouput by loading templatetags from `martor/templatetags/martortags.py`.
245+
Simply safely parse markdown content as html output by loading templatetags from `martor/templatetags/martortags.py`.
246246

247247
```html
248248
{% load martortags %}
@@ -340,7 +340,7 @@ If you want to save the images uploaded to your storage,
340340

341341
### Test Martor from this Repository
342342

343-
Assuming you are already setup with a virtual enviroment (virtualenv):
343+
Assuming you are already setup with a virtual environment (virtualenv):
344344

345345
```
346346
$ git clone https://github.com/agusmakmun/django-markdown-editor.git
@@ -356,7 +356,7 @@ Checkout at http://127.0.0.1:8000/simple-form/ on your browser.
356356

357357
### Martor Commands Reference
358358

359-
![command refference](https://raw.githubusercontent.com/agusmakmun/django-markdown-editor/master/.etc/images/bootstrap/martor-guide.png)
359+
![command reference](https://raw.githubusercontent.com/agusmakmun/django-markdown-editor/master/.etc/images/bootstrap/martor-guide.png)
360360

361361

362362
### Notes

martor/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
__VERSION__ = "1.6.37"
4-
__RELEASE_DATE__ = "09-Mar-2024"
3+
__VERSION__ = "1.6.38"
4+
__RELEASE_DATE__ = "15-Mar-2024"
55
__AUTHOR__ = "Agus Makmun (Summon Agus)"
66
__AUTHOR_EMAIL__ = "[email protected]"

martor/api.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4-
import json
54
import base64
5+
import json
6+
67
import requests
7-
from .settings import MARTOR_IMGUR_CLIENT_ID, MARTOR_IMGUR_API_KEY
8+
9+
from .settings import MARTOR_IMGUR_API_KEY, MARTOR_IMGUR_CLIENT_ID
810

911
requests.packages.urllib3.disable_warnings()
1012

@@ -39,7 +41,7 @@ def imgur_uploader(image):
3941
)
4042

4143
elif response.status_code == 415:
42-
# Unsupport File type
44+
# Unsupported File type
4345
return json.dumps(
4446
{
4547
"status": response.status_code,

martor/extensions/mention.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import markdown
22
from django.contrib.auth import get_user_model
3+
34
from ..settings import MARTOR_ENABLE_CONFIGS, MARTOR_MARKDOWN_BASE_MENTION_URL
45

56
"""
@@ -26,7 +27,7 @@ def handleMatch(self, m):
2627
username=username, is_active=True
2728
) # noqa: E501
2829

29-
"""Makesure `username` is registered and actived."""
30+
"""Makesure `username` is registered and activated."""
3031
if MARTOR_ENABLE_CONFIGS["mention"] == "true":
3132
if users.exists():
3233
url = "{0}{1}/".format(

martor/static/martor/css/martor-admin.min.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.37
2+
* Name : Martor v1.6.38
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 09-Mar-2024
4+
* Release date : 15-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/css/martor.bootstrap.min.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.37
2+
* Name : Martor v1.6.38
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 09-Mar-2024
4+
* Release date : 15-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/css/martor.semantic.min.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.37
2+
* Name : Martor v1.6.38
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 09-Mar-2024
4+
* Release date : 15-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/js/martor.bootstrap.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.37
2+
* Name : Martor v1.6.38
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 09-Mar-2024
4+
* Release date : 15-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/js/martor.bootstrap.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

martor/static/martor/js/martor.semantic.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* Name : Martor v1.6.37
2+
* Name : Martor v1.6.38
33
* Created by : Agus Makmun (Summon Agus)
4-
* Release date : 09-Mar-2024
4+
* Release date : 15-Mar-2024
55
* License : GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
66
* Repository : https://github.com/agusmakmun/django-markdown-editor
77
**/

martor/static/martor/js/martor.semantic.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

martor/templatetags/martortags.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@register.filter
1010
def safe_markdown(markdown_text):
1111
"""
12-
Safe the markdown text as html ouput.
12+
Safe the markdown text as html output.
1313
1414
Usage:
1515
{% load martortags %}

martor/tests/tests.py

+2-16
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from django.contrib.auth.models import User
55
from django.core.signals import setting_changed
66
from django.test import TestCase, override_settings
7-
from django.urls import resolve, reverse, NoReverseMatch, clear_url_caches
7+
from django.urls import clear_url_caches, resolve, reverse
88

99
from martor.utils import markdownify
10-
from martor.views import markdownfy_view, markdown_imgur_uploader, markdown_search_user
10+
from martor.views import markdown_imgur_uploader, markdown_search_user, markdownfy_view
1111

1212

1313
class SimpleTest(TestCase):
@@ -129,20 +129,6 @@ def test_markdownify_xss_handled(self):
129129
)
130130

131131
def test_urls(self):
132-
with override_settings(
133-
MARTOR_MARKDOWNIFY_URL="test/url",
134-
MARTOR_UPLOAD_URL="",
135-
MARTOR_SEARCH_USERS_URL="",
136-
):
137-
found = resolve(reverse("martor_markdownfy"))
138-
self.assertEqual(found.func, markdownfy_view)
139-
140-
with self.assertRaises(NoReverseMatch):
141-
reverse("imgur_uploader")
142-
143-
with self.assertRaises(NoReverseMatch):
144-
reverse("search_user_json")
145-
146132
with override_settings(
147133
MARTOR_MARKDOWNIFY_URL="test/url",
148134
MARTOR_UPLOAD_URL="test/upload",

martor/tests/urls.py

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import django
1+
from django.urls import include, path
22

33
from .views import TestFormView
44

5-
6-
if django.VERSION >= (2, 0):
7-
from django.urls import path, include
8-
9-
urlpatterns = [
10-
path("test-form-view/", TestFormView.as_view()),
11-
path("", include("martor.urls")),
12-
]
13-
else:
14-
from django.conf.urls import url, include
15-
16-
urlpatterns = [
17-
url(r"^test-form-view/$", TestFormView.as_view()),
18-
url(r"^martor/", include("martor.urls")),
19-
]
5+
urlpatterns = [
6+
path("test-form-view/", TestFormView.as_view()),
7+
path("martor/", include("martor.urls")),
8+
]

martor/urls.py

+7-73
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,9 @@
1-
import django
1+
from django.urls import path
22

3-
from .settings import MARTOR_MARKDOWNIFY_URL, MARTOR_UPLOAD_URL, MARTOR_SEARCH_USERS_URL
4-
from .views import (
5-
markdownfy_view,
6-
markdown_imgur_uploader,
7-
markdown_search_user,
8-
)
3+
from .views import markdown_imgur_uploader, markdown_search_user, markdownfy_view
94

10-
11-
def __normalize(path: str) -> str:
12-
# to support Python < 3.9 we can't use removeprefix('/').removesuffix('/')
13-
if path.startswith("/"):
14-
path = path[1:]
15-
if path.endswith("/"):
16-
path = path[:-1]
17-
return path
18-
19-
20-
if django.VERSION >= (2, 0):
21-
from django.urls import path
22-
23-
urlpatterns = [
24-
path(
25-
f"{__normalize(MARTOR_MARKDOWNIFY_URL)}/",
26-
markdownfy_view,
27-
name="martor_markdownfy",
28-
),
29-
]
30-
31-
if MARTOR_UPLOAD_URL:
32-
urlpatterns.append(
33-
path(
34-
f"{__normalize(MARTOR_UPLOAD_URL)}/",
35-
markdown_imgur_uploader,
36-
name="imgur_uploader",
37-
),
38-
)
39-
40-
if MARTOR_SEARCH_USERS_URL:
41-
urlpatterns.append(
42-
path(
43-
f"{__normalize(MARTOR_SEARCH_USERS_URL)}/",
44-
markdown_search_user,
45-
name="search_user_json",
46-
),
47-
)
48-
else:
49-
from django.conf.urls import url
50-
51-
urlpatterns = [
52-
url(
53-
r"^%s/$" % __normalize(MARTOR_MARKDOWNIFY_URL),
54-
markdownfy_view,
55-
name="martor_markdownfy"
56-
),
57-
]
58-
59-
if MARTOR_UPLOAD_URL:
60-
urlpatterns.append(
61-
url(
62-
r"^%s/$" % __normalize(MARTOR_UPLOAD_URL),
63-
markdown_imgur_uploader,
64-
name="imgur_uploader",
65-
),
66-
)
67-
68-
if MARTOR_SEARCH_USERS_URL:
69-
urlpatterns.append(
70-
url(
71-
r"^%s/$" % __normalize(MARTOR_SEARCH_USERS_URL),
72-
markdown_search_user,
73-
name="search_user_json",
74-
),
75-
)
5+
urlpatterns = [
6+
path("markdownify/", markdownfy_view, name="martor_markdownfy"),
7+
path("uploader/", markdown_imgur_uploader, name="imgur_uploader"),
8+
path("search-user/", markdown_search_user, name="search_user_json"),
9+
]

martor/utils.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import re
2-
import bleach
32

4-
from django.utils.functional import Promise
3+
import bleach
54
from django.core.serializers.json import DjangoJSONEncoder
5+
from django.utils.functional import Promise
66

77
try:
88
from django.utils.encoding import force_str # noqa: Django>=4.x
99
except ImportError:
1010
from django.utils.encoding import force_text as force_str # noqa: Django<=3.x
1111

1212
import markdown
13+
1314
from .settings import (
14-
MARTOR_MARKDOWN_EXTENSIONS,
15-
MARTOR_MARKDOWN_EXTENSION_CONFIGS,
16-
ALLOWED_URL_SCHEMES,
17-
ALLOWED_HTML_TAGS,
1815
ALLOWED_HTML_ATTRIBUTES,
16+
ALLOWED_HTML_TAGS,
17+
ALLOWED_URL_SCHEMES,
18+
MARTOR_MARKDOWN_EXTENSION_CONFIGS,
19+
MARTOR_MARKDOWN_EXTENSIONS,
1920
)
2021

2122

@@ -63,7 +64,7 @@ class LazyEncoder(DjangoJSONEncoder):
6364
This problem because we found error encoding,
6465
as docs says, django has special `DjangoJSONEncoder` at
6566
https://docs.djangoproject.com/en/dev/topics/serialization/#serialization-formats-json
66-
also discused in this answer: http://stackoverflow.com/a/31746279/6396981
67+
also discussed in this answer: http://stackoverflow.com/a/31746279/6396981
6768
6869
Usage:
6970
>>> data = {}

martor/views.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
from django.contrib.auth import get_user_model
5+
from django.contrib.auth.decorators import login_required
46
from django.http import HttpResponse, JsonResponse
57
from django.utils.module_loading import import_string
68
from django.utils.translation import gettext_lazy as _
7-
from django.contrib.auth.decorators import login_required
8-
from django.contrib.auth import get_user_model
99

1010
from .api import imgur_uploader
1111
from .settings import MARTOR_MARKDOWNIFY_FUNCTION
@@ -44,7 +44,7 @@ def is_ajax(request):
4444
@login_required
4545
def markdown_search_user(request):
4646
"""
47-
Json usernames of the users registered & actived.
47+
Json usernames of the users registered & activated.
4848
4949
url(method=get):
5050
/martor/search-user/?username={username}

0 commit comments

Comments
 (0)