mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-11-15 16:12:51 +11:00
Use Black's default line length of 88
This commit is contained in:
parent
02a6812c80
commit
d0f7e2eda6
15 changed files with 32 additions and 90 deletions
2
Makefile
2
Makefile
|
@ -19,7 +19,7 @@ code-cleanup: ## Black and isort the Python codebase
|
||||||
autoflake --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables \
|
autoflake --remove-all-unused-imports --ignore-init-module-imports --remove-unused-variables \
|
||||||
--in-place --exclude "**/migrations/*,dpaste/settings/local.py" -r dpaste
|
--in-place --exclude "**/migrations/*,dpaste/settings/local.py" -r dpaste
|
||||||
isort -rc dpaste
|
isort -rc dpaste
|
||||||
black --line-length=80 --exclude='/(migrations)/' dpaste
|
black --exclude='/(migrations)/' dpaste
|
||||||
|
|
||||||
.PHONY: docs
|
.PHONY: docs
|
||||||
docs: ## Compile the documentation
|
docs: ## Compile the documentation
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
VERSION = (3, 5)
|
VERSION = (3, 5)
|
||||||
|
|
||||||
__version__ = "{major}.{minor}{rest}".format(
|
__version__ = "{major}.{minor}{rest}".format(
|
||||||
major=VERSION[0],
|
major=VERSION[0], minor=VERSION[1], rest="".join(str(i) for i in VERSION[2:]),
|
||||||
minor=VERSION[1],
|
|
||||||
rest="".join(str(i) for i in VERSION[2:]),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
default_app_config = "dpaste.apps.dpasteAppConfig"
|
default_app_config = "dpaste.apps.dpasteAppConfig"
|
||||||
|
|
|
@ -43,9 +43,7 @@ class dpasteAppConfig(AppConfig):
|
||||||
# String. A string of characters which are used to create the random slug.
|
# String. A string of characters which are used to create the random slug.
|
||||||
# This is intentionally missing l and I as they look too similar with
|
# This is intentionally missing l and I as they look too similar with
|
||||||
# sans-serif fonts.
|
# sans-serif fonts.
|
||||||
SLUG_CHOICES = (
|
SLUG_CHOICES = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890"
|
||||||
"abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890"
|
|
||||||
)
|
|
||||||
|
|
||||||
# String. The lexer key that is pre-selected in the dropdown. Note that
|
# String. The lexer key that is pre-selected in the dropdown. Note that
|
||||||
# this is only used if the user has not saved a snippet before, otherwise
|
# this is only used if the user has not saved a snippet before, otherwise
|
||||||
|
|
|
@ -20,18 +20,14 @@ def get_expire_values(expires):
|
||||||
else:
|
else:
|
||||||
expire_type = Snippet.EXPIRE_TIME
|
expire_type = Snippet.EXPIRE_TIME
|
||||||
expires = expires and expires or config.EXPIRE_DEFAULT
|
expires = expires and expires or config.EXPIRE_DEFAULT
|
||||||
expires = datetime.datetime.now() + datetime.timedelta(
|
expires = datetime.datetime.now() + datetime.timedelta(seconds=int(expires))
|
||||||
seconds=int(expires)
|
|
||||||
)
|
|
||||||
return expires, expire_type
|
return expires, expire_type
|
||||||
|
|
||||||
|
|
||||||
class SnippetForm(forms.ModelForm):
|
class SnippetForm(forms.ModelForm):
|
||||||
content = forms.CharField(
|
content = forms.CharField(
|
||||||
label=_("Content"),
|
label=_("Content"),
|
||||||
widget=forms.Textarea(
|
widget=forms.Textarea(attrs={"placeholder": _("Awesome code goes here...")}),
|
||||||
attrs={"placeholder": _("Awesome code goes here...")}
|
|
||||||
),
|
|
||||||
max_length=config.MAX_CONTENT_LENGTH,
|
max_length=config.MAX_CONTENT_LENGTH,
|
||||||
strip=False,
|
strip=False,
|
||||||
)
|
)
|
||||||
|
|
|
@ -77,9 +77,7 @@ class MarkdownHighlighter(PlainTextHighlighter):
|
||||||
|
|
||||||
return mark_safe(
|
return mark_safe(
|
||||||
misaka.html(
|
misaka.html(
|
||||||
code_string,
|
code_string, extensions=self.extensions, render_flags=self.render_flags,
|
||||||
extensions=self.extensions,
|
|
||||||
render_flags=self.render_flags,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--dry-run",
|
"--dry-run", action="store_true", dest="dry_run", help="Don't do anything.",
|
||||||
action="store_true",
|
|
||||||
dest="dry_run",
|
|
||||||
help="Don't do anything.",
|
|
||||||
),
|
),
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
|
@ -43,9 +40,7 @@ class Command(BaseCommand):
|
||||||
if len(deleteable_snippets) == 0:
|
if len(deleteable_snippets) == 0:
|
||||||
self.stdout.write(u"No snippets to delete.")
|
self.stdout.write(u"No snippets to delete.")
|
||||||
return None
|
return None
|
||||||
self.stdout.write(
|
self.stdout.write(u"Will delete %s snippet(s):\n" % deleteable_snippets.count())
|
||||||
u"Will delete %s snippet(s):\n" % deleteable_snippets.count()
|
|
||||||
)
|
|
||||||
|
|
||||||
for d in deleteable_snippets:
|
for d in deleteable_snippets:
|
||||||
self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires))
|
self.stdout.write(u"- %s (%s)\n" % (d.secret_id, d.expires))
|
||||||
|
|
|
@ -21,10 +21,7 @@ def generate_secret_id(length):
|
||||||
)
|
)
|
||||||
|
|
||||||
secret_id = "".join(
|
secret_id = "".join(
|
||||||
[
|
[R.choice(config.SLUG_CHOICES) for i in range(length or config.SLUG_LENGTH)]
|
||||||
R.choice(config.SLUG_CHOICES)
|
|
||||||
for i in range(length or config.SLUG_LENGTH)
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if this slug already exists, if not, return this new slug
|
# Check if this slug already exists, if not, return this new slug
|
||||||
|
@ -52,9 +49,7 @@ class Snippet(models.Model):
|
||||||
_("Secret ID"), max_length=255, blank=True, null=True, unique=True
|
_("Secret ID"), max_length=255, blank=True, null=True, unique=True
|
||||||
)
|
)
|
||||||
content = models.TextField(_("Content"))
|
content = models.TextField(_("Content"))
|
||||||
lexer = models.CharField(
|
lexer = models.CharField(_("Lexer"), max_length=30, default=highlight.LEXER_DEFAULT)
|
||||||
_("Lexer"), max_length=30, default=highlight.LEXER_DEFAULT
|
|
||||||
)
|
|
||||||
published = models.DateTimeField(_("Published"), auto_now_add=True)
|
published = models.DateTimeField(_("Published"), auto_now_add=True)
|
||||||
expire_type = models.PositiveSmallIntegerField(
|
expire_type = models.PositiveSmallIntegerField(
|
||||||
_("Expire Type"), choices=EXPIRE_CHOICES, default=EXPIRE_CHOICES[0][0]
|
_("Expire Type"), choices=EXPIRE_CHOICES, default=EXPIRE_CHOICES[0][0]
|
||||||
|
|
|
@ -39,9 +39,7 @@ LANGUAGES = (("en", "English"),)
|
||||||
# os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'locale')),
|
# os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'locale')),
|
||||||
# )
|
# )
|
||||||
|
|
||||||
STATICFILES_STORAGE = (
|
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
|
||||||
"django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
|
|
||||||
)
|
|
||||||
|
|
||||||
STATICFILES_FINDERS = (
|
STATICFILES_FINDERS = (
|
||||||
"django.contrib.staticfiles.finders.FileSystemFinder",
|
"django.contrib.staticfiles.finders.FileSystemFinder",
|
||||||
|
@ -90,9 +88,7 @@ INSTALLED_APPS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
sys.stdout.write(f"\n🐘 Database URL is: {env('DATABASE_URL')}\n")
|
sys.stdout.write(f"\n🐘 Database URL is: {env('DATABASE_URL')}\n")
|
||||||
DATABASES = {
|
DATABASES = {"default": dj_database_url.config(default="sqlite:///dpaste.sqlite")}
|
||||||
"default": dj_database_url.config(default="sqlite:///dpaste.sqlite")
|
|
||||||
}
|
|
||||||
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# App specific settings
|
# App specific settings
|
||||||
|
@ -124,9 +120,7 @@ CSP_STYLE_SRC = ("'self'", "'unsafe-inline'")
|
||||||
LOGGING = {
|
LOGGING = {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"disable_existing_loggers": False,
|
"disable_existing_loggers": False,
|
||||||
"filters": {
|
"filters": {"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}},
|
||||||
"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"}
|
|
||||||
},
|
|
||||||
"handlers": {
|
"handlers": {
|
||||||
"mail_admins": {
|
"mail_admins": {
|
||||||
"level": "ERROR",
|
"level": "ERROR",
|
||||||
|
|
|
@ -7,9 +7,7 @@ from .base import * # noqa
|
||||||
|
|
||||||
SECRET_KEY = "test-key"
|
SECRET_KEY = "test-key"
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}}
|
||||||
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Drop CSP middleware for Django 3.0 until it was fixed upstream
|
# Drop CSP middleware for Django 3.0 until it was fixed upstream
|
||||||
# https://github.com/mozilla/django-csp/issues/129
|
# https://github.com/mozilla/django-csp/issues/129
|
||||||
|
|
|
@ -145,8 +145,7 @@ 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,
|
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": "foobar"},
|
||||||
{"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)
|
||||||
|
@ -163,25 +162,19 @@ class SnippetAPITestCase(TestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(Snippet.objects.count(), 1)
|
self.assertEqual(Snippet.objects.count(), 1)
|
||||||
self.assertEqual(
|
self.assertEqual(Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_ONETIME)
|
||||||
Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_ONETIME
|
|
||||||
)
|
|
||||||
|
|
||||||
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,
|
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": "never"},
|
||||||
{"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)
|
||||||
self.assertEqual(
|
self.assertEqual(Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_KEEP)
|
||||||
Snippet.objects.all()[0].expire_type, Snippet.EXPIRE_KEEP
|
|
||||||
)
|
|
||||||
|
|
||||||
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,
|
self.api_url, {"content": u"Hello Wörld.\n\tGood Bye", "expires": 3600},
|
||||||
{"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)
|
||||||
|
@ -211,11 +204,7 @@ 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)
|
||||||
|
|
||||||
|
@ -249,9 +238,7 @@ class SnippetAPITestCase(TestCase):
|
||||||
)
|
)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(Snippet.objects.count(), 1)
|
self.assertEqual(Snippet.objects.count(), 1)
|
||||||
self.assertEqual(
|
self.assertEqual(Snippet.objects.all()[0].lexer, config.PLAIN_CODE_SYMBOL)
|
||||||
Snippet.objects.all()[0].lexer, config.PLAIN_CODE_SYMBOL
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_filename_and_lexer_given(self):
|
def test_filename_and_lexer_given(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -145,9 +145,9 @@ class SnippetTestCase(TestCase):
|
||||||
|
|
||||||
for i in range(0, 100):
|
for i in range(0, 100):
|
||||||
Snippet.objects.create(content="foobar")
|
Snippet.objects.create(content="foobar")
|
||||||
slug_list = Snippet.objects.values_list(
|
slug_list = Snippet.objects.values_list("secret_id", flat=True).order_by(
|
||||||
"secret_id", flat=True
|
"published"
|
||||||
).order_by("published")
|
)
|
||||||
|
|
||||||
# All 1001 Snippets have been created
|
# All 1001 Snippets have been created
|
||||||
self.assertEqual(len(set(slug_list)), 100)
|
self.assertEqual(len(set(slug_list)), 100)
|
||||||
|
@ -170,9 +170,7 @@ class SnippetTestCase(TestCase):
|
||||||
def test_reply(self):
|
def test_reply(self):
|
||||||
data = self.valid_form_data()
|
data = self.valid_form_data()
|
||||||
response = self.client.post(self.new_url, data, follow=True)
|
response = self.client.post(self.new_url, data, follow=True)
|
||||||
response = self.client.post(
|
response = self.client.post(response.request["PATH_INFO"], data, follow=True)
|
||||||
response.request["PATH_INFO"], data, follow=True
|
|
||||||
)
|
|
||||||
self.assertContains(response, data["content"])
|
self.assertContains(response, data["content"])
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(Snippet.objects.count(), 2)
|
self.assertEqual(Snippet.objects.count(), 2)
|
||||||
|
@ -181,9 +179,7 @@ class SnippetTestCase(TestCase):
|
||||||
data = self.valid_form_data()
|
data = self.valid_form_data()
|
||||||
response = self.client.post(self.new_url, data, follow=True)
|
response = self.client.post(self.new_url, data, follow=True)
|
||||||
del data["content"]
|
del data["content"]
|
||||||
response = self.client.post(
|
response = self.client.post(response.request["PATH_INFO"], data, follow=True)
|
||||||
response.request["PATH_INFO"], data, follow=True
|
|
||||||
)
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(Snippet.objects.count(), 1)
|
self.assertEqual(Snippet.objects.count(), 1)
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,7 @@ urlpatterns = [
|
||||||
url(
|
url(
|
||||||
r"^(?P<snippet_id>[a-zA-Z0-9]{%d,})/slim/?$" % L,
|
r"^(?P<snippet_id>[a-zA-Z0-9]{%d,})/slim/?$" % L,
|
||||||
xframe_options_exempt(
|
xframe_options_exempt(
|
||||||
views.SnippetDetailView.as_view(
|
views.SnippetDetailView.as_view(template_name="dpaste/details_slim.html")
|
||||||
template_name="dpaste/details_slim.html"
|
|
||||||
)
|
|
||||||
),
|
),
|
||||||
name="snippet_details_slim",
|
name="snippet_details_slim",
|
||||||
),
|
),
|
||||||
|
|
|
@ -4,9 +4,5 @@ from django.views.decorators.csrf import csrf_exempt
|
||||||
from ..views import APIView
|
from ..views import APIView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(
|
url(r"^api/$", csrf_exempt(APIView.as_view()), name="dpaste_api_create_snippet",)
|
||||||
r"^api/$",
|
|
||||||
csrf_exempt(APIView.as_view()),
|
|
||||||
name="dpaste_api_create_snippet",
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -84,9 +84,7 @@ class SnippetDetailView(DetailView, FormView):
|
||||||
always expire.
|
always expire.
|
||||||
"""
|
"""
|
||||||
if "delete" in self.request.POST:
|
if "delete" in self.request.POST:
|
||||||
snippet = get_object_or_404(
|
snippet = get_object_or_404(Snippet, secret_id=self.kwargs["snippet_id"])
|
||||||
Snippet, secret_id=self.kwargs["snippet_id"]
|
|
||||||
)
|
|
||||||
snippet.delete()
|
snippet.delete()
|
||||||
|
|
||||||
# Append `#` so #delete goes away in Firefox
|
# Append `#` so #delete goes away in Firefox
|
||||||
|
@ -330,16 +328,11 @@ class APIView(View):
|
||||||
)
|
)
|
||||||
expires, expire_type = get_expire_values(expires)
|
expires, expire_type = get_expire_values(expires)
|
||||||
else:
|
else:
|
||||||
expires = datetime.datetime.now() + datetime.timedelta(
|
expires = datetime.datetime.now() + datetime.timedelta(seconds=60 * 60 * 24)
|
||||||
seconds=60 * 60 * 24
|
|
||||||
)
|
|
||||||
expire_type = Snippet.EXPIRE_TIME
|
expire_type = Snippet.EXPIRE_TIME
|
||||||
|
|
||||||
snippet = Snippet.objects.create(
|
snippet = Snippet.objects.create(
|
||||||
content=content,
|
content=content, lexer=lexer, expires=expires, expire_type=expire_type,
|
||||||
lexer=lexer,
|
|
||||||
expires=expires,
|
|
||||||
expire_type=expire_type,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Custom formatter for the API response
|
# Custom formatter for the API response
|
||||||
|
|
|
@ -75,7 +75,7 @@ multi_line_output=3
|
||||||
include_trailing_comma=True
|
include_trailing_comma=True
|
||||||
force_grid_wrap=0
|
force_grid_wrap=0
|
||||||
use_parentheses=True
|
use_parentheses=True
|
||||||
line_length=80
|
line_length=88
|
||||||
|
|
||||||
[coverage:run]
|
[coverage:run]
|
||||||
source = dpaste
|
source = dpaste
|
||||||
|
|
Loading…
Reference in a new issue