Skip to content

Commit fc09142

Browse files
committed
Format all project files with black
1 parent 5a6a1bd commit fc09142

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+503
-388
lines changed

.github/workflows/pythonapp.yml

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ jobs:
1919
run: |
2020
python -m pip install --upgrade pip
2121
pip install -r requirements.txt
22+
- name: Run black code formatter
23+
run: |
24+
black --check --force-exclude=./*/migrations/ ./
2225
- name: Django Testing project
2326
run: |
2427
python manage.py collectstatic

accounts/api/custom_claims.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def get_token(cls, user):
1010
token = super(MyTokenObtainPairSerializer, cls).get_token(user)
1111

1212
# Add custom claims
13-
token['user'] = UserSerializer(user, many=False).data
13+
token["user"] = UserSerializer(user, many=False).data
1414

1515
return token
1616

accounts/api/serializers.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,30 @@
55

66
class UserSerializer(serializers.ModelSerializer):
77
def __init__(self, *args, **kwargs):
8-
kwargs['partial'] = True
8+
kwargs["partial"] = True
99
super(UserSerializer, self).__init__(*args, **kwargs)
1010

1111
class Meta:
1212
model = User
1313
# fields = "__all__"
14-
exclude = ("password", "user_permissions", "groups", "is_staff", "is_active", "is_superuser", "last_login")
14+
exclude = (
15+
"password",
16+
"user_permissions",
17+
"groups",
18+
"is_staff",
19+
"is_active",
20+
"is_superuser",
21+
"last_login",
22+
)
1523

1624

1725
class UserCreateSerializer(serializers.ModelSerializer):
18-
password = serializers.CharField(write_only=True, required=True, style={
19-
"input_type": "password"})
26+
password = serializers.CharField(
27+
write_only=True, required=True, style={"input_type": "password"}
28+
)
2029
password2 = serializers.CharField(
21-
style={"input_type": "password"}, write_only=True, label="Confirm password")
30+
style={"input_type": "password"}, write_only=True, label="Confirm password"
31+
)
2232

2333
class Meta:
2434
model = User
@@ -39,10 +49,10 @@ def create(self, validated_data):
3949
role = validated_data["role"]
4050
if email and User.objects.filter(email=email).exists():
4151
raise serializers.ValidationError(
42-
{"email": "Email addresses must be unique."})
52+
{"email": "Email addresses must be unique."}
53+
)
4354
if password != password2:
44-
raise serializers.ValidationError(
45-
{"password": "The two passwords differ."})
55+
raise serializers.ValidationError({"password": "The two passwords differ."})
4656
user = User(email=email, gender=gender, role=role)
4757
user.set_password(password)
4858
user.save()

accounts/api/urls.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@
1010
urlpatterns = [
1111
# path('login/', TokenObtainPairView.as_view()),
1212
path("register/", registration, name="register"),
13-
path('login/', MyTokenObtainPairView.as_view()),
14-
path('token/refresh/', TokenRefreshView.as_view()),
15-
16-
path('employee/', include([
17-
path('profile/', EditEmployeeProfileAPIView.as_view(), name='employee-profile'),
18-
])),
13+
path("login/", MyTokenObtainPairView.as_view()),
14+
path("token/refresh/", TokenRefreshView.as_view()),
15+
path(
16+
"employee/",
17+
include(
18+
[
19+
path(
20+
"profile/",
21+
EditEmployeeProfileAPIView.as_view(),
22+
name="employee-profile",
23+
),
24+
]
25+
),
26+
),
1927
]

accounts/api/views.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ def registration(request):
1919
user = serializer.save()
2020
res = {
2121
"status": True,
22-
"message": 'Successfully registered',
22+
"message": "Successfully registered",
2323
}
2424
return response.Response(res, status.HTTP_201_CREATED)
2525

2626

2727
class EditEmployeeProfileAPIView(RetrieveUpdateAPIView):
2828
serializer_class = UserSerializer
29-
http_method_names = ['get', 'put']
29+
http_method_names = ["get", "put"]
3030
permission_classes = [IsAuthenticated, IsEmployee]
3131

3232
def get_object(self):

accounts/apps.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
class AccountsConfig(AppConfig):
5-
name = 'accounts'
5+
name = "accounts"

accounts/forms.py

+60-59
Original file line numberDiff line numberDiff line change
@@ -4,69 +4,72 @@
44

55
from accounts.models import User
66

7-
GENDER_CHOICES = (
8-
('male', 'Male'),
9-
('female', 'Female'))
7+
GENDER_CHOICES = (("male", "Male"), ("female", "Female"))
108

119

1210
class EmployeeRegistrationForm(UserCreationForm):
1311
# gender = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, choices=GENDER_CHOICES)
1412

1513
def __init__(self, *args, **kwargs):
1614
super(EmployeeRegistrationForm, self).__init__(*args, **kwargs)
17-
self.fields['gender'].required = True
18-
self.fields['first_name'].label = "First Name"
19-
self.fields['last_name'].label = "Last Name"
20-
self.fields['password1'].label = "Password"
21-
self.fields['password2'].label = "Confirm Password"
15+
self.fields["gender"].required = True
16+
self.fields["first_name"].label = "First Name"
17+
self.fields["last_name"].label = "Last Name"
18+
self.fields["password1"].label = "Password"
19+
self.fields["password2"].label = "Confirm Password"
2220

2321
# self.fields['gender'].widget = forms.CheckboxInput()
2422

25-
self.fields['first_name'].widget.attrs.update(
23+
self.fields["first_name"].widget.attrs.update(
2624
{
27-
'placeholder': 'Enter First Name',
25+
"placeholder": "Enter First Name",
2826
}
2927
)
30-
self.fields['last_name'].widget.attrs.update(
28+
self.fields["last_name"].widget.attrs.update(
3129
{
32-
'placeholder': 'Enter Last Name',
30+
"placeholder": "Enter Last Name",
3331
}
3432
)
35-
self.fields['email'].widget.attrs.update(
33+
self.fields["email"].widget.attrs.update(
3634
{
37-
'placeholder': 'Enter Email',
35+
"placeholder": "Enter Email",
3836
}
3937
)
40-
self.fields['password1'].widget.attrs.update(
38+
self.fields["password1"].widget.attrs.update(
4139
{
42-
'placeholder': 'Enter Password',
40+
"placeholder": "Enter Password",
4341
}
4442
)
45-
self.fields['password2'].widget.attrs.update(
43+
self.fields["password2"].widget.attrs.update(
4644
{
47-
'placeholder': 'Confirm Password',
45+
"placeholder": "Confirm Password",
4846
}
4947
)
5048

5149
class Meta:
5250
model = User
53-
fields = ['first_name', 'last_name', 'email', 'password1', 'password2', 'gender']
51+
fields = [
52+
"first_name",
53+
"last_name",
54+
"email",
55+
"password1",
56+
"password2",
57+
"gender",
58+
]
5459
error_messages = {
55-
'first_name': {
56-
'required': 'First name is required',
57-
'max_length': 'Name is too long'
60+
"first_name": {
61+
"required": "First name is required",
62+
"max_length": "Name is too long",
5863
},
59-
'last_name': {
60-
'required': 'Last name is required',
61-
'max_length': 'Last Name is too long'
64+
"last_name": {
65+
"required": "Last name is required",
66+
"max_length": "Last Name is too long",
6267
},
63-
'gender': {
64-
'required': 'Gender is required'
65-
}
68+
"gender": {"required": "Gender is required"},
6669
}
6770

6871
def clean_gender(self):
69-
gender = self.cleaned_data.get('gender')
72+
gender = self.cleaned_data.get("gender")
7073
if not gender:
7174
raise forms.ValidationError("Gender is required")
7275
return gender
@@ -80,52 +83,51 @@ def save(self, commit=True):
8083

8184

8285
class EmployerRegistrationForm(UserCreationForm):
83-
8486
def __init__(self, *args, **kwargs):
8587
super(EmployerRegistrationForm, self).__init__(*args, **kwargs)
86-
self.fields['first_name'].label = "Company Name"
87-
self.fields['last_name'].label = "Company Address"
88-
self.fields['password1'].label = "Password"
89-
self.fields['password2'].label = "Confirm Password"
88+
self.fields["first_name"].label = "Company Name"
89+
self.fields["last_name"].label = "Company Address"
90+
self.fields["password1"].label = "Password"
91+
self.fields["password2"].label = "Confirm Password"
9092

91-
self.fields['first_name'].widget.attrs.update(
93+
self.fields["first_name"].widget.attrs.update(
9294
{
93-
'placeholder': 'Enter Company Name',
95+
"placeholder": "Enter Company Name",
9496
}
9597
)
96-
self.fields['last_name'].widget.attrs.update(
98+
self.fields["last_name"].widget.attrs.update(
9799
{
98-
'placeholder': 'Enter Company Address',
100+
"placeholder": "Enter Company Address",
99101
}
100102
)
101-
self.fields['email'].widget.attrs.update(
103+
self.fields["email"].widget.attrs.update(
102104
{
103-
'placeholder': 'Enter Email',
105+
"placeholder": "Enter Email",
104106
}
105107
)
106-
self.fields['password1'].widget.attrs.update(
108+
self.fields["password1"].widget.attrs.update(
107109
{
108-
'placeholder': 'Enter Password',
110+
"placeholder": "Enter Password",
109111
}
110112
)
111-
self.fields['password2'].widget.attrs.update(
113+
self.fields["password2"].widget.attrs.update(
112114
{
113-
'placeholder': 'Confirm Password',
115+
"placeholder": "Confirm Password",
114116
}
115117
)
116118

117119
class Meta:
118120
model = User
119-
fields = ['first_name', 'last_name', 'email', 'password1', 'password2']
121+
fields = ["first_name", "last_name", "email", "password1", "password2"]
120122
error_messages = {
121-
'first_name': {
122-
'required': 'First name is required',
123-
'max_length': 'Name is too long'
123+
"first_name": {
124+
"required": "First name is required",
125+
"max_length": "Name is too long",
126+
},
127+
"last_name": {
128+
"required": "Last name is required",
129+
"max_length": "Last Name is too long",
124130
},
125-
'last_name': {
126-
'required': 'Last name is required',
127-
'max_length': 'Last Name is too long'
128-
}
129131
}
130132

131133
def save(self, commit=True):
@@ -147,8 +149,8 @@ class UserLoginForm(forms.Form):
147149
def __init__(self, *args, **kwargs):
148150
super().__init__(*args, **kwargs)
149151
self.user = None
150-
self.fields['email'].widget.attrs.update({'placeholder': 'Enter Email'})
151-
self.fields['password'].widget.attrs.update({'placeholder': 'Enter Password'})
152+
self.fields["email"].widget.attrs.update({"placeholder": "Enter Email"})
153+
self.fields["password"].widget.attrs.update({"placeholder": "Enter Password"})
152154

153155
def clean(self, *args, **kwargs):
154156
email = self.cleaned_data.get("email")
@@ -171,17 +173,16 @@ def get_user(self):
171173

172174

173175
class EmployeeProfileUpdateForm(forms.ModelForm):
174-
175176
def __init__(self, *args, **kwargs):
176177
super(EmployeeProfileUpdateForm, self).__init__(*args, **kwargs)
177-
self.fields['first_name'].widget.attrs.update(
178+
self.fields["first_name"].widget.attrs.update(
178179
{
179-
'placeholder': 'Enter First Name',
180+
"placeholder": "Enter First Name",
180181
}
181182
)
182-
self.fields['last_name'].widget.attrs.update(
183+
self.fields["last_name"].widget.attrs.update(
183184
{
184-
'placeholder': 'Enter Last Name',
185+
"placeholder": "Enter Last Name",
185186
}
186187
)
187188

accounts/managers.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class UserManager(BaseUserManager):
99
def _create_user(self, email, password, **extra_fields):
1010
"""Create and save a User with the given email and password."""
1111
if not email:
12-
raise ValueError('The given email must be set')
12+
raise ValueError("The given email must be set")
1313
email = self.normalize_email(email)
1414
user = self.model(email=email, **extra_fields)
1515
user.set_password(password)
@@ -18,18 +18,18 @@ def _create_user(self, email, password, **extra_fields):
1818

1919
def create_user(self, email, password=None, **extra_fields):
2020
"""Create and save a regular User with the given email and password."""
21-
extra_fields.setdefault('is_staff', False)
22-
extra_fields.setdefault('is_superuser', False)
21+
extra_fields.setdefault("is_staff", False)
22+
extra_fields.setdefault("is_superuser", False)
2323
return self._create_user(email, password, **extra_fields)
2424

2525
def create_superuser(self, email, password, **extra_fields):
2626
"""Create and save a SuperUser with the given email and password."""
27-
extra_fields.setdefault('is_staff', True)
28-
extra_fields.setdefault('is_superuser', True)
27+
extra_fields.setdefault("is_staff", True)
28+
extra_fields.setdefault("is_superuser", True)
2929

30-
if extra_fields.get('is_staff') is not True:
31-
raise ValueError('Superuser must have is_staff=True.')
32-
if extra_fields.get('is_superuser') is not True:
33-
raise ValueError('Superuser must have is_superuser=True.')
30+
if extra_fields.get("is_staff") is not True:
31+
raise ValueError("Superuser must have is_staff=True.")
32+
if extra_fields.get("is_superuser") is not True:
33+
raise ValueError("Superuser must have is_superuser=True.")
3434

3535
return self._create_user(email, password, **extra_fields)

accounts/models.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33

44
from accounts.managers import UserManager
55

6-
GENDER_CHOICES = (
7-
('male', 'Male'),
8-
('female', 'Female'))
6+
GENDER_CHOICES = (("male", "Male"), ("female", "Female"))
97

108

119
class User(AbstractUser):
1210
username = None
13-
role = models.CharField(max_length=12, error_messages={
14-
'required': "Role must be provided"
15-
})
11+
role = models.CharField(
12+
max_length=12, error_messages={"required": "Role must be provided"}
13+
)
1614
gender = models.CharField(max_length=10, blank=True, null=True, default="")
17-
email = models.EmailField(unique=True, blank=False,
18-
error_messages={
19-
'unique': "A user with that email already exists.",
20-
})
15+
email = models.EmailField(
16+
unique=True,
17+
blank=False,
18+
error_messages={
19+
"unique": "A user with that email already exists.",
20+
},
21+
)
2122

2223
USERNAME_FIELD = "email"
2324
REQUIRED_FIELDS = []

0 commit comments

Comments
 (0)