diff --git a/backend/accounts/admin.py b/backend/accounts/admin.py index 0612f79..05c69c4 100644 --- a/backend/accounts/admin.py +++ b/backend/accounts/admin.py @@ -1,6 +1,7 @@ from django import forms from django.contrib import admin from django.contrib.auth.admin import UserAdmin + from .models import CustomUser diff --git a/backend/accounts/models.py b/backend/accounts/models.py index a412105..63294f7 100644 --- a/backend/accounts/models.py +++ b/backend/accounts/models.py @@ -1,10 +1,11 @@ -from django.db import models -from django.contrib.auth.models import AbstractUser -from django.urls import reverse -from django_resized import ResizedImageField -from django.utils import timezone from datetime import timedelta +from django.contrib.auth.models import AbstractUser +from django.db import models +from django.urls import reverse +from django.utils import timezone +from django_resized import ResizedImageField + class CustomUser(AbstractUser): # first_name inherited from base user class diff --git a/backend/accounts/serializers.py b/backend/accounts/serializers.py index 8f96d97..97385b7 100644 --- a/backend/accounts/serializers.py +++ b/backend/accounts/serializers.py @@ -1,12 +1,12 @@ -from djoser.serializers import UserSerializer as BaseUserSerializer -from rest_framework.serializers import ModelSerializer, ImageField -from rest_framework import serializers from accounts.models import CustomUser -from user_groups.serializers import SimpleUserGroupSerializer -from django.core.cache import cache -from django.core import exceptions as django_exceptions -from rest_framework.settings import api_settings from django.contrib.auth.password_validation import validate_password +from django.core import exceptions as django_exceptions +from django.core.cache import cache +from djoser.serializers import UserSerializer as BaseUserSerializer +from rest_framework import serializers +from rest_framework.serializers import ImageField, ModelSerializer +from rest_framework.settings import api_settings +from user_groups.serializers import SimpleUserGroupSerializer # There can be multiple subject instances with the same name, only differing in course, year level, and semester. We filter them here diff --git a/backend/accounts/signals.py b/backend/accounts/signals.py index 185781a..aabbc68 100644 --- a/backend/accounts/signals.py +++ b/backend/accounts/signals.py @@ -1,10 +1,12 @@ +import json +import os + +from config.settings import ROOT_DIR, SEED_DATA, get_secret from django.db.models.signals import post_migrate from django.dispatch import receiver -from config.settings import SEED_DATA, ROOT_DIR, get_secret -from django_celery_beat.models import PeriodicTask, CrontabSchedule +from django_celery_beat.models import CrontabSchedule, PeriodicTask + from .models import CustomUser -import os -import json # Function to fill in users table with test data on dev/staging diff --git a/backend/accounts/urls.py b/backend/accounts/urls.py index af98b55..894e0ea 100644 --- a/backend/accounts/urls.py +++ b/backend/accounts/urls.py @@ -1,6 +1,6 @@ -from django.urls import path, include -from rest_framework.routers import DefaultRouter from accounts import views +from django.urls import include, path +from rest_framework.routers import DefaultRouter router = DefaultRouter() router.register(r"users", views.CustomUserViewSet, basename="users") diff --git a/backend/accounts/validators.py b/backend/accounts/validators.py index c573e46..ea08952 100644 --- a/backend/accounts/validators.py +++ b/backend/accounts/validators.py @@ -1,6 +1,7 @@ +import re + from django.core.exceptions import ValidationError from django.utils.translation import gettext as _ -import re class UppercaseValidator(object): diff --git a/backend/accounts/views.py b/backend/accounts/views.py index 5b6d1da..fa778de 100644 --- a/backend/accounts/views.py +++ b/backend/accounts/views.py @@ -1,15 +1,15 @@ -from rest_framework import status -from accounts.models import CustomUser from accounts import serializers -from rest_framework.decorators import action -from rest_framework.response import Response -from djoser.conf import settings -from djoser.views import UserViewSet as DjoserUserViewSet +from accounts.models import CustomUser from django.contrib.auth.tokens import default_token_generator +from django.core.cache import cache from djoser import signals from djoser.compat import get_user_email -from django.core.cache import cache +from djoser.conf import settings +from djoser.views import UserViewSet as DjoserUserViewSet +from rest_framework import status +from rest_framework.decorators import action from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response class CustomUserViewSet(DjoserUserViewSet): diff --git a/backend/api/urls.py b/backend/api/urls.py index 0606328..8b34203 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -1,13 +1,13 @@ +from config.settings import DEBUG, MEDIA_ROOT, SERVE_MEDIA from django.conf.urls.static import static +from django.contrib import admin from django.contrib.staticfiles.urls import staticfiles_urlpatterns -from django.urls import path, include +from django.urls import include, path from drf_spectacular.views import ( SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView, ) -from django.contrib import admin -from config.settings import DEBUG, SERVE_MEDIA, MEDIA_ROOT urlpatterns = [ path("accounts/", include("accounts.urls")), diff --git a/backend/billing/urls.py b/backend/billing/urls.py index ab2bb02..d4bdd72 100644 --- a/backend/billing/urls.py +++ b/backend/billing/urls.py @@ -1,5 +1,5 @@ -from django.urls import path from billing import views +from django.urls import path urlpatterns = [ path("", views.BillingHistoryView.as_view()), diff --git a/backend/billing/views.py b/backend/billing/views.py index e81f83c..93086bc 100644 --- a/backend/billing/views.py +++ b/backend/billing/views.py @@ -1,12 +1,12 @@ -from rest_framework import status -from rest_framework.views import APIView -from rest_framework.response import Response -from rest_framework.permissions import IsAuthenticated +from datetime import datetime + +import stripe from config.settings import STRIPE_SECRET_KEY from django.core.cache import cache -from datetime import datetime -import stripe - +from rest_framework import status +from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework.views import APIView # Make sure to set your secret key stripe.api_key = STRIPE_SECRET_KEY diff --git a/backend/config/celery.py b/backend/config/celery.py index 0def3f9..3d3db7d 100644 --- a/backend/config/celery.py +++ b/backend/config/celery.py @@ -1,6 +1,6 @@ -from celery import Celery import os +from celery import Celery # Set the default Django settings module for the 'celery' program. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") diff --git a/backend/config/settings.py b/backend/config/settings.py index 9fa14d6..ee5101b 100644 --- a/backend/config/settings.py +++ b/backend/config/settings.py @@ -1,7 +1,8 @@ +import os from datetime import timedelta from pathlib import Path -from dotenv import load_dotenv, find_dotenv # Python dotenv -import os + +from dotenv import find_dotenv, load_dotenv # Python dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. # Backend folder (/backend) diff --git a/backend/config/urls.py b/backend/config/urls.py index d9e0921..b3788e1 100644 --- a/backend/config/urls.py +++ b/backend/config/urls.py @@ -1,4 +1,4 @@ -from django.urls import path, include +from django.urls import include, path urlpatterns = [ path("api/v1/", include("api.urls")), diff --git a/backend/emails/templates.py b/backend/emails/templates.py index 02fde41..056fc28 100644 --- a/backend/emails/templates.py +++ b/backend/emails/templates.py @@ -1,5 +1,5 @@ -from djoser import email from django.utils import timezone +from djoser import email class ActivationEmail(email.ActivationEmail): diff --git a/backend/notifications/admin.py b/backend/notifications/admin.py index c6668f7..2dd1517 100644 --- a/backend/notifications/admin.py +++ b/backend/notifications/admin.py @@ -1,5 +1,6 @@ -from unfold.admin import ModelAdmin from django.contrib import admin +from unfold.admin import ModelAdmin + from .models import Notification diff --git a/backend/notifications/serializers.py b/backend/notifications/serializers.py index e6e5cb1..60ea673 100644 --- a/backend/notifications/serializers.py +++ b/backend/notifications/serializers.py @@ -1,5 +1,5 @@ -from rest_framework import serializers from notifications.models import Notification +from rest_framework import serializers class NotificationSerializer(serializers.ModelSerializer): diff --git a/backend/notifications/signals.py b/backend/notifications/signals.py index 35cfedf..5d98218 100644 --- a/backend/notifications/signals.py +++ b/backend/notifications/signals.py @@ -1,7 +1,7 @@ -from django.dispatch import receiver -from django.db.models.signals import post_save -from notifications.models import Notification from django.core.cache import cache +from django.db.models.signals import post_save +from django.dispatch import receiver +from notifications.models import Notification # Template for running actions after user have paid for a subscription diff --git a/backend/notifications/urls.py b/backend/notifications/urls.py index 5d62fd1..fe442a8 100644 --- a/backend/notifications/urls.py +++ b/backend/notifications/urls.py @@ -1,4 +1,4 @@ -from django.urls import path, include +from django.urls import include, path from notifications.views import NotificationViewSet from rest_framework.routers import DefaultRouter diff --git a/backend/notifications/views.py b/backend/notifications/views.py index feb0413..0057b6e 100644 --- a/backend/notifications/views.py +++ b/backend/notifications/views.py @@ -1,8 +1,8 @@ -from rest_framework import viewsets +from django.core.cache import cache from notifications.models import Notification from notifications.serializers import NotificationSerializer +from rest_framework import viewsets from rest_framework.exceptions import PermissionDenied -from django.core.cache import cache class NotificationViewSet(viewsets.ModelViewSet): diff --git a/backend/payments/urls.py b/backend/payments/urls.py index 6354e7f..f837427 100644 --- a/backend/payments/urls.py +++ b/backend/payments/urls.py @@ -1,7 +1,6 @@ from django.urls import path from payments import views - urlpatterns = [ path("checkout_session/", views.StripeCheckoutView.as_view()), path("webhook/", views.stripe_webhook_view, name="Stripe Webhook"), diff --git a/backend/payments/views.py b/backend/payments/views.py index 3adac0b..968ff13 100644 --- a/backend/payments/views.py +++ b/backend/payments/views.py @@ -1,31 +1,32 @@ +import json +import logging + +import stripe +from accounts.models import CustomUser from config.settings import ( + FRONTEND_ADDRESS, + FRONTEND_PORT, STRIPE_SECRET_KEY, STRIPE_SECRET_WEBHOOK, URL_SCHEME, - FRONTEND_ADDRESS, - FRONTEND_PORT, -) -from rest_framework.permissions import IsAuthenticated -from rest_framework.views import APIView -from rest_framework.response import Response -from django.http import HttpResponse -from django.views.decorators.csrf import csrf_exempt -from rest_framework import status -import logging -import stripe -from subscriptions.models import SubscriptionPlan, UserSubscription -from accounts.models import CustomUser -from rest_framework.decorators import api_view -from subscriptions.tasks import get_user_subscription -import json -from emails.templates import ( - SubscriptionAvailedEmail, - SubscriptionRefundedEmail, - SubscriptionCancelledEmail, ) from django.core.cache import cache -from payments.serializers import CheckoutSerializer +from django.http import HttpResponse +from django.views.decorators.csrf import csrf_exempt from drf_spectacular.utils import extend_schema +from emails.templates import ( + SubscriptionAvailedEmail, + SubscriptionCancelledEmail, + SubscriptionRefundedEmail, +) +from payments.serializers import CheckoutSerializer +from rest_framework import status +from rest_framework.decorators import api_view +from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework.views import APIView +from subscriptions.models import SubscriptionPlan, UserSubscription +from subscriptions.tasks import get_user_subscription stripe.api_key = STRIPE_SECRET_KEY diff --git a/backend/search_results/admin.py b/backend/search_results/admin.py index b2415f9..070d1c1 100644 --- a/backend/search_results/admin.py +++ b/backend/search_results/admin.py @@ -1,8 +1,9 @@ -from unfold.admin import ModelAdmin from django.contrib import admin -from .models import SearchResult +from unfold.admin import ModelAdmin from unfold.contrib.filters.admin import RangeDateFilter +from .models import SearchResult + @admin.register(SearchResult) class SearchResultAdmin(ModelAdmin): diff --git a/backend/search_results/tasks.py b/backend/search_results/tasks.py index 7c35008..f4a2a91 100644 --- a/backend/search_results/tasks.py +++ b/backend/search_results/tasks.py @@ -1,4 +1,5 @@ from celery import shared_task + from .models import SearchResult diff --git a/backend/subscriptions/models.py b/backend/subscriptions/models.py index 871c2ea..4172d15 100644 --- a/backend/subscriptions/models.py +++ b/backend/subscriptions/models.py @@ -1,7 +1,7 @@ -from django.db import models from accounts.models import CustomUser -from user_groups.models import UserGroup +from django.db import models from django.utils.timezone import now +from user_groups.models import UserGroup class StripePrice(models.Model): diff --git a/backend/subscriptions/serializers.py b/backend/subscriptions/serializers.py index 00243b4..e858450 100644 --- a/backend/subscriptions/serializers.py +++ b/backend/subscriptions/serializers.py @@ -1,6 +1,6 @@ -from rest_framework import serializers -from subscriptions.models import SubscriptionPlan, UserSubscription, StripePrice from accounts.serializers import SimpleCustomUserSerializer +from rest_framework import serializers +from subscriptions.models import StripePrice, SubscriptionPlan, UserSubscription class SimpleStripePriceSerializer(serializers.ModelSerializer): diff --git a/backend/subscriptions/signals.py b/backend/subscriptions/signals.py index c47c738..a497c38 100644 --- a/backend/subscriptions/signals.py +++ b/backend/subscriptions/signals.py @@ -1,9 +1,10 @@ -from django.dispatch import receiver -from django.db.models.signals import post_migrate, post_save -from .models import UserSubscription, StripePrice, SubscriptionPlan -from django.core.cache import cache -from config.settings import STRIPE_SECRET_KEY import stripe +from config.settings import STRIPE_SECRET_KEY +from django.core.cache import cache +from django.db.models.signals import post_migrate, post_save +from django.dispatch import receiver + +from .models import StripePrice, SubscriptionPlan, UserSubscription stripe.api_key = STRIPE_SECRET_KEY diff --git a/backend/subscriptions/tasks.py b/backend/subscriptions/tasks.py index a7f8d1f..16a6629 100644 --- a/backend/subscriptions/tasks.py +++ b/backend/subscriptions/tasks.py @@ -3,8 +3,8 @@ from celery import shared_task @shared_task def get_user_subscription(user_id): - from subscriptions.models import UserSubscription from accounts.models import CustomUser + from subscriptions.models import UserSubscription USER = CustomUser.objects.get(id=user_id) diff --git a/backend/subscriptions/urls.py b/backend/subscriptions/urls.py index 5dbbb5a..6cba16d 100644 --- a/backend/subscriptions/urls.py +++ b/backend/subscriptions/urls.py @@ -1,6 +1,6 @@ -from django.urls import path, include -from subscriptions import views +from django.urls import include, path from rest_framework.routers import DefaultRouter +from subscriptions import views router = DefaultRouter() router.register(r"plans", views.SubscriptionPlanViewset, basename="Subscription Plans") diff --git a/backend/subscriptions/views.py b/backend/subscriptions/views.py index 49b3e2d..8a1f44e 100644 --- a/backend/subscriptions/views.py +++ b/backend/subscriptions/views.py @@ -1,11 +1,11 @@ +from django.core.cache import cache +from rest_framework import viewsets +from rest_framework.permissions import AllowAny, IsAuthenticated +from subscriptions.models import SubscriptionPlan, UserSubscription from subscriptions.serializers import ( SubscriptionPlanSerializer, UserSubscriptionSerializer, ) -from subscriptions.models import SubscriptionPlan, UserSubscription -from rest_framework.permissions import AllowAny, IsAuthenticated -from rest_framework import viewsets -from django.core.cache import cache class SubscriptionPlanViewset(viewsets.ModelViewSet): diff --git a/backend/user_groups/admin.py b/backend/user_groups/admin.py index 54a8f8b..99543e1 100644 --- a/backend/user_groups/admin.py +++ b/backend/user_groups/admin.py @@ -1,8 +1,9 @@ from django.contrib import admin from unfold.admin import ModelAdmin -from .models import UserGroup from unfold.contrib.filters.admin import RangeDateFilter +from .models import UserGroup + @admin.register(UserGroup) class UserGroupAdmin(ModelAdmin): diff --git a/backend/user_groups/models.py b/backend/user_groups/models.py index 4ecce67..3f5c9d7 100644 --- a/backend/user_groups/models.py +++ b/backend/user_groups/models.py @@ -1,7 +1,7 @@ +import stripe +from config.settings import STRIPE_SECRET_KEY from django.db import models from django.utils.timezone import now -from config.settings import STRIPE_SECRET_KEY -import stripe stripe.api_key = STRIPE_SECRET_KEY diff --git a/backend/user_groups/serializers.py b/backend/user_groups/serializers.py index b82a0ea..e6eca20 100644 --- a/backend/user_groups/serializers.py +++ b/backend/user_groups/serializers.py @@ -1,4 +1,5 @@ from rest_framework import serializers + from .models import UserGroup diff --git a/backend/user_groups/signals.py b/backend/user_groups/signals.py index 28e151e..62fb873 100644 --- a/backend/user_groups/signals.py +++ b/backend/user_groups/signals.py @@ -1,13 +1,15 @@ -from subscriptions.models import SubscriptionPlan +import json +import os + +import stripe from accounts.models import CustomUser -from .models import UserGroup -from subscriptions.tasks import get_user_group_subscription +from config.settings import ROOT_DIR, STRIPE_SECRET_KEY from django.db.models.signals import m2m_changed, post_migrate from django.dispatch import receiver -from config.settings import STRIPE_SECRET_KEY, ROOT_DIR -import os -import json -import stripe +from subscriptions.models import SubscriptionPlan +from subscriptions.tasks import get_user_group_subscription + +from .models import UserGroup stripe.api_key = STRIPE_SECRET_KEY diff --git a/backend/webdriver/tasks.py b/backend/webdriver/tasks.py index 6bf0381..5df15f5 100644 --- a/backend/webdriver/tasks.py +++ b/backend/webdriver/tasks.py @@ -1,13 +1,13 @@ from celery import shared_task +from search_results.tasks import create_search_result +from selenium.webdriver.common.by import By from webdriver.utils import ( - setup_webdriver, - selenium_action_template, - google_search, get_element, get_elements, + google_search, + selenium_action_template, + setup_webdriver, ) -from selenium.webdriver.common.by import By -from search_results.tasks import create_search_result # Task template diff --git a/backend/webdriver/utils.py b/backend/webdriver/utils.py index fdee0da..aa71f51 100644 --- a/backend/webdriver/utils.py +++ b/backend/webdriver/utils.py @@ -2,21 +2,20 @@ Settings file to hold constants and functions """ +import os +import random + +import undetected_chromedriver as uc +from config.settings import CAPTCHA_TESTING, USE_PROXY, get_secret +from selenium import webdriver +from selenium.webdriver import FirefoxOptions from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys -from config.settings import get_secret -from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC -from selenium.webdriver import FirefoxOptions -from selenium import webdriver -import undetected_chromedriver as uc -from config.settings import USE_PROXY, CAPTCHA_TESTING -from config.settings import get_secret +from selenium.webdriver.support.ui import WebDriverWait from twocaptcha import TwoCaptcha from whois import whois from whois.parser import PywhoisError -import os -import random def take_snapshot(driver, filename="dump.png"): @@ -249,7 +248,7 @@ def execute_selenium_elements(driver, timeout, elements): element["default"]["key"], timeout=timeout, ) - except Exception as e: + except Exception: print(f"Failed to find primary element") # If that fails, try to get the failover one print("Trying to find legacy element")