Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Commit 8e37f4f

Browse files
chore(post_gen_project.py): fix formatting and add missing newline at end of file (#635)
chore(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port chore(serializers.py): fix formatting of field names in SignupSerializer and UserSerializer feat(serializers.py): add required and allow_blank options to email field in SignupSerializer chore(apps.py): fix formatting of name field in HomeConfig chore(createsuperuserauto.py): fix formatting and typo in help message chore(customchangepassword.py): fix formatting and typo in help message chore(upgradetosuperuser.py): fix formatting and add missing newline at end of file chore(0001_load_initial_data.py): remove unnecessary newline at end of file chore(views.py): reformat code for better readability and maintainability chore(manage.py): reformat code for better readability and maintainability chore(admin.py): reformat code for better readability and maintainability chore(apps.py): reformat code for better readability and maintainability chore(urls.py): reformat code for better readability and maintainability chore(utils.py): reformat code for better readability and maintainability chore(admin.py): reformat code for better readability and maintainability chore(forms.py): reformat code for better readability and maintainability chore(0001_initial.py): reformat code for better readability and maintainability chore(factories.py): reformat code for better readability and maintainability chore(views.py): reformat code for better readability and maintainability chore(wsgi.py): reformat code for better readability and maintainability
1 parent e40ee37 commit 8e37f4f

File tree

19 files changed

+101
-81
lines changed

19 files changed

+101
-81
lines changed

hooks/post_gen_project.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
REMOVE_PATHS = [
66
'{% if cookiecutter.is_mobile != "y" %} web_build {% endif %}',
7-
'{% if cookiecutter.is_mobile == "y" %} .github {% endif %}'
7+
'{% if cookiecutter.is_mobile == "y" %} .github {% endif %}',
88
]
99

1010
for path in REMOVE_PATHS:
@@ -14,4 +14,4 @@
1414
if os.path.isdir(path):
1515
shutil.rmtree(path)
1616
else:
17-
os.unlink(path)
17+
os.unlink(path)

{{cookiecutter.project_slug}}/home/api/v1/serializers.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@
1616
class SignupSerializer(serializers.ModelSerializer):
1717
class Meta:
1818
model = User
19-
fields = ('id', 'name', 'email', 'password')
19+
fields = ("id", "name", "email", "password")
2020
extra_kwargs = {
21-
'password': {
22-
'write_only': True,
23-
'style': {
24-
'input_type': 'password'
25-
}
21+
"password": {"write_only": True, "style": {"input_type": "password"}},
22+
"email": {
23+
"required": True,
24+
"allow_blank": False,
2625
},
27-
'email': {
28-
'required': True,
29-
'allow_blank': False,
30-
}
3126
}
3227

3328
def _get_request(self):
34-
request = self.context.get('request')
35-
if request and not isinstance(request, HttpRequest) and hasattr(request, '_request'):
29+
request = self.context.get("request")
30+
if (
31+
request
32+
and not isinstance(request, HttpRequest)
33+
and hasattr(request, "_request")
34+
):
3635
request = request._request
3736
return request
3837

@@ -41,20 +40,19 @@ def validate_email(self, email):
4140
if allauth_settings.UNIQUE_EMAIL:
4241
if email and email_address_exists(email):
4342
raise serializers.ValidationError(
44-
_("A user is already registered with this e-mail address."))
43+
_("A user is already registered with this e-mail address.")
44+
)
4545
return email
4646

4747
def create(self, validated_data):
4848
user = User(
49-
email=validated_data.get('email'),
50-
name=validated_data.get('name'),
51-
username=generate_unique_username([
52-
validated_data.get('name'),
53-
validated_data.get('email'),
54-
'user'
55-
])
49+
email=validated_data.get("email"),
50+
name=validated_data.get("name"),
51+
username=generate_unique_username(
52+
[validated_data.get("name"), validated_data.get("email"), "user"]
53+
),
5654
)
57-
user.set_password(validated_data.get('password'))
55+
user.set_password(validated_data.get("password"))
5856
user.save()
5957
request = self._get_request()
6058
setup_user_email(request, user, [])
@@ -68,9 +66,10 @@ def save(self, request=None):
6866
class UserSerializer(serializers.ModelSerializer):
6967
class Meta:
7068
model = User
71-
fields = ['id', 'email', 'name']
69+
fields = ["id", "email", "name"]
7270

7371

7472
class PasswordSerializer(PasswordResetSerializer):
7573
"""Custom serializer for rest_auth to solve reset password error"""
74+
7675
password_reset_form_class = ResetPasswordForm

{{cookiecutter.project_slug}}/home/apps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
class HomeConfig(AppConfig):
5-
name = 'home'
5+
name = "home"

{{cookiecutter.project_slug}}/home/management/commands/createsuperuserauto.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,49 @@
55

66

77
class Command(createsuperuser.Command):
8-
help = 'Crate a superuser, and allow password to be provided'
8+
help = "Crate a superuser, and allow password to be provided"
99

1010
def add_arguments(self, parser):
1111
super(Command, self).add_arguments(parser)
1212
parser.add_argument(
13-
'--password', dest='password', default=None,
14-
help='Specifies the password for the superuser.',
13+
"--password",
14+
dest="password",
15+
default=None,
16+
help="Specifies the password for the superuser.",
1517
)
1618
if self.UserModel.USERNAME_FIELD != "username":
1719
parser.add_argument(
18-
'--username', dest='username', default=None,
19-
help="Specifies the username for the superuser"
20+
"--username",
21+
dest="username",
22+
default=None,
23+
help="Specifies the username for the superuser",
2024
)
2125

2226
def handle(self, *args, **options):
23-
password = options.get('password')
24-
username = options.get('username')
25-
database = options.get('database')
26-
email = options.get('email')
27+
password = options.get("password")
28+
username = options.get("username")
29+
database = options.get("database")
30+
email = options.get("email")
2731

2832
User = self.UserModel
2933
username_field_type = type(User._meta.get_field(User.USERNAME_FIELD))
3034
username = email if username_field_type == EmailField else username
3135
username_type = "email" if username_field_type == EmailField else "username"
3236
if not password or not username:
33-
raise CommandError(f"You need to specify both password and {username_type}.")
37+
raise CommandError(
38+
f"You need to specify both password and {username_type}."
39+
)
3440
options.update({User.USERNAME_FIELD: username})
3541
super(Command, self).handle(*args, **options)
3642

37-
user = self.UserModel._default_manager.db_manager(database).get(**{User.USERNAME_FIELD: username})
43+
user = self.UserModel._default_manager.db_manager(database).get(
44+
**{User.USERNAME_FIELD: username}
45+
)
3846
if password:
3947
user.set_password(password)
4048
user.save()
4149

4250
if email:
43-
EmailAddress.objects.create(user=user, email=email, primary=True, verified=True)
51+
EmailAddress.objects.create(
52+
user=user, email=email, primary=True, verified=True
53+
)

{{cookiecutter.project_slug}}/home/management/commands/customchangepassword.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,43 @@
55

66

77
class Command(BaseCommand):
8-
help = 'Update password of the provided username.'
8+
help = "Update password of the provided username."
99

1010
def add_arguments(self, parser):
1111
parser.add_argument(
12-
'--username', dest='username', default=None,
13-
help='Specifies the username to be updated.',
12+
"--username",
13+
dest="username",
14+
default=None,
15+
help="Specifies the username to be updated.",
1416
)
1517

1618
parser.add_argument(
17-
'--email', dest='email', default=None,
18-
help='Specifies the email to be updated.',
19+
"--email",
20+
dest="email",
21+
default=None,
22+
help="Specifies the email to be updated.",
1923
)
2024

2125
parser.add_argument(
22-
'--password', dest='password', default=None,
23-
help='Specifies the password to be updated.',
26+
"--password",
27+
dest="password",
28+
default=None,
29+
help="Specifies the password to be updated.",
2430
)
2531

2632
def handle(self, *args, **options):
2733
User = get_user_model()
28-
password = options.get('password')
29-
username = options.get('username')
30-
email = options.get('email')
34+
password = options.get("password")
35+
username = options.get("username")
36+
email = options.get("email")
3137

3238
username_field_type = type(User._meta.get_field(User.USERNAME_FIELD))
3339
username = email if username_field_type == EmailField else username
3440
username_type = "email" if username_field_type == EmailField else "username"
3541
if not password or not username:
36-
raise CommandError(f"You need to specify both password and {username_type}.")
42+
raise CommandError(
43+
f"You need to specify both password and {username_type}."
44+
)
3745

3846
try:
3947
user = User.objects.get(**{User.USERNAME_FIELD: username})

{{cookiecutter.project_slug}}/home/management/commands/upgradetosuperuser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def handle(self, *args, **kwargs) -> None:
2828
)
2929
)
3030
except EmailAddress.DoesNotExist:
31-
self.stdout.write(self.style.ERROR(f"User {email} does not exist or not active or verified"))
31+
self.stdout.write(
32+
self.style.ERROR(
33+
f"User {email} does not exist or not active or verified"
34+
)
35+
)
3236
else:
3337
self.stdout.write(self.style.ERROR(f"No email address provided."))

