Skip to content

Commit 1a2d0dd

Browse files
committed
fix: remove python 3.5 travis which following python Markdown, some flake8, Object of type QuerySet is not JSON serializable
1 parent e535b38 commit 1a2d0dd

File tree

9 files changed

+216
-126
lines changed

9 files changed

+216
-126
lines changed

.travis.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,6 @@ sudo: false
33

44
matrix:
55
include:
6-
- python: 3.5
7-
env: DJANGO="==1.8.*"
8-
- python: 3.5
9-
env: DJANGO="==1.9.*"
10-
- python: 3.5
11-
env: DJANGO="==1.10.*"
12-
- python: 3.5
13-
env: DJANGO="==1.11.*"
14-
- python: 3.5
15-
env: DJANGO="==2.0.*"
16-
- python: 3.5
17-
env: DJANGO="==2.1.*"
18-
- python: 3.5
19-
env: DJANGO="==2.2.*"
20-
216
- python: 3.6
227
env: DJANGO="==1.8.*"
238
- python: 3.6
@@ -59,6 +44,17 @@ matrix:
5944
- python: 3.8
6045
env: DJANGO="==3.1.*"
6146

47+
- python: 3.9
48+
env: DJANGO="==2.0.*"
49+
- python: 3.9
50+
env: DJANGO="==2.1.*"
51+
- python: 3.9
52+
env: DJANGO="==2.2.*"
53+
- python: 3.9
54+
env: DJANGO="==3.0.*"
55+
- python: 3.9
56+
env: DJANGO="==3.1.*"
57+
6258
- os: osx
6359
language: generic
6460
env: DJANGO="==3.1.*"

martor/extensions/emoji.py

Lines changed: 161 additions & 80 deletions
Large diffs are not rendered by default.

martor/extensions/mention.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
>>> import markdown
1010
>>> md = markdown.Markdown(extensions=['martor.utils.extensions.mention'])
1111
>>> md.convert('@[summonagus]')
12-
'<p><a class="direct-mention-link" href="https://webname.com/profile/summonagus/">summonagus</a></p>'
12+
'<p><a class="direct-mention-link"
13+
href="https://example.com/profile/summonagus/">summonagus</a></p>'
1314
>>>
1415
>>> md.convert('hello @[summonagus], i mentioned you!')
15-
'<p>hello <a class="direct-mention-link" href="https://webname.com/profile/summonagus/">summonagus</a>, i mentioned you!</p>'
16+
'<p>hello <a class="direct-mention-link"
17+
href="https://example.com/profile/summonagus/">summonagus</a>,
18+
i mentioned you!</p>'
1619
>>>
1720
"""
1821

martor/settings.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
# Input: string boolean, `true/false`
1111
MARTOR_ENABLE_CONFIGS = getattr(
1212
settings, 'MARTOR_ENABLE_CONFIGS', {
13-
'emoji': 'true', # to enable/disable emoji icons.
14-
'imgur': 'true', # to enable/disable imgur/custom uploader.
15-
'mention': 'false', # to enable/disable mention
16-
'jquery': 'true', # to include/revoke jquery (require for admin default django)
17-
'living': 'false', # to enable/disable live updates in preview
18-
'spellcheck': 'false', # to enable/disable spellcheck in form textareas
19-
'hljs': 'true', # to enable/disable hljs highlighting in preview
13+
'emoji': 'true', # enable/disable emoji icons.
14+
'imgur': 'true', # enable/disable imgur/custom uploader.
15+
'mention': 'false', # enable/disable mention
16+
'jquery': 'true', # include/revoke jquery (require for admin django)
17+
'living': 'false', # enable/disable live updates in preview
18+
'spellcheck': 'false', # enable/disable spellcheck in form textareas
19+
'hljs': 'true', # enable/disable hljs highlighting in preview
2020
}
2121
)
2222

@@ -61,10 +61,10 @@
6161

6262
# Custom markdown extensions.
6363
'martor.extensions.urlize',
64-
'martor.extensions.del_ins', # ~~strikethrough~~ and ++underscores++
65-
'martor.extensions.mention', # to parse markdown mention
66-
'martor.extensions.emoji', # to parse markdown emoji
67-
'martor.extensions.mdx_video', # to parse embed/iframe video
64+
'martor.extensions.del_ins', # ~~strikethrough~~ and ++underscores++
65+
'martor.extensions.mention', # to parse markdown mention
66+
'martor.extensions.emoji', # to parse markdown emoji
67+
'martor.extensions.mdx_video', # to parse embed/iframe video
6868
'martor.extensions.escape_html', # to handle the XSS vulnerabilities
6969
]
7070
)
@@ -76,19 +76,23 @@
7676

7777
# Markdown urls
7878
MARTOR_UPLOAD_URL = getattr(
79-
settings, 'MARTOR_UPLOAD_URL', '/martor/uploader/' # for imgur
79+
settings, 'MARTOR_UPLOAD_URL',
80+
'/martor/uploader/' # for imgur
8081
)
8182
MARTOR_SEARCH_USERS_URL = getattr(
82-
settings, 'MARTOR_SEARCH_USERS_URL', '/martor/search-user/' # for mention
83+
settings, 'MARTOR_SEARCH_USERS_URL',
84+
'/martor/search-user/' # for mention
8385
)
8486

8587
# Markdown Extensions
8688
MARTOR_MARKDOWN_BASE_EMOJI_URL = getattr(
87-
settings, 'MARTOR_MARKDOWN_BASE_EMOJI_URL', 'https://github.githubassets.com/images/icons/emoji/'
89+
settings, 'MARTOR_MARKDOWN_BASE_EMOJI_URL',
90+
'https://github.githubassets.com/images/icons/emoji/'
8891
)
8992

9093
MARTOR_MARKDOWN_BASE_MENTION_URL = getattr(
91-
settings, 'MARTOR_MARKDOWN_BASE_MENTION_URL', 'https://python.web.id/author/'
94+
settings, 'MARTOR_MARKDOWN_BASE_MENTION_URL',
95+
'https://python.web.id/author/'
9296
)
9397

9498
# If you need to use your own themed "bootstrap" or "semantic ui" dependency

martor/tests/tests.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
from django.test import TestCase
2+
from martor.utils import markdownify, VersionNotCompatible
33

44

55
class SimpleTest(TestCase):
@@ -9,12 +9,11 @@ def test_me(self):
99
self.assertEqual(response.status_code, 200)
1010

1111
def test_markdownify_error(self,):
12-
from martor.utils import markdownify, VersionNotCompatible
13-
## This tests that real errors don't raise VersionNotCompatible
12+
# This tests that real errors don't raise VersionNotCompatible
1413
# errors, which could be misleading.
1514
try:
1615
markdownify(None)
1716
except Exception as e:
18-
self.assertNotIsInstance(e,VersionNotCompatible)
17+
self.assertNotIsInstance(e, VersionNotCompatible)
1918
else:
2019
self.fail("no assertion raised")

martor/utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ def markdownify(markdown_content):
3636
except TypeError as e:
3737
if 'extendMarkdown' not in str(e):
3838
raise
39-
raise VersionNotCompatible("The markdown isn't compatible, please reinstall "
40-
"your python markdown into Markdown>=3.0")
39+
raise VersionNotCompatible(
40+
"The markdown isn't compatible, please reinstall "
41+
"your python markdown into Markdown>=3.0"
42+
)
4143

4244

4345
class LazyEncoder(DjangoJSONEncoder):
4446
"""
4547
This problem because we found error encoding,
46-
as docs says, django has special `DjangoJSONEncoder`
47-
at https://docs.djangoproject.com/en/1.10/topics/serialization/#serialization-formats-json
48+
as docs says, django has special `DjangoJSONEncoder` at
49+
https://docs.djangoproject.com/en/dev/topics/serialization/#serialization-formats-json
4850
also discused in this answer: http://stackoverflow.com/a/31746279/6396981
4951
5052
Usage:

