Skip to content

Commit 13fa248

Browse files
authored
Merge pull request #35 from RSE-Sheffield/feat/lint
Add automatic Python code formatting
2 parents 6b1fbf5 + 8a57d43 commit 13fa248

File tree

23 files changed

+265
-175
lines changed

23 files changed

+265
-175
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://flake8.pycqa.org/en/latest/user/configuration.html
2+
[flake8]
3+
max-line-length = 120

.github/workflows/lint-python.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint Python code
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
lint:
8+
runs-on: ubuntu-24.04
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
- name: Install linters
13+
run: pip install black flake8
14+
- name: Lint Python code
15+
run: |
16+
dirs="SORT home survey invites"
17+
black $dirs
18+
flake8 $dirs
19+
# Suggest merging any changes
20+
- name: Create Pull Request
21+
# https://github.com/marketplace/actions/create-pull-request
22+
uses: peter-evans/create-pull-request@v7
23+
with:
24+
body: "Python code reformatted with black and isort"
25+
branch: "chore/python-formatting"

SORT/settings.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
https://docs.djangoproject.com/en/5.1/ref/settings/
1111
"""
1212

13+
import os
1314
from pathlib import Path
15+
1416
from dotenv import load_dotenv
15-
import os
1617

1718
load_dotenv() # Load environment variables from .env file
1819

@@ -24,7 +25,7 @@
2425
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
2526

2627
# SECURITY WARNING: keep the secret key used in production secret!
27-
SECRET_KEY = os.getenv('DJANGO_SECRET_KEY')
28+
SECRET_KEY = os.getenv("DJANGO_SECRET_KEY")
2829

2930
# SECURITY WARNING: don't run with debug turned on in production!
3031
DEBUG = True
@@ -43,10 +44,8 @@
4344
"django.contrib.staticfiles",
4445
"django_bootstrap5",
4546
"django_extensions",
46-
'debug_toolbar',
47-
47+
"debug_toolbar",
4848
# apps created by FA:
49-
5049
"home",
5150
"survey",
5251
"invites",
@@ -60,16 +59,15 @@
6059
"django.contrib.auth.middleware.AuthenticationMiddleware",
6160
"django.contrib.messages.middleware.MessageMiddleware",
6261
"django.middleware.clickjacking.XFrameOptionsMiddleware",
63-
'debug_toolbar.middleware.DebugToolbarMiddleware'
62+
"debug_toolbar.middleware.DebugToolbarMiddleware",
6463
]
6564

6665
ROOT_URLCONF = "SORT.urls"
6766

6867
TEMPLATES = [
6968
{
7069
"BACKEND": "django.template.backends.django.DjangoTemplates",
71-
"DIRS": [BASE_DIR / 'static/templates']
72-
,
70+
"DIRS": [BASE_DIR / "static/templates"],
7371
"APP_DIRS": True,
7472
"OPTIONS": {
7573
"context_processors": [
@@ -91,7 +89,7 @@
9189
DATABASES = {
9290
"default": {
9391
"ENGINE": "django.db.backends.sqlite3",
94-
"NAME": BASE_DIR / 'db.sqlite3',
92+
"NAME": BASE_DIR / "db.sqlite3",
9593
# "NAME": os.getenv("DB_NAME"),
9694
# "USER": os.getenv("DB_USER"),
9795
# "PASSWORD": os.getenv("DB_PASSWORD"),
@@ -136,8 +134,7 @@
136134

137135
STATIC_URL = "static/"
138136

139-
STATICFILES_DIRS = [BASE_DIR / 'static']
140-
137+
STATICFILES_DIRS = [BASE_DIR / "static"]
141138

142139

143140
# Default primary key field type
@@ -155,15 +152,13 @@
155152
# FA: 30 minutes before automatic log out
156153
SESSION_COOKIE_AGE = 1800
157154

158-
PASSWORD_RESET_TIMEOUT = 1800 # FA: default to expire after 30 minutes
155+
PASSWORD_RESET_TIMEOUT = 1800 # FA: default to expire after 30 minutes
159156

160157
# FA: for local testing emails:
161158

162-
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
159+
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
163160

164-
AUTHENTICATION_BACKENDS = (
165-
'django.contrib.auth.backends.ModelBackend',
166-
)
161+
AUTHENTICATION_BACKENDS = ("django.contrib.auth.backends.ModelBackend",)
167162

168163
# For django-debug-toolbar
169164
INTERNAL_IPS = [
@@ -174,5 +169,4 @@
174169

175170
# FA: for production:
176171

177-
#EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
178-
172+
# EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

SORT/urls.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
1. Import the include() function: from django.urls import include, path
1515
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1616
"""
17+
1718
from django.conf import settings
1819
from django.contrib import admin
19-
from django.urls import path, include
20+
from django.urls import include, path
2021

2122
urlpatterns = [
2223
path("admin/", admin.site.urls),
@@ -25,6 +26,7 @@
2526

2627
if settings.DEBUG:
2728
import debug_toolbar
29+
2830
urlpatterns += [
29-
path('__debug__/', include(debug_toolbar.urls)),
30-
]
31+
path("__debug__/", include(debug_toolbar.urls)),
32+
]

