Skip to content

Commit

Permalink
chore: Upgrade Django to 4.2.x (#1538)
Browse files Browse the repository at this point in the history
* chore: Upgrade Django to 4.2.13
  • Loading branch information
arslanashraf7 authored Jul 26, 2024
1 parent 17ec138 commit ffc8179
Show file tree
Hide file tree
Showing 36 changed files with 286 additions and 347 deletions.
4 changes: 0 additions & 4 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,6 @@
"description": "The SL tracking ID",
"required": false
},
"STATUS_TOKEN": {
"description": "Token to access the status API.",
"required": true
},
"USE_X_FORWARDED_HOST": {
"description": "Set HOST header to original domain accessed by user",
"required": false
Expand Down
2 changes: 0 additions & 2 deletions applications/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
"""Initialize applications app"""

default_app_config = "applications.apps.ApplicationConfig"
144 changes: 78 additions & 66 deletions applications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,42 @@
from django.utils.safestring import mark_safe
from mitol.common.admin import TimestampedModelAdmin

from applications import models
from applications.models import (
ApplicationStep,
ApplicationStepSubmission,
BootcampRunApplicationStep,
BootcampApplication,
VideoInterviewSubmission,
QuizSubmission,
ApplicantLetter,
Interview,
)
from ecommerce.models import Order
from main.utils import get_field_names


@admin.register(ApplicationStep)
class ApplicationStepAdmin(admin.ModelAdmin):
"""Admin for ApplicationStep"""

model = models.ApplicationStep
model = ApplicationStep
list_display = ("id", "get_bootcamp_title", "submission_type", "step_order")
ordering = ("bootcamp", "step_order")

@admin.display(
description="Bootcamp",
ordering="bootcamp__title",
)
def get_bootcamp_title(self, obj):
"""Returns the bootcamp title"""
return obj.bootcamp.title

get_bootcamp_title.short_description = "Bootcamp"
get_bootcamp_title.admin_order_field = "bootcamp__title"


@admin.register(BootcampRunApplicationStep)
class BootcampRunApplicationStepAdmin(admin.ModelAdmin):
"""Admin for BootcampRunApplicationStep"""

model = models.BootcampRunApplicationStep
model = BootcampRunApplicationStep
list_display = (
"id",
"get_run_display_title",
Expand All @@ -53,27 +65,30 @@ def get_queryset(self, request):
"""Overrides base queryset"""
return super().get_queryset(request).select_related("bootcamp_run__bootcamp")

@admin.display(
description="Bootcamp Run",
ordering="bootcamp_run__title",
)
def get_run_display_title(self, obj):
"""Returns the bootcamp run display title"""
return obj.bootcamp_run.display_title

get_run_display_title.short_description = "Bootcamp Run"
get_run_display_title.admin_order_field = "bootcamp_run__title"

@admin.display(
description="Submission Type",
ordering="application_step__submission_type",
)
def get_submission_type(self, obj):
"""Returns the application step submission type"""
return obj.application_step.submission_type

get_submission_type.short_description = "Submission Type"
get_submission_type.admin_order_field = "application_step__submission_type"

@admin.display(
description="Step Order",
ordering="application_step__step_order",
)
def get_step_order(self, obj):
"""Returns the application step order"""
return obj.application_step.step_order

get_step_order.short_description = "Step Order"
get_step_order.admin_order_field = "application_step__step_order"


class OrderInline(admin.StackedInline):
"""Inline form for Order"""
Expand All @@ -90,10 +105,11 @@ def has_add_permission(self, request, obj=None):
return False


@admin.register(BootcampApplication)
class BootcampApplicationAdmin(TimestampedModelAdmin):
"""Admin for BootcampApplication"""

model = models.BootcampApplication
model = BootcampApplication
include_timestamps_in_list = True
inlines = [OrderInline]
list_display = ("id", "get_user_email", "get_run_display_title", "state")
Expand All @@ -114,25 +130,27 @@ def get_queryset(self, request):
.select_related("user", "bootcamp_run__bootcamp")
)

@admin.display(
description="User",
ordering="user__email",
)
def get_user_email(self, obj):
"""Returns the user email"""
return obj.user.email

get_user_email.short_description = "User"
get_user_email.admin_order_field = "user__email"

@admin.display(
description="Bootcamp Run",
ordering="bootcamp_run__title",
)
def get_run_display_title(self, obj):
"""Returns the bootcamp run display title"""
return obj.bootcamp_run.display_title

get_run_display_title.short_description = "Bootcamp Run"
get_run_display_title.admin_order_field = "bootcamp_run__title"


class AppStepSubmissionInline(GenericTabularInline):
"""Admin class for ApplicationStepSubmission"""

model = models.ApplicationStepSubmission
model = ApplicationStepSubmission
max_num = 1
raw_id_fields = ("bootcamp_application", "run_application_step")

Expand Down Expand Up @@ -170,6 +188,10 @@ def get_queryset(self, request):
)
)

