Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃毃 [#28] Run autopep8, isort & black #29

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bobvance/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class UserAdmin(_UserAdmin):

def get_form(self, request, obj=None, **kwargs):
ModelForm = super().get_form(request, obj, **kwargs)
assert issubclass(
ModelForm, (PreventPrivilegeEscalationMixin, self.add_form)
)
assert issubclass(ModelForm, (PreventPrivilegeEscalationMixin, self.add_form))
# Set the current and target user on the ModelForm class so they are
# available in the instantiated form. See the comment in the
# UserChangeForm for more details.
Expand Down
4 changes: 1 addition & 3 deletions src/bobvance/accounts/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class UserModelEmailBackend(ModelBackend):

def authenticate(self, request, username=None, password=None, **kwargs):
try:
user = get_user_model().objects.get(
email__iexact=username, is_active=True
)
user = get_user_model().objects.get(email__iexact=username, is_active=True)
if check_password(password, user.password):
return user
except get_user_model().DoesNotExist:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def handle(self, **options):
user = qs.get()

if not password and options["generate_password"]:
options["password"] = self.UserModel.objects.make_random_password(
length=20
)
options["password"] = self.UserModel.objects.make_random_password(length=20)

if options["password"] or not PASSWORD_FROM_ENV_SUPPORTED:
self.stdout.write("Setting user password...")
Expand All @@ -78,17 +76,13 @@ def handle(self, **options):

if options["email_password_reset"]:
password_reset_path = reverse("admin_password_reset")
default_host = (
settings.ALLOWED_HOSTS[0] if settings.ALLOWED_HOSTS else ""
)
default_host = settings.ALLOWED_HOSTS[0] if settings.ALLOWED_HOSTS else ""
if default_host == "*":
default_host = ""
domain = options["domain"] or default_host

pw_reset_link = (
f"https://{domain}{password_reset_path}"
if domain
else "unknown url"
f"https://{domain}{password_reset_path}" if domain else "unknown url"
)
send_mail(
f"Your admin user for {settings.PROJECT_NAME} ({domain or 'unknown url'})",
Expand Down
4 changes: 1 addition & 3 deletions src/bobvance/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class User(AbstractBaseUser, PermissionsMixin):
is_staff = models.BooleanField(
_("staff status"),
default=False,
help_text=_(
"Designates whether the user can log into this admin site."
),
help_text=_("Designates whether the user can log into this admin site."),
)
is_active = models.BooleanField(
_("active"),
Expand Down
4 changes: 1 addition & 3 deletions src/bobvance/accounts/tests/test_permission_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def setUp(self):
username="less_perms_staff_user", password="secret"
)
for p in Permission.objects.filter(
content_type=ContentType.objects.get(
app_label="accounts", model="user"
)
content_type=ContentType.objects.get(app_label="accounts", model="user")
):
self.less_perms_staff_user.user_permissions.add(p)

Expand Down
4 changes: 1 addition & 3 deletions src/bobvance/accounts/tests/test_user_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

class UserManagerTests(TestCase):
def test_create_superuser(self):
user = User.objects.create_superuser(
"god", "god@heaven.com", "praisejebus"
)
user = User.objects.create_superuser("god", "god@heaven.com", "praisejebus")
self.assertIsNotNone(user.pk)
self.assertTrue(user.is_staff)
self.assertTrue(user.is_superuser)
Expand Down
8 changes: 2 additions & 6 deletions src/bobvance/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def validate_max_permissions(
return

if is_superuser:
raise ValidationError(
_("You need to be superuser to create other superusers.")
)
raise ValidationError(_("You need to be superuser to create other superusers."))

allowed_permissions = current_user.get_all_permissions()

Expand All @@ -43,9 +41,7 @@ def validate_max_permissions(

if not given_permissions.issubset(allowed_permissions):
raise ValidationError(
_(
"You cannot create or update a user with more permissions than yourself."
)
_("You cannot create or update a user with more permissions than yourself.")
)


Expand Down
4 changes: 1 addition & 3 deletions src/bobvance/accounts/views/csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ def csrf_failure(request, reason="", template_name=CSRF_FAILURE_TEMPLATE_NAME):
"""
if request.path in settings.LOGIN_URLS and request.user.is_authenticated:
return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL)
return original_csrf_failure(
request, reason=reason, template_name=template_name
)
return original_csrf_failure(request, reason=reason, template_name=template_name)
11 changes: 4 additions & 7 deletions src/bobvance/base/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.contrib import admin

from bobvance.base.models import Customer, Product, OrderProduct, Order

from django import forms
from django.contrib import admin
from django.db import models

from bobvance.base.models import Customer, Order, OrderProduct, Product

# Register your models here.


Expand Down Expand Up @@ -43,9 +42,7 @@ def formfield_for_dbfield(self, db_field, request, **kwargs):
if isinstance(db_field, (models.CharField, models.TextField)):
kwargs["widget"] = forms.TextInput(attrs={"readonly": "readonly"})
elif isinstance(db_field, models.BooleanField):
kwargs["widget"] = forms.CheckboxInput(
attrs={"disabled": "readonly"}
)
kwargs["widget"] = forms.CheckboxInput(attrs={"disabled": "readonly"})
else:
kwargs["widget"] = forms.TextInput(attrs={"disabled": "readonly"})
return super().formfield_for_dbfield(db_field, request, **kwargs)
Expand Down
3 changes: 2 additions & 1 deletion src/bobvance/base/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from bobvance.base.models import Customer
from django import forms

from bobvance.base.models import Customer


class CustomerForm(forms.ModelForm):
class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ class Migration(migrations.Migration):
"quantity",
models.PositiveIntegerField(
default=1,
validators=[
django.core.validators.MinValueValidator(1)
],
validators=[django.core.validators.MinValueValidator(1)],
),
),
(
Expand Down
4 changes: 1 addition & 3 deletions src/bobvance/base/migrations/0005_order_total_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="order",
name="total_price",
field=models.DecimalField(
decimal_places=0, default=0, max_digits=5
),
field=models.DecimalField(decimal_places=0, default=0, max_digits=5),
),
]
8 changes: 2 additions & 6 deletions src/bobvance/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ class Order(models.Model):
default=ORDER_STATUS_CHOICES[0][0],
)
created_at = models.DateTimeField(auto_now_add=True)
total_price = models.DecimalField(
max_digits=5, decimal_places=0, default=0
)
total_price = models.DecimalField(max_digits=5, decimal_places=0, default=0)

def __str__(self):
return f"{self.customer} - {self.id}"
Expand All @@ -71,9 +69,7 @@ class OrderProduct(models.Model):
product = models.ForeignKey(
Product, related_name="product_orders", on_delete=models.CASCADE
)
quantity = models.PositiveIntegerField(
default=1, validators=[MinValueValidator(1)]
)
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(1)])

def __str__(self):
return f"{self.product.name} - {self.quantity}x"
Expand Down
21 changes: 10 additions & 11 deletions src/bobvance/base/urls.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
from django.urls import path, include
from django.urls import include, path

from bobvance.base.views import (
Home,
ProductsView,
ProductDetailView,
AboutUsView,
AddToCartView,
CartView,
UpdateCartView,
RemoveFromCartView,
Home,
NewProductsView,
OrderView,
ProductDetailView,
ProductsView,
RemoveFromCartView,
SuccessView,
AboutUsView,
NewProductsView,
UpdateCartView,
UsedProductsView,
)

urlpatterns = [
path("", Home.as_view(), name="home"),
path("products/", ProductsView.as_view(), name="products"),
path(
"product/<int:pk>/", ProductDetailView.as_view(), name="product_detail"
),
path("product/<int:pk>/", ProductDetailView.as_view(), name="product_detail"),
path("add-to-cart/", AddToCartView.as_view(), name="add_to_cart"),
path("cart/", CartView.as_view(), name="cart"),
path("update-cart/", UpdateCartView.as_view(), name="update_cart"),
Expand Down
27 changes: 8 additions & 19 deletions src/bobvance/base/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from bobvance.base.models import Product, Order, OrderProduct, Customer
from django.views.generic import (
ListView,
DetailView,
TemplateView,
View,
FormView,
)
from django.shortcuts import get_object_or_404, render, redirect
from django.http import JsonResponse

from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.views.generic import DetailView, FormView, ListView, TemplateView, View

from bobvance.base.forms import CustomerForm
from bobvance.base.models import Customer, Order, OrderProduct, Product


class Home(TemplateView):
Expand Down Expand Up @@ -53,9 +46,9 @@ class ProductDetailView(DetailView):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["more_products"] = Product.objects.exclude(
pk=self.object.pk
).order_by("?")[:5]
context["more_products"] = Product.objects.exclude(pk=self.object.pk).order_by(
"?"
)[:5]
return context


Expand Down Expand Up @@ -179,9 +172,7 @@ def form_valid(self, form):
)

customer = form.save()
order = Order.objects.create(
customer=customer, total_price=total_price
)
order = Order.objects.create(customer=customer, total_price=total_price)

for product in cart_items:
OrderProduct.objects.create(
Expand All @@ -204,9 +195,7 @@ class SuccessView(TemplateView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["order"] = get_object_or_404(Order, pk=self.kwargs["pk"])
context["orderproduct"] = OrderProduct.objects.filter(
order=context["order"]
)
context["orderproduct"] = OrderProduct.objects.filter(order=context["order"])
return context


Expand Down
20 changes: 5 additions & 15 deletions src/bobvance/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@

LANGUAGE_CODE = "nl-nl"

TIME_ZONE = (
"Europe/Amsterdam" # note: this *may* affect the output of DRF datetimes
)
TIME_ZONE = "Europe/Amsterdam" # note: this *may* affect the output of DRF datetimes

USE_I18N = True

Expand Down Expand Up @@ -218,9 +216,7 @@
"verbose": {
"format": "%(asctime)s %(levelname)s %(name)s %(module)s %(process)d %(thread)d %(message)s"
},
"timestamped": {
"format": "%(asctime)s %(levelname)s %(name)s %(message)s"
},
"timestamped": {"format": "%(asctime)s %(levelname)s %(name)s %(message)s"},
"simple": {"format": "%(levelname)s %(message)s"},
"performance": {
"format": "%(asctime)s %(process)d | %(thread)d | %(message)s",
Expand Down Expand Up @@ -298,12 +294,8 @@
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"
},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]


Expand Down Expand Up @@ -426,9 +418,7 @@
#
# Maykin fork of DJANGO-TWO-FACTOR-AUTH
#
TWO_FACTOR_FORCE_OTP_ADMIN = config(
"TWO_FACTOR_FORCE_OTP_ADMIN", default=not DEBUG
)
TWO_FACTOR_FORCE_OTP_ADMIN = config("TWO_FACTOR_FORCE_OTP_ADMIN", default=not DEBUG)
TWO_FACTOR_PATCH_ADMIN = config("TWO_FACTOR_PATCH_ADMIN", default=True)

#
Expand Down
8 changes: 2 additions & 6 deletions src/bobvance/conf/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

# The file storage engine to use when collecting static files with the
# collectstatic management command.
STATICFILES_STORAGE = (
"django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
)
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"

# Production logging facility.

Expand Down Expand Up @@ -66,9 +64,7 @@
##############################

# APM
MIDDLEWARE = [
"elasticapm.contrib.django.middleware.TracingMiddleware"
] + MIDDLEWARE
MIDDLEWARE = ["elasticapm.contrib.django.middleware.TracingMiddleware"] + MIDDLEWARE
INSTALLED_APPS = INSTALLED_APPS + [
"elasticapm.contrib.django",
]
Expand Down
4 changes: 1 addition & 3 deletions src/bobvance/conf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def get_sentry_integrations() -> list:

try:
from sentry_sdk.integrations import celery
except (
DidNotEnable
): # happens if the celery import fails by the integration
except DidNotEnable: # happens if the celery import fails by the integration
pass
else:
extra.append(celery.CeleryIntegration())
Expand Down
1 change: 1 addition & 0 deletions src/bobvance/contact/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin

from bobvance.contact.models import Contact

# Register your models here.
Expand Down
1 change: 1 addition & 0 deletions src/bobvance/contact/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django import forms

from .models import Contact


Expand Down
1 change: 1 addition & 0 deletions src/bobvance/contact/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import factory

from bobvance.contact.models import Contact


Expand Down
4 changes: 3 additions & 1 deletion src/bobvance/contact/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django_webtest import WebTest
from django.urls import reverse

from django_webtest import WebTest

from bobvance.contact.models import Contact
from bobvance.contact.tests.factories import ContactFactory

Expand Down
Loading
Loading