Skip to content

Commit 46fdaf3

Browse files
committed
Improve error handling, update style, update deps
1 parent d14a8e6 commit 46fdaf3

20 files changed

+410
-255
lines changed

.flake8

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
[flake8]
2-
max-line-length = 119
3-
exclude =
4-
.git,
2+
extend-exclude =
53
migrations,
64
static,
75
staticfiles,
86
templates,
7+
max-line-length = 79

Pipfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ url = "https://pypi.org/simple"
44
verify_ssl = true
55

66
[dev-packages]
7-
black = "==19.10b0"
7+
black = "==20.8b1"
88
flake8 = "*"
99
factory-boy = "*"
10+
isort = "*"
1011

1112
[packages]
1213
django = "~=3.0"

Pipfile.lock

+238-176
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ After made code changes and before commit, check code style from main directory
140140

141141
After making changes in code and before commit, check code style.
142142
```shell
143+
pipenv run isort .
143144
pipenv run black .
144-
pipenv run flake8
145+
pipenv run flake8 .
145146
```
146147

147148

caselaw/asgi.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
88
"""
99

10+
# Standard library
1011
import os
1112

13+
# Third-party
1214
from django.core.asgi import get_asgi_application
1315

1416
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "caselaw.settings")

caselaw/settings.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
https://docs.djangoproject.com/en/3.0/ref/settings/
1111
"""
1212

13+
# Standard library
1314
import os
14-
import django_heroku
1515
from distutils.util import strtobool
1616

17+
# Third-party
18+
import django_heroku
19+
1720
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
1821
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1922

@@ -25,7 +28,9 @@
2528
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY")
2629

2730
# SECURITY WARNING: don't run with debug turned on in production!
28-
DEBUG = bool(strtobool(str(os.environ.get("DJANGO_DEBUG_ENABLED", default=False))))
31+
DEBUG = bool(
32+
strtobool(str(os.environ.get("DJANGO_DEBUG_ENABLED", default=False)))
33+
)
2934

3035
ALLOWED_HOSTS = ["localhost", "127.0.0.1"]
3136

@@ -95,7 +100,7 @@
95100
}
96101
}
97102

98-
# See https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
103+
# See https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables # noqa: E501
99104

100105
if "GITHUB_WORKFLOW" in os.environ:
101106
SECRET_KEY = "cbo9e7%1c^ijxoit37^!kbfyikaet%z&*pm&4k(3#h*k%irylt"
@@ -115,13 +120,12 @@
115120
# Password validation
116121
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
117122

123+
_auth_pass_valid = "django.contrib.auth.password_validation"
118124
AUTH_PASSWORD_VALIDATORS = [
119-
{
120-
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
121-
},
122-
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
123-
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
124-
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
125+
{"NAME": f"{_auth_pass_valid}.UserAttributeSimilarityValidator"},
126+
{"NAME": f"{_auth_pass_valid}.MinimumLengthValidator"},
127+
{"NAME": f"{_auth_pass_valid}.CommonPasswordValidator"},
128+
{"NAME": f"{_auth_pass_valid}.NumericPasswordValidator"},
125129
]
126130

127131

