Skip to content

Commit

Permalink
Code review changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHolmes123 committed Dec 5, 2024
1 parent 1de5b80 commit 5f8714a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions web/domains/user/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class Meta:
model = Email
fields = ["email", "type"]

def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user", None)
def __init__(self, *args, user: User, **kwargs):
self.user = user
super().__init__(*args, **kwargs)

def clean_email(self):
Expand Down Expand Up @@ -177,8 +177,8 @@ class Meta:
"is_primary": "Preferred contact address",
}

def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user", None)
def __init__(self, *args, user: User, **kwargs):
self.user = user
super().__init__(*args, **kwargs)

def save(self, commit=True):
Expand Down
11 changes: 6 additions & 5 deletions web/domains/user/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ class Email(models.Model):
WORK = "WORK"
HOME = "HOME"
TYPES = ((WORK, "Work"), (HOME, "Home"))
email = models.EmailField(max_length=254, blank=False, null=False)
type = models.CharField(max_length=30, choices=TYPES, blank=False, null=False, default=WORK)
portal_notifications = models.BooleanField(blank=False, null=False, default=False)
email = models.EmailField(max_length=254)
type = models.CharField(max_length=30, choices=TYPES, default=WORK)
portal_notifications = models.BooleanField(default=False)
comment = models.CharField(max_length=4000, blank=True, null=True)
is_primary = models.BooleanField(blank=False, null=False, default=False)
is_verified = models.BooleanField(blank=False, null=False, default=False)
is_primary = models.BooleanField(default=False)
is_verified = models.BooleanField(default=False)

user = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="emails"
Expand All @@ -112,6 +112,7 @@ def __str__(self):
return self.email


# TODO: Need to rework this as it can create a load of records if the button is spammed.
class EmailVerification(models.Model):
email = models.ForeignKey(Email, on_delete=models.CASCADE)
token = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
Expand Down
2 changes: 1 addition & 1 deletion web/domains/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class SendVerifyEmailView(UserBaseMixin, SingleObjectMixin, RedirectView):
model = Email
pk_url_kwarg = "email_pk"

def get_queryset(self) -> QuerySet[PhoneNumber]:
def get_queryset(self) -> QuerySet[Email]:
qs = super().get_queryset()
return qs.filter(user=self.request.user)

Expand Down

0 comments on commit 5f8714a

Please sign in to comment.