@admin.display(
description="Application User",
ordering="app_step_submission__bootcamp_application__user__email",
)
def get_user_email(self, obj):
"""Returns the user email"""
app_step_submissions = obj.app_step_submissions.all()
Expand All @@ -179,11 +201,10 @@ def get_user_email(self, obj):
else app_step_submissions[0].bootcamp_application.user.email
)

get_user_email.short_description = "Application User"
get_user_email.admin_order_field = (
"app_step_submission__bootcamp_application__user__email"
@admin.display(
description="App Bootcamp Run",
ordering="app_step_submission__bootcamp_application__bootcamp_run__title",
)

def get_run_display_title(self, obj):
"""Returns the bootcamp run display title"""
app_step_submissions = obj.app_step_submissions.all()
Expand All @@ -193,11 +214,7 @@ def get_run_display_title(self, obj):
else app_step_submissions[0].bootcamp_application.bootcamp_run.display_title
)

get_run_display_title.short_description = "App Bootcamp Run"
get_run_display_title.admin_order_field = (
"app_step_submission__bootcamp_application__bootcamp_run__title"
)

@admin.display(description="Submission")
def app_step_submission_link(self, obj):
"""Returns a link to the related bootcamp application"""
app_step_submissions = obj.app_step_submissions.all()
Expand All @@ -208,48 +225,47 @@ def app_step_submission_link(self, obj):
'<a href="{}">Submission ({})</a>'.format(
reverse(
"admin:applications_{}_change".format(
models.ApplicationStepSubmission._meta.model_name
ApplicationStepSubmission._meta.model_name
),
args=(app_step_submission.id,),
), # pylint: disable=protected-access
app_step_submission.id,
)
)

app_step_submission_link.short_description = "Submission"


@admin.register(VideoInterviewSubmission)
class VideoInterviewSubmissionAdmin(SubmissionTypeAdmin):
"""Admin class for VideoInterviewSubmission"""

model = models.VideoInterviewSubmission
model = VideoInterviewSubmission

raw_id_fields = ("interview",)

def get_list_display(self, request):
return tuple(super().get_list_display(request) or ()) + ("interview_link",)

@admin.display(description="Interview")
def interview_link(self, obj):
"""Returns a link to the related interview record"""
if not hasattr(obj, "interview") or obj.interview is None:
return None
return mark_safe(
'<a href="{}">Interview ({})</a>'.format(
reverse(
"admin:jobma_{}_change".format(models.Interview._meta.model_name),
"admin:jobma_{}_change".format(Interview._meta.model_name),
args=(obj.interview.id,),
), # pylint: disable=protected-access
obj.interview.id,
)
)

interview_link.short_description = "Interview"


@admin.register(QuizSubmission)
class QuizSubmissionAdmin(SubmissionTypeAdmin):
"""Admin for QuizSubmission"""

model = models.QuizSubmission
model = QuizSubmission

def get_list_display(self, request):
return tuple(super().get_list_display(request) or ()) + ("started_date",)
Expand All @@ -272,10 +288,11 @@ def clean_object_id(self):
return object_id


@admin.register(ApplicationStepSubmission)
class ApplicationStepSubmissionAdmin(TimestampedModelAdmin):
"""Admin for ApplicationStepSubmission"""

