mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-23 03:46:37 +11:00
Code cleanup
This commit is contained in:
parent
49ca2d7631
commit
adc8573134
9 changed files with 34 additions and 18 deletions
|
@ -1,7 +1,9 @@
|
|||
VERSION = (3, 5)
|
||||
|
||||
__version__ = "{major}.{minor}{rest}".format(
|
||||
major=VERSION[0], minor=VERSION[1], rest="".join(str(i) for i in VERSION[2:]),
|
||||
major=VERSION[0],
|
||||
minor=VERSION[1],
|
||||
rest="".join(str(i) for i in VERSION[2:]),
|
||||
)
|
||||
|
||||
default_app_config = "dpaste.apps.dpasteAppConfig"
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from logging import getLogger
|
||||
|
||||
from django.apps import AppConfig, apps
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from logging import getLogger
|
||||
|
||||
log = getLogger(__file__)
|
||||
|
||||
|
||||
class dpasteAppConfig(AppConfig):
|
||||
name = "dpaste"
|
||||
verbose_name = "dpaste"
|
||||
|
@ -133,8 +134,8 @@ class dpasteAppConfig(AppConfig):
|
|||
If the Highlight Class is not given, PygmentsHighlighter is used.
|
||||
"""
|
||||
from dpaste.highlight import (
|
||||
PlainTextHighlighter,
|
||||
MarkdownHighlighter,
|
||||
PlainTextHighlighter,
|
||||
RestructuredTextHighlighter,
|
||||
)
|
||||
|
||||
|
|
|
@ -77,7 +77,9 @@ class MarkdownHighlighter(PlainTextHighlighter):
|
|||
|
||||
return mark_safe(
|
||||
misaka.html(
|
||||
code_string, extensions=self.extensions, render_flags=self.render_flags,
|
||||
code_string,
|
||||
extensions=self.extensions,
|
||||
render_flags=self.render_flags,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -14,7 +14,10 @@ class Command(BaseCommand):
|
|||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
"--dry-run", action="store_true", dest="dry_run", help="Don't do anything.",
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
dest="dry_run",
|
||||
help="Don't do anything.",
|
||||
),
|
||||
|
||||
def handle(self, *args, **options):
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""
|
||||
Settings for the testsuite runs.
|
||||
"""
|
||||
import django
|
||||
|
||||
from .base import * # noqa
|
||||
|
||||
|
|
|
@ -145,7 +145,8 @@ class SnippetAPITestCase(TestCase):
|
|||
def test_expire_choices_invalid_given(self):
|
||||
# A expire choice that does not exist returns a BadRequest
|
||||
response = self.client.post(
|
||||
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": "foobar"},
|
||||
self.api_url,
|
||||
{"content": u"Hello Wörld.\n\tGood Bye", "expires": "foobar"},
|
||||
)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(Snippet.objects.count(), 0)
|
||||
|
@ -166,7 +167,8 @@ class SnippetAPITestCase(TestCase):
|
|||
|
||||
def test_valid_expiration_choices_never(self):
|
||||
response = self.client.post(
|
||||
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": "never"},
|
||||
self.api_url,
|
||||
{"content": u"Hello Wörld.\n\tGood Bye", "expires": "never"},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 1)
|
||||
|
@ -174,7 +176,8 @@ class SnippetAPITestCase(TestCase):
|
|||
|
||||
def test_valid_expiration_choices_hour(self):
|
||||
response = self.client.post(
|
||||
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": 3600},
|
||||
self.api_url,
|
||||
{"content": u"Hello Wörld.\n\tGood Bye", "expires": 3600},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 1)
|
||||
|
@ -204,7 +207,11 @@ class SnippetAPITestCase(TestCase):
|
|||
"""
|
||||
response = self.client.post(
|
||||
self.api_url,
|
||||
{"content": u"Hello Wörld.\n\tGood Bye", "lexer": "", "filename": "",},
|
||||
{
|
||||
"content": u"Hello Wörld.\n\tGood Bye",
|
||||
"lexer": "",
|
||||
"filename": "",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
|
|
|
@ -375,7 +375,9 @@ class SnippetTestCase(TestCase):
|
|||
management.call_command("cleanup_snippets")
|
||||
self.assertEqual(Snippet.objects.count(), 1)
|
||||
|
||||
def test_delete_management_snippet_never_expires_not_get_deleted(self,):
|
||||
def test_delete_management_snippet_never_expires_not_get_deleted(
|
||||
self,
|
||||
):
|
||||
"""
|
||||
Snippets without an expiration date wont get deleted automatically.
|
||||
"""
|
||||
|
|
|
@ -4,5 +4,9 @@ from django.views.decorators.csrf import csrf_exempt
|
|||
from ..views import APIView
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r"^api/$", csrf_exempt(APIView.as_view()), name="dpaste_api_create_snippet",)
|
||||
re_path(
|
||||
r"^api/$",
|
||||
csrf_exempt(APIView.as_view()),
|
||||
name="dpaste_api_create_snippet",
|
||||
)
|
||||
]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import datetime
|
||||
import difflib
|
||||
import ipaddress
|
||||
import json
|
||||
|
||||
from django.apps import apps
|
||||
|
@ -21,16 +20,12 @@ from django.views.generic.base import TemplateView, View
|
|||
from django.views.generic.detail import DetailView
|
||||
from pygments.lexers import get_lexer_for_filename
|
||||
from pygments.util import ClassNotFound
|
||||
from ratelimit.decorators import ratelimit
|
||||
from ratelimit.exceptions import Ratelimited
|
||||
|
||||
from dpaste import highlight
|
||||
from dpaste.forms import SnippetForm, get_expire_values
|
||||
from dpaste.highlight import PygmentsHighlighter
|
||||
from dpaste.models import Snippet
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
config = apps.get_app_config("dpaste")
|
||||
|
||||
|
||||
|
@ -343,6 +338,7 @@ class APIView(View):
|
|||
# handle them here.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
def handler404(request, exception=None, template_name="dpaste/404.html"):
|
||||
context = {}
|
||||
context.update(config.extra_template_context)
|
||||
|
|
Loading…
Reference in a new issue