Skip to content

Commit

Permalink
DeepSource fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
blag committed Sep 6, 2023
1 parent f0ad180 commit a239c8f
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ def get_initial(self):
def get_template_names(self):
if is_ajax(self.request):
return [self.template_name_ajax]
else:
return [self.template_name]
return [self.template_name]

def get_form_kwargs(self):
kwargs = super(SignupView, self).get_form_kwargs()
Expand Down Expand Up @@ -235,25 +234,25 @@ def form_valid(self, form):
self.send_email_confirmation(email_address)
if settings.ACCOUNT_EMAIL_CONFIRMATION_REQUIRED and not email_address.verified:
return self.email_confirmation_required_response()
else:
show_message = [
settings.ACCOUNT_EMAIL_CONFIRMATION_EMAIL,
self.messages.get("email_confirmation_sent"),
not email_address.verified
]
if all(show_message):
messages.add_message(
self.request,
self.messages["email_confirmation_sent"]["level"],
self.messages["email_confirmation_sent"]["text"].format(**{
"email": form.cleaned_data["email"]
})
)
# attach form to self to maintain compatibility with login_user
# API. this should only be relied on by d-u-a and it is not a stable
# API for site developers.
self.form = form
self.login_user()

show_message = [
settings.ACCOUNT_EMAIL_CONFIRMATION_EMAIL,
self.messages.get("email_confirmation_sent"),
not email_address.verified
]
if all(show_message):
messages.add_message(
self.request,
self.messages["email_confirmation_sent"]["level"],
self.messages["email_confirmation_sent"]["text"].format(**{
"email": form.cleaned_data["email"]
})
)
# attach form to self to maintain compatibility with login_user
# API. this should only be relied on by d-u-a and it is not a stable
# API for site developers.
self.form = form # skipcq: PYL-W0201
self.login_user()
return redirect(self.get_success_url())

def create_user(self, form, commit=True, model=None, **kwargs):
Expand Down Expand Up @@ -317,16 +316,16 @@ def get_code(self):
def is_open(self):
if self.signup_code:
return True
else:
if self.signup_code_present:
if self.messages.get("invalid_signup_code"):
messages.add_message(
self.request,
self.messages["invalid_signup_code"]["level"],
self.messages["invalid_signup_code"]["text"].format(**{
"code": self.get_code(),
})
)

if self.signup_code_present and self.messages.get("invalid_signup_code"):
messages.add_message(
self.request,
self.messages["invalid_signup_code"]["level"],
self.messages["invalid_signup_code"]["text"].format(**{
"code": self.get_code(),
})
)

return settings.ACCOUNT_OPEN_SIGNUP

def email_confirmation_required_response(self):
Expand Down Expand Up @@ -378,8 +377,7 @@ def get(self, *args, **kwargs):
def get_template_names(self):
if is_ajax(self.request):
return [self.template_name_ajax]
else:
return [self.template_name]
return [self.template_name]

def get_context_data(self, **kwargs):
ctx = super(LoginView, self).get_context_data(**kwargs)
Expand Down Expand Up @@ -550,8 +548,7 @@ def get_redirect_url(self):
if not settings.ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL:
return settings.ACCOUNT_LOGIN_REDIRECT_URL
return settings.ACCOUNT_EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL
else:
return settings.ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL
return settings.ACCOUNT_EMAIL_CONFIRMATION_ANONYMOUS_REDIRECT_URL

def after_confirmation(self, confirmation):
user = confirmation.email_address.user
Expand Down Expand Up @@ -598,9 +595,7 @@ def get_user(self):
return self.request.user

def get_form_kwargs(self):
"""
Returns the keyword arguments for instantiating the form.
"""
"""Returns the keyword arguments for instantiating the form."""
kwargs = {"user": self.request.user, "initial": self.get_initial()}
if self.request.method in ["POST", "PUT"]:
kwargs.update({
Expand Down Expand Up @@ -650,11 +645,8 @@ def send_email(self, email):
for user in User.objects.filter(pk__in=email_qs.values("user")):
uid = int_to_base36(user.id)
token = self.make_token(user)
password_reset_url = "{0}://{1}{2}".format(
protocol,
current_site.domain,
reverse(settings.ACCOUNT_PASSWORD_RESET_TOKEN_URL, kwargs=dict(uidb36=uid, token=token))
)
path = reverse(settings.ACCOUNT_PASSWORD_RESET_TOKEN_URL, kwargs=dict(uidb36=uid, token=token))
password_reset_url = f"{protocol}://{current_site.domain}{path}"
ctx = {
"user": user,
"current_site": current_site,
Expand Down

0 comments on commit a239c8f

Please sign in to comment.