@@ -149,7 +153,11 @@
149153
},
150154
},
151155
"loggers": {
152-
"django": {"handlers": ["console"], "level": "DEBUG", "propagate": True},
156+
"django": {
157+
"handlers": ["console"],
158+
"level": "DEBUG",
159+
"propagate": True,
160+
},
153161
"django.request": {
154162
"handlers": ["console"],
155163
"level": "DEBUG",
@@ -190,9 +198,13 @@
190198

191199
COMPRESS_PRECOMPILERS = (("text/x-scss", "django_libsass.SassCompiler"),)
192200

193-
COMPRESS_ENABLED = bool(strtobool(str(os.environ.get("DJANGO_COMPRESS_ENABLED", True))))
201+
COMPRESS_ENABLED = bool(
202+
strtobool(str(os.environ.get("DJANGO_COMPRESS_ENABLED", True)))
203+
)
194204

195-
COMPRESS_OFFLINE = bool(strtobool(str(os.environ.get("DJANGO_COMPRESS_OFFLINE", True))))
205+
COMPRESS_OFFLINE = bool(
206+
strtobool(str(os.environ.get("DJANGO_COMPRESS_OFFLINE", True)))
207+
)
196208

197209
LIBSASS_OUTPUT_STYLE = os.environ.get("DJANGO_LIBSASS_STYLE", "compressed")
198210

caselaw/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1. Import the include() function: from django.urls import include, path
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
16+
# Third-party
1617
from django.conf.urls import url
1718
from django.contrib import admin
1819
from django.urls import include, path

caselaw/wsgi.py

+2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
88
"""
99

10+
# Standard library
1011
import os
1112

13+
# Third-party
1214
from django.core.wsgi import get_wsgi_application
1315

1416
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "caselaw.settings")

legal_db/admin.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# Third-party
12
from django.contrib import admin
2-
33
from ordered_model.admin import OrderedModelAdmin
44

5-
from .models import Case, FAQ, Link, Scholarship
5+
from .models import FAQ, Case, Link, Scholarship
66

77

88
class CaseAdmin(admin.ModelAdmin):
@@ -27,7 +27,13 @@ class CaseAdmin(admin.ModelAdmin):
2727
# Customize the list
2828
list_display = ("name", "license", "status", "updated_at")
2929
list_filter = ["status", "license"]
30-
search_fields = ("name", "courts", "related_cases", "background", "summary")
30+
search_fields = (
31+
"name",
32+
"courts",
33+
"related_cases",
34+
"background",
35+
"summary",
36+
)
3137

3238

3339
class LinkAdmin(admin.ModelAdmin):

legal_db/apps.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Third-party
12
from django.apps import AppConfig
23

34

legal_db/factories.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Third-party
12
import factory
23
from factory.django import DjangoModelFactory
34

legal_db/forms.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Third-party
12
from django.forms import (
23
BooleanField,
34
CharField,

legal_db/migrations/0001_initial.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Generated by Django 3.0.8 on 2020-07-31 20:35
22

3-
from django.db import migrations, models
3+
# Third-party
44
import django.db.models.deletion
55
import django_countries.fields
66
import markdownx.models
77
import taggit.managers
8+
from django.db import migrations, models
89

910

1011
class Migration(migrations.Migration):

legal_db/models.py

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
# Third-party
12
from django.db import models
23
from django.utils.translation import gettext_lazy as _
3-
44
from django_countries.fields import CountryField
55
from markdownx.models import MarkdownxField
66
from ordered_model.models import OrderedModel
@@ -12,7 +12,8 @@ class BaseModel(models.Model):
1212
blank=True, null=True, help_text="Internal notes or description."
1313
)
1414
created_at = models.DateTimeField(
15-
auto_now_add=True, help_text="A timestamp of when the object is first created."
15+
auto_now_add=True,
16+
help_text="A timestamp of when the object is first created.",
1617
)
1718
updated_at = models.DateTimeField(
1819
auto_now=True,
@@ -24,13 +25,16 @@ class Meta:
2425

2526

2627
class LegalResource(BaseModel):
27-
"""Abstract Class to contain the commons attributes of Cases and Scholarship"""
28+
"""
29+
Abstract Class to contain the commons attributes of Cases and Scholarship
30+
"""
2831

2932
license = models.CharField(
3033
max_length=50,
3134
blank=True,
3235
null=True,
33-
help_text="The Creative Commons licence associated to the legal resource.",
36+
help_text="The Creative Commons licence associated to the legal"
37+
" resource.",
3438
)
3539
contributor_name = models.CharField(max_length=120)
3640
contributor_email = models.EmailField()
@@ -67,42 +71,47 @@ class Case(LegalResource):
6771
max_length=200,
6872
blank=True,
6973
null=True,
70-
help_text="If there are multiple lawsuits between the parties, please just "
71-
"include one here and note the others in the related cases field.",
74+
help_text="If there are multiple lawsuits between the parties, please"
75+
" just include one here and note the others in the related cases"
76+
" field.",
7277
)
7378
related_cases = models.CharField(
7479
max_length=255,
7580
blank=True,
7681
null=True,
77-
help_text="If there are multiple lawsuits between the parties in this dispute, "
78-
"please note additional cases here.",
82+
help_text="If there are multiple lawsuits between the parties in this"
83+
" dispute, please note additional cases here.",
84+
)
85+
country = CountryField(
86+
blank_label="Select a country", blank=True, null=True
7987
)
80-
country = CountryField(blank_label="Select a country", blank=True, null=True)
8188
courts = models.CharField(
8289
max_length=255,
8390
blank=True,
8491
null=True,
85-
help_text="The original court name and/or English translation. If the lawsuit "
86-
"was filed in one court and then went to another court on appeal, please note "
87-
"all relevant courts here.",
92+
help_text="The original court name and/or English translation. If the"
93+
" lawsuit was filed in one court and then went to another court on"
94+
" appeal, please note all relevant courts here.",
8895
)
8996
background = models.TextField(
9097
blank=True,
9198
null=True,
92-
help_text="Describe the factual information that led to the lawsuit "
93-
"being filed, and explain what claims were filed in the lawsuit.",
99+
help_text="Describe the factual information that led to the lawsuit"
100+
" being filed, and explain what claims were filed in the lawsuit.",
94101
)
95102
decision_year = models.PositiveSmallIntegerField(
96103
blank=True, null=True, help_text="Year of case resolution."
97104
)
98105
is_pending = models.BooleanField(
99-
blank=True, null=True, help_text="Indicate if is an ongoing case or not."
106+
blank=True,
107+
null=True,
108+
help_text="Indicate if is an ongoing case or not.",
100109
)
101110
links = models.ManyToManyField(
102111
Link,
103-
help_text="Include any links to pleadings, briefs, and opinions in the "
104-
"lawsuit, as well as blog posts, academic articles, or other relevant "
105-
"materials.",
112+
help_text="Include any links to pleadings, briefs, and opinions in the"
113+
" lawsuit, as well as blog posts, academic articles, or other relevant"
114+
" materials.",
106115
)
107116

108117
def __str__(self):

legal_db/templatetags/markdown_extras.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
# Third-party
2+
import markdown as md
13
from django import template
24
from django.template.defaultfilters import stringfilter
35

4-
import markdown as md
5-
66
register = template.Library()
77

88

0 commit comments

Comments
 (0)