-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Linting Issues #209
Fix Linting Issues #209
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
}, | ||
} | ||
|
||
|
||
# Eliminates warning about missing staticfiles directory | ||
WHITENOISE_AUTOREFRESH = True | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
import datetime | ||
|
||
from django.contrib.auth import get_user_model | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (llm): The removal of |
||
import pytest | ||
from django.db import models | ||
from django.shortcuts import reverse | ||
from django.utils.text import slugify | ||
|
||
import pytest | ||
|
||
from mixer.backend.django import mixer | ||
from tinymce.models import HTMLField | ||
|
||
from apps.blog.models import Category, Post | ||
|
||
|
||
pytestmark = pytest.mark.django_db(reset_sequences=True) | ||
|
||
|
||
user_model = get_user_model() | ||
|
||
|
||
class TestCategory: | ||
def test_name_is_charfield(self): | ||
category = mixer.blend(Category, pk=1) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.contrib.auth import get_user_model | ||
from django.contrib.auth.models import User | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.db import models | ||
from django.template.defaultfilters import slugify | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
|
||
from django_otp.util import random_hex | ||
from encrypted_model_fields.fields import EncryptedCharField | ||
|
||
|
@@ -29,7 +28,7 @@ class AuthorView(models.IntegerChoices): | |
|
||
# Relationship Fields | ||
user = models.OneToOneField( | ||
get_user_model(), primary_key=True, related_name="profile", on_delete=models.CASCADE | ||
User, primary_key=True, related_name="profile", on_delete=models.CASCADE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (llm): The change in the ForeignKey relationship to use |
||
) | ||
|
||
def __str__(self): | ||
|
@@ -98,9 +97,7 @@ class EmailToken(models.Model): | |
token_expiration_timestamp = models.DateTimeField(null=True, blank=True) | ||
|
||
# Relationship Fields | ||
user = models.ForeignKey( | ||
get_user_model(), related_name="user_email_tokens", on_delete=models.CASCADE | ||
) | ||
user = models.ForeignKey(User, related_name="user_email_tokens", on_delete=models.CASCADE) | ||
|
||
def __repr__(self): | ||
return f"<EmailToken(id={self.id}, user_id={self.user_id}, user='{self.user}')>" | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -2,10 +2,10 @@ | |||||||
|
||||||||
from django.conf import settings | ||||||||
from django.contrib import auth, messages | ||||||||
from django.contrib.auth import get_user_model | ||||||||
from django.contrib.auth.forms import AuthenticationForm | ||||||||
from django.contrib.auth.hashers import check_password | ||||||||
from django.contrib.auth.mixins import UserPassesTestMixin | ||||||||
from django.contrib.auth.models import User | ||||||||
from django.contrib.auth.views import ( | ||||||||
PasswordResetCompleteView, | ||||||||
PasswordResetConfirmView, | ||||||||
|
@@ -20,7 +20,6 @@ | |||||||
from django.utils.safestring import mark_safe | ||||||||
from django.views.generic import CreateView, DetailView, TemplateView | ||||||||
from django.views.generic.edit import FormView | ||||||||
|
||||||||
from shapeshifter.views import MultiModelFormView | ||||||||
from two_factor.forms import AuthenticationTokenForm | ||||||||
from two_factor.views.core import LoginView, SetupView | ||||||||
|
@@ -51,7 +50,7 @@ class UserRegisterView(CreateView): | |||||||
|
||||||||
def user_exists(self, form) -> bool: | ||||||||
username = form.data["username"] | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (llm): Directly referencing the User model instead of using get_user_model() reduces the flexibility of the user model. If the project ever needs to customize the user model, this change will necessitate refactoring all direct references to User. |
||||||||
user = get_user_model().objects.filter(username=username) | ||||||||
user = User.objects.filter(username=username) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (llm): I noticed the change from |
||||||||
if user.exists(): | ||||||||
return True | ||||||||
|
||||||||
|
@@ -110,7 +109,7 @@ def build_html_content(self, user, token) -> str: | |||||||
}, | ||||||||
) | ||||||||
|
||||||||
def email_two_factor_token(self, user: get_user_model(), token): | ||||||||
def email_two_factor_token(self, user: User, token): | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (llm): Given the changes in method signatures to use |
||||||||
"""Sends email containing current token""" | ||||||||
|
||||||||
subject = "Your One Time Token" | ||||||||
|
@@ -155,7 +154,8 @@ def login_user(self, user): | |||||||
|
||||||||
def handle_email_auth_user(self, user): | ||||||||
"""Handles the actions for processing an email authenticated user""" | ||||||||
if user_passes_auth := self.authenticate_user(user=user): | ||||||||
user_passes_auth = self.authenticate_user(user=user) | ||||||||
if user_passes_auth: | ||||||||
Comment on lines
+157
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (rule): Sourcery has identified the following issue:
Suggested change
|
||||||||
self.login_user(user=user) | ||||||||
token = self.retrieve_token_from_db(user) | ||||||||
self.email_two_factor_token(user, token) | ||||||||
|
@@ -176,8 +176,8 @@ def post(self, *args, **kwargs): | |||||||
|
||||||||
# Scenario 1: The user does not exist in the DB | ||||||||
try: | ||||||||
user = get_user_model().objects.get(username=username) | ||||||||
except get_user_model().DoesNotExist: | ||||||||
user = User.objects.get(username=username) | ||||||||
except User.DoesNotExist: | ||||||||
self._add_user_does_not_exist_message() | ||||||||
return redirect(self.request.path_info) | ||||||||
|
||||||||
|
@@ -202,7 +202,7 @@ def post(self, *args, **kwargs): | |||||||
# enable the Django Two-Factor Auth package to handle | ||||||||
elif self.steps.current == "token": | ||||||||
user_pk = self.request.session["wizard_user_login_view"]["user_pk"] | ||||||||
user = get_user_model().objects.get(pk=user_pk) | ||||||||
user = User.objects.get(pk=user_pk) | ||||||||
if user.profile.is_two_factor_auth_by_token: | ||||||||
return super().post(*args, **kwargs) | ||||||||
|
||||||||
|
@@ -224,7 +224,7 @@ class UserSetupEmailView(TemplateView): | |||||||
template_name = "two_factor/setup_by_email.html" | ||||||||
success_url = reverse_lazy("blog:users:setup_email_token") | ||||||||
|
||||||||
def store_token_in_db(self, user: get_user_model(), token: str): | ||||||||
def store_token_in_db(self, user: User, token: str): | ||||||||
"""Creates an email token object in the DB""" | ||||||||
EmailToken.objects.create( | ||||||||
challenge_email_address=user.email, | ||||||||
|
@@ -235,7 +235,7 @@ def store_token_in_db(self, user: get_user_model(), token: str): | |||||||
user_id=user.id, | ||||||||
) | ||||||||
|
||||||||
def build_html_content(self, user: get_user_model(), token: str) -> str: | ||||||||
def build_html_content(self, user: User, token: str) -> str: | ||||||||
""" " Specifies the email template and context variables""" | ||||||||
return render_to_string( | ||||||||
template_name="emails/token.html", | ||||||||
|
@@ -246,7 +246,7 @@ def build_html_content(self, user: get_user_model(), token: str) -> str: | |||||||
}, | ||||||||
) | ||||||||
|
||||||||
def email_two_factor_token(self, user: get_user_model(), token: str): | ||||||||
def email_two_factor_token(self, user: User, token: str): | ||||||||
"""Sends email containing one-time token""" | ||||||||
|
||||||||
subject = "Your One Time Token" | ||||||||
|
@@ -315,7 +315,7 @@ def build_html_content(self, user, token) -> str: | |||||||
}, | ||||||||
) | ||||||||
|
||||||||
def email_two_factor_success(self, user: get_user_model(), token): | ||||||||
def email_two_factor_success(self, user: User, token): | ||||||||
"""Sends email containing one-time token""" | ||||||||
|
||||||||
subject = "Two-Factor Authentication Successful" | ||||||||
|
@@ -365,7 +365,7 @@ class ProfileView(TwoFactorAuthUserMixin, DetailView): | |||||||
template_name = "users/profile.html" | ||||||||
|
||||||||
def get_object(self, queryset=None): | ||||||||
return get_object_or_404(get_user_model(), username=self.kwargs["username"]) | ||||||||
return get_object_or_404(User, username=self.kwargs["username"]) | ||||||||
|
||||||||
|
||||||||
class ProfileUpdateView(TwoFactorAuthUserMixin, UserPassesTestMixin, MultiModelFormView): | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (llm): This change impacts the
Post
model's relationship with theUser
model. It's essential to ensure that all tests related to thePost
model, especially those that involve theauthor
relationship, are updated to reflect this change. This includes updating any fixtures or mock objects used in these tests.