home/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from django.contrib import admin
1+
# from django.contrib import admin
22

33
# Register your models here.

home/forms.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
from django import forms
2-
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordResetForm
3-
from django.core.exceptions import ValidationError
2+
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
43
from django.contrib.auth.models import User
4+
from django.core.exceptions import ValidationError
55

66

77
class ManagerSignupForm(UserCreationForm):
8-
email = forms.EmailField(required=True, label='Email', error_messages={'required': 'Email is required.'})
9-
8+
email = forms.EmailField(
9+
required=True, label="Email", error_messages={"required": "Email is required."}
10+
)
1011

1112
class Meta:
1213
model = User
13-
fields = ('email', 'password1', 'password2')
14+
fields = ("email", "password1", "password2")
1415

1516
def clean_email(self):
16-
email = self.cleaned_data.get('email')
17+
email = self.cleaned_data.get("email")
1718
if User.objects.filter(email=email).exists():
1819
raise ValidationError("This email is already registered.")
1920
return email
2021

2122
def save(self, commit=True):
2223
user = super().save(commit=False)
23-
user.email = self.cleaned_data['email']
24+
user.email = self.cleaned_data["email"]
2425
user.username = user.email
2526
if commit:
2627
user.save()
2728
return user
2829

2930

3031
class ManagerLoginForm(AuthenticationForm):
31-
username = forms.EmailField(label='Email', max_length=60, widget=forms.EmailInput(attrs={'autofocus': True}))
32+
username = forms.EmailField(
33+
label="Email", max_length=60, widget=forms.EmailInput(attrs={"autofocus": True})
34+
)
3235

3336
class Meta:
3437
model = AuthenticationForm
35-
fields = ['username', 'password']
38+
fields = ["username", "password"]
3639

3740

3841
class UserProfileForm(forms.ModelForm):
3942
class Meta:
4043
model = User
41-
fields = ['email', 'first_name', 'last_name']
44+
fields = ["email", "first_name", "last_name"]
4245

4346
def clean_email(self):
44-
email = self.cleaned_data.get('email')
47+
email = self.cleaned_data.get("email")
4548

4649
if User.objects.exclude(pk=self.instance.pk).filter(email=email).exists():
4750
raise forms.ValidationError("This email is already in use.")
@@ -51,4 +54,4 @@ def save(self, commit=True):
5154
user = super().save(commit=False)
5255
if commit:
5356
user.save()
54-
return user
57+
return user

home/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from django.db import models
1+
# from django.db import models
22

33
# Create your models here.

home/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from django.test import TestCase
1+
# from django.test import TestCase
22

33
# Create your tests here.

home/urls.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
__author__ = "Farhad Allian"
22

3-
from django.urls import path, include
3+
from django.urls import include, path
4+
45
from . import views
56

67
urlpatterns = [
7-
path('', views.HomeView.as_view(), name='home'),
8-
path('login/', views.LoginInterfaceView.as_view(), name='login'),
9-
path('logout/', views.LogoutInterfaceView.as_view(), name='logout'),
10-
path('signup/', views.SignupView.as_view(), name='signup'),
11-
path('', include('survey.urls'), name='survey'),
12-
path('invite/', include('invites.urls'), name='invites'),
13-
path('profile/', views.ProfileView.as_view(), name='profile'),
14-
path('password_reset/', views.CustomPasswordResetView.as_view(), name='password_reset'),
15-
path('password_reset/done/', views.CustomPasswordResetDoneView.as_view(), name='password_reset_done'),
16-
path('reset/<uidb64>/<token>/', views.CustomPasswordResetConfirmView.as_view(), name='password_reset_confirm'),
17-
path('reset/done/', views.CustomPasswordResetCompleteView.as_view(), name='password_reset_complete'),
18-
#path('password_reset/expired/', views.PasswordResetExpiredView.as_view(), name='password_reset_expired'),
19-
20-
]
8+
path("", views.HomeView.as_view(), name="home"),
9+
path("login/", views.LoginInterfaceView.as_view(), name="login"),
10+
path("logout/", views.LogoutInterfaceView.as_view(), name="logout"),
11+
path("signup/", views.SignupView.as_view(), name="signup"),
12+
path("", include("survey.urls"), name="survey"),
13+
path("invite/", include("invites.urls"), name="invites"),
14+
path("profile/", views.ProfileView.as_view(), name="profile"),
15+
path(
16+
"password_reset/",
17+
views.CustomPasswordResetView.as_view(),
18+
name="password_reset",
19+
),
20+
path(
21+
"password_reset/done/",
22+
views.CustomPasswordResetDoneView.as_view(),
23+
name="password_reset_done",
24+
),
25+
path(
26+
"reset/<uidb64>/<token>/",
27+
views.CustomPasswordResetConfirmView.as_view(),
28+
name="password_reset_confirm",
29+
),
30+
path(
31+
"reset/done/",
32+
views.CustomPasswordResetCompleteView.as_view(),
33+
name="password_reset_complete",
34+
),
35+
# path('password_reset/expired/', views.PasswordResetExpiredView.as_view(), name='password_reset_expired'),
36+
]

0 commit comments

Comments
 (0)