{{cookiecutter.project_slug}}/home/migrations/0001_load_initial_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def create_site(apps, schema_editor):
1515

1616

1717
class Migration(migrations.Migration):
18-
1918
dependencies = [
2019
("sites", "0002_alter_domain_unique"),
2120
]

{{cookiecutter.project_slug}}/home/views.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
def home(request):
55
packages = [
6-
{'name':'django-allauth', 'url': 'https://pypi.org/project/django-allauth/0.38.0/'},
7-
{'name':'django-bootstrap4', 'url': 'https://pypi.org/project/django-bootstrap4/0.0.7/'},
8-
{'name':'djangorestframework', 'url': 'https://pypi.org/project/djangorestframework/3.9.0/'},
6+
{
7+
"name": "django-allauth",
8+
"url": "https://pypi.org/project/django-allauth/0.38.0/",
9+
},
10+
{
11+
"name": "django-bootstrap4",
12+
"url": "https://pypi.org/project/django-bootstrap4/0.0.7/",
13+
},
14+
{
15+
"name": "djangorestframework",
16+
"url": "https://pypi.org/project/djangorestframework/3.9.0/",
17+
},
918
]
10-
context = {
11-
'packages': packages
12-
}
13-
return render(request, 'home/index.html', context)
19+
context = {"packages": packages}
20+
return render(request, "home/index.html", context)

{{cookiecutter.project_slug}}/manage.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66

77
def main():
8-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{cookiecutter.project_slug}}.settings')
8+
os.environ.setdefault(
9+
"DJANGO_SETTINGS_MODULE", "{{cookiecutter.project_slug}}.settings"
10+
)
911
try:
1012
from django.core.management import execute_from_command_line
1113
except ImportError as exc:
@@ -17,5 +19,5 @@ def main():
1719
execute_from_command_line(sys.argv)
1820

1921

20-
if __name__ == '__main__':
22+
if __name__ == "__main__":
2123
main()

{{cookiecutter.project_slug}}/modules/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Crowdbotics' official modules working properly.
88

99
try:
10-
admins = Path(".").rglob('admin.py')
10+
admins = Path(".").rglob("admin.py")
1111

1212
for admin in admins:
1313
module = import_module(posixpath_to_modulepath(admin), package="modules")

0 commit comments

Comments
 (0)