diff --git a/.flake8 b/.flake8 index be5d5515c8..fdbeb86a5a 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,6 @@ [flake8] max-line-length = 120 -application-import-names = dmoj,judge,django_ace +application-import-names = dmoj,judge,django_ace,martor import-order-style = pycharm enable-extensions = G ignore = @@ -18,6 +18,9 @@ per-file-ignores = ./judge/management/commands/runmoss.py:F403,F405 # E501: line too long, ignore in migrations ./judge/migrations/*.py:E501 + # E501: line too long, ignore in martor emoji and mention extensions + ./martor/extensions/emoji.py:E501 + ./martor/extensions/mention.py:E501 exclude = # belongs to the user ./dmoj/local_settings.py, diff --git a/dmoj/urls.py b/dmoj/urls.py index 32976e10dc..5852a0094b 100644 --- a/dmoj/urls.py +++ b/dmoj/urls.py @@ -8,7 +8,6 @@ from django.utils.functional import lazy from django.utils.translation import gettext_lazy as _ from django.views.generic import RedirectView -from martor.views import markdown_search_user from judge.feed import AtomBlogFeed, AtomCommentFeed, AtomProblemFeed, BlogFeed, CommentFeed, ProblemFeed from judge.sitemap import sitemaps @@ -22,6 +21,7 @@ ContestUserSearchSelect2View, OrganizationSelect2View, ProblemSelect2View, TicketUserSelect2View, \ UserSearchSelect2View, UserSelect2View from judge.views.widgets import martor_image_uploader +from martor.views import markdown_search_user admin.autodiscover() diff --git a/martor/admin.py b/martor/admin.py index 2e041b75eb..1046adeec9 100644 --- a/martor/admin.py +++ b/martor/admin.py @@ -1,12 +1,11 @@ from django.contrib import admin -from django.db import models -from .widgets import AdminMartorWidget from .models import MartorField +from .widgets import AdminMartorWidget class MartorModelAdmin(admin.ModelAdmin): formfield_overrides = { - MartorField: {'widget': AdminMartorWidget} + MartorField: {'widget': AdminMartorWidget}, } diff --git a/martor/api.py b/martor/api.py index 2f0b2964e1..c0e12eac6a 100644 --- a/martor/api.py +++ b/martor/api.py @@ -1,7 +1,10 @@ -import json import base64 +import json + + import requests -from .settings import (MARTOR_IMGUR_CLIENT_ID, MARTOR_IMGUR_API_KEY) + +from .settings import MARTOR_IMGUR_API_KEY, MARTOR_IMGUR_CLIENT_ID requests.packages.urllib3.disable_warnings() @@ -24,8 +27,8 @@ def imgur_uploader(image): 'key': MARTOR_IMGUR_API_KEY, 'image': base64.b64encode(image.read()), 'type': 'base64', - 'name': image.name - } + 'name': image.name, + }, ) """ @@ -40,15 +43,15 @@ def imgur_uploader(image): return json.dumps({ 'status': respdata['status'], 'link': respdata['data']['link'], - 'name': respdata['data']['name'] + 'name': respdata['data']['name'], }) elif response.status_code == 415: # Unsupport File type return json.dumps({ 'status': response.status_code, - 'error': response.reason + 'error': response.reason, }) return json.dumps({ 'status': response.status_code, - 'error': response.content.decode('utf-8') + 'error': response.content.decode('utf-8'), }) diff --git a/martor/extensions/del_ins.py b/martor/extensions/del_ins.py index 14db77552f..5cb930e2cd 100644 --- a/martor/extensions/del_ins.py +++ b/martor/extensions/del_ins.py @@ -31,8 +31,8 @@ from markdown.inlinepatterns import SimpleTagPattern -DEL_RE = r"(\~\~)(.+?)(\~\~)" -INS_RE = r"(\+\+)(.+?)(\+\+)" +DEL_RE = r'(\~\~)(.+?)(\~\~)' +INS_RE = r'(\+\+)(.+?)(\+\+)' class DelInsExtension(markdown.extensions.Extension): @@ -49,6 +49,6 @@ def makeExtension(*args, **kwargs): return DelInsExtension(*args, **kwargs) -if __name__ == "__main__": +if __name__ == '__main__': import doctest doctest.testmod() diff --git a/martor/extensions/emoji.py b/martor/extensions/emoji.py index 238c304af8..7706b975c5 100644 --- a/martor/extensions/emoji.py +++ b/martor/extensions/emoji.py @@ -99,7 +99,7 @@ def handleMatch(self, m): if emoji not in EMOJIS: return emoji url = '{0}{1}.png'.format( - MARTOR_MARKDOWN_BASE_EMOJI_URL, emoji.replace(':', '') + MARTOR_MARKDOWN_BASE_EMOJI_URL, emoji.replace(':', ''), ) if MARTOR_MARKDOWN_BASE_EMOJI_USE_STATIC is True: url = static(url) @@ -121,6 +121,6 @@ def makeExtension(*args, **kwargs): return EmojiExtension(*args, **kwargs) -if __name__ == "__main__": +if __name__ == '__main__': import doctest doctest.testmod() diff --git a/martor/extensions/mdx_video.py b/martor/extensions/mdx_video.py index 52518df743..a8f965dc35 100644 --- a/martor/extensions/mdx_video.py +++ b/martor/extensions/mdx_video.py @@ -30,7 +30,7 @@ def add_inline(self, md, name, klass, re): pattern = klass(re) pattern.md = md pattern.ext = self - md.inlinePatterns.add(name, pattern, "= (2, 0): diff --git a/martor/utils.py b/martor/utils.py index 49cb131f7f..859026e887 100644 --- a/martor/utils.py +++ b/martor/utils.py @@ -1,12 +1,12 @@ -from django.utils.functional import Promise -from django.utils.encoding import force_str +import markdown from django.core.serializers.json import DjangoJSONEncoder +from django.utils.encoding import force_str +from django.utils.functional import Promise -import markdown from .settings import ( - MARTOR_MARKDOWN_SAFE_MODE, MARTOR_MARKDOWN_EXTENSIONS, - MARTOR_MARKDOWN_EXTENSION_CONFIGS + MARTOR_MARKDOWN_EXTENSION_CONFIGS, + MARTOR_MARKDOWN_SAFE_MODE, ) @@ -30,11 +30,11 @@ def markdownify(markdown_content): markdown_content, safe_mode=MARTOR_MARKDOWN_SAFE_MODE, extensions=MARTOR_MARKDOWN_EXTENSIONS, - extension_configs=MARTOR_MARKDOWN_EXTENSION_CONFIGS + extension_configs=MARTOR_MARKDOWN_EXTENSION_CONFIGS, ) except Exception: raise VersionNotCompatible("The markdown isn't compatible, please reinstall " - "your python markdown into Markdown>=3.0") + 'your python markdown into Markdown>=3.0') class LazyEncoder(DjangoJSONEncoder): diff --git a/martor/views.py b/martor/views.py index de3d68e9a0..fce7b48d90 100644 --- a/martor/views.py +++ b/martor/views.py @@ -1,10 +1,11 @@ import json -from django.http import HttpResponse -from django.utils.module_loading import import_string -from django.utils.translation import gettext_lazy as _ + from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.db.models import Q +from django.http import HttpResponse +from django.utils.module_loading import import_string +from django.utils.translation import gettext_lazy as _ from .api import imgur_uploader from .settings import MARTOR_MARKDOWNIFY_FUNCTION @@ -60,12 +61,12 @@ def markdown_search_user(request): and username != '' \ and ' ' not in username: users = User.objects.filter( - Q(username__icontains=username) + Q(username__icontains=username), ).filter(is_active=True) if users.exists(): data.update({ 'status': 200, - 'data': [{'username': u.username} for u in users] + 'data': [{'username': u.username} for u in users], }) return HttpResponse( json.dumps(data, cls=LazyEncoder), @@ -73,12 +74,12 @@ def markdown_search_user(request): data.update({ 'status': 204, 'error': _('No users registered as `%(username)s` ' - 'or user is unactived.') % {'username': username} + 'or user is unactived.') % {'username': username}, }) else: data.update({ 'status': 204, - 'error': _('Validation Failed for field `username`') + 'error': _('Validation Failed for field `username`'), }) return HttpResponse( json.dumps(data, cls=LazyEncoder), diff --git a/martor/widgets.py b/martor/widgets.py index 531ef4f3ff..c90c279fb5 100644 --- a/martor/widgets.py +++ b/martor/widgets.py @@ -1,13 +1,13 @@ from django import forms -from django.template.loader import get_template from django.contrib.admin import widgets +from django.template.loader import get_template from .settings import ( MARTOR_ENABLE_CONFIGS, - MARTOR_UPLOAD_URL, MARTOR_MARKDOWNIFY_URL, + MARTOR_MARKDOWN_BASE_EMOJI_URL, MARTOR_SEARCH_USERS_URL, - MARTOR_MARKDOWN_BASE_EMOJI_URL + MARTOR_UPLOAD_URL, ) @@ -21,7 +21,7 @@ def render(self, name, value, attrs=None, renderer=None, **kwargs): 'data-upload-url': MARTOR_UPLOAD_URL, 'data-markdownfy-url': MARTOR_MARKDOWNIFY_URL, 'data-search-users-url': MARTOR_SEARCH_USERS_URL, - 'data-base-emoji-url': MARTOR_MARKDOWN_BASE_EMOJI_URL + 'data-base-emoji-url': MARTOR_MARKDOWN_BASE_EMOJI_URL, } # Make sure that the martor value is in the class attr passed in @@ -58,7 +58,7 @@ class Media: 'plugins/css/ace.min.css', 'plugins/css/semantic.css', 'plugins/css/resizable.min.css', - ) + ), } js = ( 'plugins/js/ace.js',