mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 08:02:54 +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 = (3, 5)
|
||||||
|
|
||||||
__version__ = "{major}.{minor}{rest}".format(
|
__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"
|
default_app_config = "dpaste.apps.dpasteAppConfig"
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
|
from logging import getLogger
|
||||||
|
|
||||||
from django.apps import AppConfig, apps
|
from django.apps import AppConfig, apps
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from logging import getLogger
|
|
||||||
|
|
||||||
log = getLogger(__file__)
|
log = getLogger(__file__)
|
||||||
|
|
||||||
|
|
||||||
class dpasteAppConfig(AppConfig):
|
class dpasteAppConfig(AppConfig):
|
||||||
name = "dpaste"
|
name = "dpaste"
|
||||||
verbose_name = "dpaste"
|
verbose_name = "dpaste"
|
||||||
|
@ -133,8 +134,8 @@ class dpasteAppConfig(AppConfig):
|
||||||
If the Highlight Class is not given, PygmentsHighlighter is used.
|
If the Highlight Class is not given, PygmentsHighlighter is used.
|
||||||
"""
|
"""
|
||||||
from dpaste.highlight import (
|
from dpaste.highlight import (
|
||||||
PlainTextHighlighter,
|
|
||||||
MarkdownHighlighter,
|
MarkdownHighlighter,
|
||||||
|
PlainTextHighlighter,
|
||||||
RestructuredTextHighlighter,
|
RestructuredTextHighlighter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,9 @@ class MarkdownHighlighter(PlainTextHighlighter):
|
||||||
|
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
misaka.html(
|
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):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
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):
|
def handle(self, *args, **options):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Settings for the testsuite runs.
|
Settings for the testsuite runs.
|
||||||
"""
|
"""
|
||||||
import django
|
|
||||||
|
|
||||||
from .base import * # noqa
|
from .base import * # noqa
|
||||||
|
|
||||||
|
|
|
@ -145,7 +145,8 @@ class SnippetAPITestCase(TestCase):
|
||||||
def test_expire_choices_invalid_given(self):
|
def test_expire_choices_invalid_given(self):
|
||||||
# A expire choice that does not exist returns a BadRequest
|
# A expire choice that does not exist returns a BadRequest
|
||||||
response = self.client.post(
|
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(response.status_code, 400)
|
||||||
self.assertEqual(Snippet.objects.count(), 0)
|
self.assertEqual(Snippet.objects.count(), 0)
|
||||||
|
@ -166,7 +167,8 @@ class SnippetAPITestCase(TestCase):
|
||||||
|
|
||||||
def test_valid_expiration_choices_never(self):
|
def test_valid_expiration_choices_never(self):
|
||||||
response = self.client.post(
|
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(response.status_code, 200)
|
||||||
self.assertEqual(Snippet.objects.count(), 1)
|
self.assertEqual(Snippet.objects.count(), 1)
|
||||||
|
@ -174,7 +176,8 @@ class SnippetAPITestCase(TestCase):
|
||||||
|
|
||||||
def test_valid_expiration_choices_hour(self):
|
def test_valid_expiration_choices_hour(self):
|
||||||
response = self.client.post(
|
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(response.status_code, 200)
|
||||||
self.assertEqual(Snippet.objects.count(), 1)
|
self.assertEqual(Snippet.objects.count(), 1)
|
||||||
|
@ -204,7 +207,11 @@ class SnippetAPITestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
self.api_url,
|
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)
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
|
|
@ -375,7 +375,9 @@ class SnippetTestCase(TestCase):
|
||||||
management.call_command("cleanup_snippets")
|
management.call_command("cleanup_snippets")
|
||||||
self.assertEqual(Snippet.objects.count(), 1)
|
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.
|
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
|
from ..views import APIView
|
||||||
|
|
||||||
urlpatterns = [
|
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 datetime
|
||||||
import difflib
|
import difflib
|
||||||
import ipaddress
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.apps import apps
|
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 django.views.generic.detail import DetailView
|
||||||
from pygments.lexers import get_lexer_for_filename
|
from pygments.lexers import get_lexer_for_filename
|
||||||
from pygments.util import ClassNotFound
|
from pygments.util import ClassNotFound
|
||||||
from ratelimit.decorators import ratelimit
|
|
||||||
from ratelimit.exceptions import Ratelimited
|
|
||||||
|
|
||||||
from dpaste import highlight
|
from dpaste import highlight
|
||||||
from dpaste.forms import SnippetForm, get_expire_values
|
from dpaste.forms import SnippetForm, get_expire_values
|
||||||
from dpaste.highlight import PygmentsHighlighter
|
from dpaste.highlight import PygmentsHighlighter
|
||||||
from dpaste.models import Snippet
|
from dpaste.models import Snippet
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
config = apps.get_app_config("dpaste")
|
config = apps.get_app_config("dpaste")
|
||||||
|
|
||||||
|
|
||||||
|
@ -343,6 +338,7 @@ class APIView(View):
|
||||||
# handle them here.
|
# handle them here.
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def handler404(request, exception=None, template_name="dpaste/404.html"):
|
def handler404(request, exception=None, template_name="dpaste/404.html"):
|
||||||
context = {}
|
context = {}
|
||||||
context.update(config.extra_template_context)
|
context.update(config.extra_template_context)
|
||||||
|
|
Loading…
Reference in a new issue