Skip to content

Commit

Permalink
Merge pull request #48 from jdeanwallace/black
Browse files Browse the repository at this point in the history
Add black formatter.
  • Loading branch information
jdeanwallace authored Jan 26, 2024
2 parents f48c63f + 54b1abb commit ab19e12
Show file tree
Hide file tree
Showing 26 changed files with 448 additions and 280 deletions.
13 changes: 10 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ jobs:
- checkout
- run:
name: Create virtual environment
command: python -m venv venv
command: |
python -m venv venv
. venv/bin/activate
pip install pip pip-tools --upgrade
pip-sync requirements/dev.txt
- run:
name: Check style
command: |
. venv/bin/activate
black --check .
- run:
name: Run tests
command: |
. venv/bin/activate
pip install pip-tools --upgrade
pip-sync requirements/dev.txt
./manage.py makemigrations
./manage.py test
workflows:
Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
## Getting Started

```bash
cd /path/to/project/directory
python -m venv venv
. venv/bin/activate
pip install pip-tools --upgrade
pip-sync requirements/dev.txt
./manage.py makemigrations
./manage.py migrate
./manage.py createsuperuser
...
./manage.py runserver
python -m venv venv && \
. venv/bin/activate && \
pip install pip-tools --upgrade && \
pip-sync requirements/dev.txt && \
python manage.py makemigrations && \
python manage.py migrate && \
python manage.py createsuperuser

python manage.py runserver
```

<!-- End. -->
2 changes: 1 addition & 1 deletion apps/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
default_app_config = 'apps.accounts.apps.AccountsConfig'
default_app_config = "apps.accounts.apps.AccountsConfig"
61 changes: 47 additions & 14 deletions apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,59 @@
@admin.register(models.User)
class UserAdmin(UserAdmin):
add_form = forms.CreateUserForm
add_form_template = 'admin/accounts/user/add_form.html'
add_form_template = "admin/accounts/user/add_form.html"
list_display = (
'uuid', 'email', 'first_name', 'last_name', 'is_staff', 'date_joined',
"uuid",
"email",
"first_name",
"last_name",
"is_staff",
"date_joined",
)
search_fields = (
'uuid', 'email', 'first_name', 'last_name',
"uuid",
"email",
"first_name",
"last_name",
)
ordering = ("-date_joined",)
readonly_fields = (
"uuid",
"last_login",
"date_joined",
)
ordering = ('-date_joined',)
readonly_fields = ('uuid', 'last_login', 'date_joined',)

fieldsets = (
(None, {'fields': ('uuid', 'email', 'password')}),
(_('Personal info'), {'fields': ('first_name', 'last_name',)}),
(_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
'groups', 'user_permissions')}),
(_('Important dates'), {'fields': ('last_login', 'date_joined')}),
(None, {"fields": ("uuid", "email", "password")}),
(
_("Personal info"),
{
"fields": (
"first_name",
"last_name",
)
},
),
(
_("Permissions"),
{
"fields": (
"is_active",
"is_staff",
"is_superuser",
"groups",
"user_permissions",
)
},
),
(_("Important dates"), {"fields": ("last_login", "date_joined")}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('first_name', 'last_name'),
}),
(
None,
{
"classes": ("wide",),
"fields": ("first_name", "last_name"),
},
),
)
2 changes: 1 addition & 1 deletion apps/accounts/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class AccountsConfig(AppConfig):
name = 'apps.accounts'
name = "apps.accounts"

def ready(self):
from . import receivers
3 changes: 1 addition & 2 deletions apps/accounts/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ def authenticate(self, request, username=None, password=None, **kwargs):
# difference between an existing and a nonexistent user (#20760).
UserModel().set_password(password)
else:
if (user.check_password(password)
and self.user_can_authenticate(user)):
if user.check_password(password) and self.user_can_authenticate(user):
return user
27 changes: 16 additions & 11 deletions apps/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class AuthenticationForm(DjangoAuthenticationForm):
error_messages = {
'invalid_login': _(
"invalid_login": _(
"Please enter a correct %(username)s and password. Note that both "
"fields may be case-sensitive."
),
Expand All @@ -26,32 +26,34 @@ def __init__(self, request=None, *args, **kwargs):
super().__init__(*args, **kwargs)

# Set the label for the "username" field.
self.fields['username'].label = _('Email')
self.fields["username"].label = _("Email")

def clean_username(self):
username = self.cleaned_data.get('username')
username = self.cleaned_data.get("username")
try:
validate_email(username)
except forms.ValidationError:
raise forms.ValidationError(
_('This needs to be a valid email address.'),
_("This needs to be a valid email address."),
)

return username

def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
username = self.cleaned_data.get("username")
password = self.cleaned_data.get("password")

if username is not None and password:
self.user_cache = authenticate(
self.request, username=username, password=password,
self.request,
username=username,
password=password,
)
if self.user_cache is None:
raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={'username': 'email'},
self.error_messages["invalid_login"],
code="invalid_login",
params={"username": "email"},
)
else:
self.confirm_login_allowed(self.user_cache)
Expand All @@ -74,4 +76,7 @@ class CreateUserForm(forms.ModelForm):

class Meta:
model = User
fields = ('first_name', 'last_name',)
fields = (
"first_name",
"last_name",
)
20 changes: 13 additions & 7 deletions apps/accounts/management/commands/changepassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def _get_pass(self, prompt="Password: "):
def add_arguments(self, parser):
parser.add_argument(
UserModel.EMAIL_FIELD,
help='%s to change password for.' % UserModel.EMAIL_FIELD,
help="%s to change password for." % UserModel.EMAIL_FIELD,
)
parser.add_argument(
'--database', action='store', dest='database',
"--database",
action="store",
dest="database",
default=DEFAULT_DB_ALIAS,
help='Specifies the database to use. Default is "default".',
)
Expand All @@ -35,9 +37,11 @@ def handle(self, *args, **options):
email = options[UserModel.EMAIL_FIELD]

try:
u = UserModel._default_manager.using(options['database']).get(**{
UserModel.EMAIL_FIELD: email,
})
u = UserModel._default_manager.using(options["database"]).get(
**{
UserModel.EMAIL_FIELD: email,
}
)
except UserModel.DoesNotExist:
raise CommandError("user '%s' does not exist" % email)

Expand All @@ -58,13 +62,15 @@ def handle(self, *args, **options):
try:
validate_password(p2, u)
except ValidationError as err:
self.stderr.write('\n'.join(err.messages))
self.stderr.write("\n".join(err.messages))
count += 1
else:
password_validated = True

if count == MAX_TRIES:
raise CommandError("Aborting password change for user '%s' after %s attempts" % (u, count))
raise CommandError(
"Aborting password change for user '%s' after %s attempts" % (u, count)
)

u.set_password(p1)
u.save()
Expand Down
Loading

0 comments on commit ab19e12

Please sign in to comment.