model = models.ApplicationStepSubmission
model = ApplicationStepSubmission
form = ApplicationStepSubmissionForm
list_display = (
"id",
Expand Down Expand Up @@ -313,6 +330,7 @@ def get_readonly_fields(self, request, obj=None):
return tuple(self.readonly_fields or ()) + ("content_type", "object_id")
return self.readonly_fields

@admin.display(description="submission object")
def submission_content_obj_link(self, obj):
"""Returns a link to the content object"""
if obj.content_object is None:
Expand All @@ -329,27 +347,28 @@ def submission_content_obj_link(self, obj):
)
)

submission_content_obj_link.short_description = "submission object"

@admin.display(
description="User",
ordering="user__email",
)
def get_user_email(self, obj):
"""Returns the user email"""
return obj.bootcamp_application.user.email

get_user_email.short_description = "User"
get_user_email.admin_order_field = "user__email"

@admin.display(
description="Bootcamp Run",
ordering="bootcamp_run__title",
)
def get_run_display_title(self, obj):
"""Returns the bootcamp run display title"""
return obj.bootcamp_application.bootcamp_run.display_title

get_run_display_title.short_description = "Bootcamp Run"
get_run_display_title.admin_order_field = "bootcamp_run__title"


@admin.register(ApplicantLetter)
class ApplicantLetterAdmin(TimestampedModelAdmin):
"""Admin for ApplicantLetter"""

model = models.ApplicantLetter
model = ApplicantLetter
list_display = ("id", "letter_type", "get_user_email", "get_run_display_title")
list_filter = ("letter_type",)
raw_id_fields = ("application",)
Expand All @@ -358,27 +377,20 @@ class ApplicantLetterAdmin(TimestampedModelAdmin):
"application__bootcamp_run__title",
"application__bootcamp_run__bootcamp__title",
)
readonly_fields = get_field_names(models.ApplicantLetter)
readonly_fields = get_field_names(ApplicantLetter)

@admin.display(
description="User",
ordering="user__email",
)
def get_user_email(self, obj):
"""Returns the user email"""
return obj.application.user.email

get_user_email.short_description = "User"
get_user_email.admin_order_field = "user__email"

@admin.display(
description="Bootcamp Run",
ordering="bootcamp_run__title",
)
def get_run_display_title(self, obj):
"""Returns the bootcamp run display title"""
return obj.application.bootcamp_run.display_title

get_run_display_title.short_description = "Bootcamp Run"
get_run_display_title.admin_order_field = "bootcamp_run__title"


admin.site.register(models.ApplicationStep, ApplicationStepAdmin)
admin.site.register(models.BootcampRunApplicationStep, BootcampRunApplicationStepAdmin)
admin.site.register(models.BootcampApplication, BootcampApplicationAdmin)
admin.site.register(models.VideoInterviewSubmission, VideoInterviewSubmissionAdmin)
admin.site.register(models.QuizSubmission, QuizSubmissionAdmin)
admin.site.register(models.ApplicationStepSubmission, ApplicationStepSubmissionAdmin)
admin.site.register(models.ApplicantLetter, ApplicantLetterAdmin)
8 changes: 4 additions & 4 deletions applications/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from django.urls import path
from django.conf.urls import url, include
from django.urls import include
from rest_framework import routers

from applications.views import (
Expand All @@ -20,9 +20,9 @@
router.register(r"submissions", ReviewSubmissionViewSet, basename="submissions_api")

urlpatterns = [
url(r"^api/", include(router.urls)),
url(
r"^api/applications/(?P<pk>\d+)/resume/$",
path("api/", include(router.urls)),
path(
"api/applications/<int:pk>/resume/",
UploadResumeView.as_view(),
name="upload-resume",
),
Expand Down
4 changes: 2 additions & 2 deletions authentication/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Authentication middleware"""

from urllib.parse import quote
from django.shortcuts import redirect
from django.utils.http import urlquote

from social_core.exceptions import SocialAuthBaseException
from social_django.middleware import SocialAuthExceptionMiddleware
Expand Down Expand Up @@ -31,6 +31,6 @@ def process_exception(self, request, exception):

if url:
url += ("?" in url and "&" or "?") + "message={0}&backend={1}".format(
urlquote(message), backend_name
quote(message), backend_name
)
return redirect(url)
Loading

0 comments on commit ffc8179

Please sign in to comment.