Skip to content

Commit

Permalink
refactor: accounts/admin 에 타입 힌트 추가 #92
Browse files Browse the repository at this point in the history
  • Loading branch information
TGoddessana committed Oct 3, 2023
1 parent 4ae1300 commit 007a0d9
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError
from django.db.models import QuerySet
from rest_framework.authtoken.models import TokenProxy

from apps.accounts.models import User
Expand All @@ -26,15 +27,16 @@ class Meta:
"email",
]

def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
def clean_password2(self) -> str | None:
password1: str | None = self.cleaned_data.get("password1")
password2: str | None = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise ValidationError("Passwords don't match")
return password2

def save(self, commit=True):
def save(self, commit: bool = True) -> User:
user = super().save(commit=False)
assert isinstance(user, User)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
Expand Down Expand Up @@ -92,7 +94,8 @@ class UserAdmin(BaseUserAdmin):
ordering = ["email"]

@staticmethod
def social_accounts(obj):
def social_accounts(obj: User) -> str | QuerySet[User]:
assert hasattr(obj, "socialaccount_set")
return (
obj.socialaccount_set.all()
if obj.socialaccount_set.all()
Expand Down

0 comments on commit 007a0d9

Please sign in to comment.