martor/views.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
22
from __future__ import unicode_literals
33

4+
import json
5+
46
from django.http import (HttpResponse, JsonResponse)
57
from django.utils.module_loading import import_string
68
from django.utils.translation import ugettext_lazy as _
@@ -9,6 +11,7 @@
911

1012
from .api import imgur_uploader
1113
from .settings import MARTOR_MARKDOWNIFY_FUNCTION
14+
from .utils import LazyEncoder
1215

1316
User = get_user_model()
1417

@@ -67,8 +70,9 @@ def markdown_search_user(request):
6770
queries = {'%s__icontains' % User.USERNAME_FIELD: username}
6871
users = User.objects.filter(**queries).filter(is_active=True)
6972
if users.exists():
70-
users_name = users.values_list('username', flat=True)
71-
response_data.update({'status': 200, 'data': users_name})
73+
usernames = users.values_list('username', flat=True)
74+
usernames = json.dumps(list(usernames))
75+
response_data.update({'status': 200, 'data': usernames})
7276
return JsonResponse(response_data)
7377

7478
error_message = _('No users registered as `%(username)s` '
@@ -79,4 +83,4 @@ def markdown_search_user(request):
7983
error_message = _('Validation Failed for field `username`')
8084
response_data.update({'status': 204, 'error': error_message})
8185

82-
return JsonResponse(response_data)
86+
return JsonResponse(response_data, encoder=LazyEncoder)

martor/widgets.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def render(self, name, value, attrs=None, renderer=None, **kwargs):
5757
emoji_enabled = MARTOR_ENABLE_CONFIGS.get('emoji') == 'true'
5858
mentions_enabled = MARTOR_ENABLE_CONFIGS.get('mention') == 'true'
5959

60-
widget = super(MartorWidget, self).render(name, value, attributes_to_pass)
60+
widget = super().render(name, value, attributes_to_pass)
6161

6262
return template.render({
6363
'martor': widget,
@@ -88,7 +88,8 @@ class Media:
8888
'martor/js/martor.%s.min.js' % selected_theme,
8989
)
9090

91-
# Adding the following scripts to the end of the tuple in case it affects behaviour.
91+
# Adding the following scripts to the end
92+
# of the tuple in case it affects behaviour.
9293
# spellcheck configuration
9394
if MARTOR_ENABLE_CONFIGS.get('spellcheck') == 'true':
9495
js = ('plugins/js/typo.js', 'plugins/js/spellcheck.js').__add__(js)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ def get_requirements():
3838
'Operating System :: OS Independent',
3939
'Programming Language :: JavaScript',
4040
'Programming Language :: Python',
41-
'Programming Language :: Python :: 3.5',
4241
'Programming Language :: Python :: 3.6',
4342
'Programming Language :: Python :: 3.7',
4443
'Programming Language :: Python :: 3.8',
44+
'Programming Language :: Python :: 3.9',
4545
'Topic :: Software Development :: Libraries :: Python Modules',
4646
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
4747
],

0 commit comments

Comments
 (0)