Skip to content

Commit

Permalink
Merge branch '5343-upgrade-django-in-mitxonline' of https://github.co…
Browse files Browse the repository at this point in the history
…m/mitodl/mitxonline into 5343-upgrade-django-in-mitxonline
  • Loading branch information
cp-at-mit committed Sep 9, 2024
2 parents fb2bd80 + 4146a23 commit bc3353b
Show file tree
Hide file tree
Showing 32 changed files with 122 additions and 97 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
"filename": "main/settings.py",
"hashed_secret": "09edaaba587f94f60fbb5cee2234507bcb883cc2",
"is_verified": false,
"line_number": 958
"line_number": 955
}
],
"pants": [
Expand Down Expand Up @@ -240,5 +240,5 @@
}
]
},
"generated_at": "2024-07-02T16:40:29Z"
"generated_at": "2024-09-09T19:17:25Z"
}
2 changes: 1 addition & 1 deletion authentication/middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Authentication middleware"""


from django.shortcuts import redirect
from urllib.parse import quote
from social_core.exceptions import SocialAuthBaseException
from social_django.middleware import SocialAuthExceptionMiddleware

Expand Down
3 changes: 2 additions & 1 deletion authentication/middleware_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Tests for auth middleware"""

from urllib.parse import quote

from django.contrib.sessions.middleware import SessionMiddleware
from django.shortcuts import reverse
from urllib.parse import quote
from rest_framework import status
from social_core.exceptions import AuthAlreadyAssociated
from social_django.utils import load_backend, load_strategy
Expand Down
16 changes: 0 additions & 16 deletions courses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def get_user_email(self, obj):
"""Returns the related User email"""
return obj.user.email


@admin.display(
description="Program",
ordering="program__readable_id",
Expand All @@ -172,7 +171,6 @@ def get_program_readable_id(self, obj):
return obj.program.readable_id



@admin.register(ProgramEnrollmentAudit)
class ProgramEnrollmentAuditAdmin(TimestampedModelAdmin):
"""Admin for ProgramEnrollmentAudit"""
Expand All @@ -190,7 +188,6 @@ def get_program_readable_id(self, obj):
"""Returns the related Program readable_id"""
return obj.enrollment.program.readable_id


@admin.display(
description="User",
ordering="enrollment__user__email",
Expand All @@ -199,7 +196,6 @@ def get_user(self, obj):
"""Returns the related User's email"""
return obj.enrollment.user.email


def has_add_permission(self, request): # noqa: ARG002
return False

Expand Down Expand Up @@ -276,7 +272,6 @@ def get_user_email(self, obj):
"""Returns the related User email"""
return obj.user.email


@admin.display(
description="Course Run",
ordering="run__courseware_id",
Expand All @@ -286,7 +281,6 @@ def get_run_courseware_id(self, obj):
return obj.run.courseware_id



@admin.register(CourseRunEnrollmentAudit)
class CourseRunEnrollmentAuditAdmin(TimestampedModelAdmin):
"""Admin for CourseRunEnrollmentAudit"""
Expand All @@ -309,7 +303,6 @@ def get_run_courseware_id(self, obj):
"""Returns the related CourseRun courseware_id"""
return obj.enrollment.run.courseware_id


@admin.display(
description="User",
ordering="enrollment__user__email",
Expand All @@ -318,7 +311,6 @@ def get_user(self, obj):
"""Returns the related User's email"""
return obj.enrollment.user.email


def has_add_permission(self, request): # noqa: ARG002
return False

Expand Down Expand Up @@ -364,7 +356,6 @@ def get_user_username(self, obj):
"""Returns the related User username"""
return obj.user.username


@admin.display(
description="Course Run",
ordering="course_run__courseware_id",
Expand All @@ -374,7 +365,6 @@ def get_run_courseware_id(self, obj):
return obj.course_run.courseware_id



@admin.register(CourseRunGradeAudit)
class CourseRunGradeAuditAdmin(TimestampedModelAdmin):
"""Admin for CourseRunGradeAudit"""
Expand All @@ -397,7 +387,6 @@ def get_user_email(self, obj):
"""Returns the related User email"""
return obj.course_run_grade.user.email


@admin.display(
description="Course Run",
ordering="course_run_grade__course_run__courseware_id",
Expand All @@ -406,7 +395,6 @@ def get_run_courseware_id(self, obj):
"""Returns the related CourseRun courseware_id"""
return obj.course_run_grade.course_run.courseware_id


def has_add_permission(self, request): # noqa: ARG002
return False

Expand Down Expand Up @@ -493,7 +481,6 @@ def get_revoked_state(self, obj):
"""Return the revoked state"""
return obj.is_revoked is not True


def get_queryset(self, request): # noqa: ARG002
return self.model.all_objects.get_queryset().select_related(
"user", "course_run"
Expand Down Expand Up @@ -529,7 +516,6 @@ def get_revoked_state(self, obj):
"""Return the revoked state"""
return obj.is_revoked is not True


def get_queryset(self, request): # noqa: ARG002
return self.model.all_objects.get_queryset().select_related("user", "program")

Expand Down Expand Up @@ -559,5 +545,3 @@ class RelatedProgramAdmin(admin.ModelAdmin):
model = RelatedProgram
list_display = ("id", "first_program", "second_program")
list_filter = ["first_program", "second_program"]


4 changes: 2 additions & 2 deletions courses/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django.db import IntegrityError, transaction
from django.db.models import Q
from django.db.models.query import QuerySet
from ecommerce.models import OrderStatus
from mitol.common.utils import now_in_utc
from mitol.common.utils.collections import (
first_or_none,
Expand Down Expand Up @@ -42,6 +41,7 @@
is_grade_valid,
is_letter_grade_valid,
)
from ecommerce.models import OrderStatus
from openedx.api import (
enroll_in_edx_course_runs,
get_edx_api_course_detail_client,
Expand Down Expand Up @@ -260,7 +260,7 @@ def deactivate_run_enrollment(
Returns:
CourseRunEnrollment: The deactivated enrollment
"""
from ecommerce.models import Line, Order
from ecommerce.models import Line
from hubspot_sync.task_helpers import sync_hubspot_line_by_line_id

try:
Expand Down
2 changes: 1 addition & 1 deletion courses/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
ProgramRequirementNodeType,
)
from ecommerce.factories import LineFactory, OrderFactory, ProductFactory
from ecommerce.models import Order, OrderStatus
from ecommerce.models import OrderStatus
from main.test_utils import MockHttpError
from openedx.constants import (
EDX_DEFAULT_ENROLLMENT_MODE,
Expand Down
2 changes: 1 addition & 1 deletion courses/management/commands/test_unenroll_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from courses.management.commands import unenroll_enrollment
from ecommerce.factories import LineFactory, OrderFactory, ProductFactory
from ecommerce.models import Order, OrderStatus
from ecommerce.models import OrderStatus
from users.factories import UserFactory

pytestmark = [pytest.mark.django_db]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@


class Migration(migrations.Migration):

dependencies = [
('courses', '0054_add_program_availability'),
("courses", "0054_add_program_availability"),
]

operations = [
migrations.RenameIndex(
model_name='programrequirement',
new_name='courses_pro_program_c8ff7c_idx',
old_fields=('program', 'course'),
model_name="programrequirement",
new_name="courses_pro_program_c8ff7c_idx",
old_fields=("program", "course"),
),
migrations.RenameIndex(
model_name='programrequirement',
new_name='courses_pro_course__fdcdb6_idx',
old_fields=('course', 'program'),
model_name="programrequirement",
new_name="courses_pro_course__fdcdb6_idx",
old_fields=("course", "program"),
),
]
5 changes: 4 additions & 1 deletion courses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,10 @@ class Meta:
condition=Q(depth=1),
),
)
indexes = [models.Index(fields=("program", "course")), models.Index(fields=("course", "program"))]
indexes = [
models.Index(fields=("program", "course")),
models.Index(fields=("course", "program")),
]


class PartnerSchool(TimestampedModel):
Expand Down
2 changes: 1 addition & 1 deletion courses/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
limit_to_certificate_pages,
)
from ecommerce.factories import OrderFactory, ProductFactory
from ecommerce.models import Order, OrderStatus
from ecommerce.models import OrderStatus
from main.test_utils import format_as_iso8601
from users.factories import UserFactory

Expand Down
3 changes: 1 addition & 2 deletions courses/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging

from django.db.models import Q
from ecommerce.models import OrderStatus
from mitol.common.utils.datetime import now_in_utc

from courses.models import (
Expand All @@ -14,6 +13,7 @@
LearnerProgramRecordShare,
PaidCourseRun,
)
from ecommerce.models import OrderStatus
from main.celery import app

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -81,7 +81,6 @@ def clear_unenrolled_paid_course_run(enrollment_id):
these exist, the user won't be able to re-buy into the course later if they
want to.
"""
from ecommerce.models import Order

try:
enrollment = CourseRunEnrollment.all_objects.filter(id=enrollment_id).get()
Expand Down
2 changes: 1 addition & 1 deletion courses/tasks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
subscribe_edx_course_emails,
)
from ecommerce.factories import OrderFactory
from ecommerce.models import Order, OrderStatus
from ecommerce.models import OrderStatus

pytestmark = pytest.mark.django_db

Expand Down
10 changes: 4 additions & 6 deletions ecommerce/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,12 @@ class BaseOrderAdmin(fsm.FlowAdminMixin, TimestampedModelAdmin):
inlines = [OrderLineInline, OrderDiscountInline, OrderTransactionInline]
readonly_fields = ["reference_number"]
flow_state = OrderFlow.state

def get_transition_fields(self, request, obj, slug):
return ['state']
return ["state"]

def get_object_flow(self, request, obj):
return OrderFlow(
obj, user=request.user
)
return OrderFlow(obj, user=request.user)

def has_change_permission(self, request, obj=None): # noqa: ARG002
return False
Expand Down
1 change: 0 additions & 1 deletion ecommerce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
DiscountRedemption,
FulfilledOrder,
Order,
OrderFlow,
OrderStatus,
PendingOrder,
UserDiscount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mitol.common.utils.datetime import now_in_utc

from courses.models import CourseRun, CourseRunEnrollment
from ecommerce.models import Line, Order, OrderStatus
from ecommerce.models import Line, OrderStatus


class Command(BaseCommand):
Expand Down
12 changes: 11 additions & 1 deletion ecommerce/migrations/0008_add_order_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ class Migration(migrations.Migration):
("updated_on", models.DateTimeField(auto_now=True)),
(
"state",
models.CharField(choices=[('pending', 'Pending'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled'), ('declined', 'Declined'), ('errored', 'Errored'), ('refunded', 'Refunded'), ('review', 'Review'), ('partially_refunded', 'Partially Refunded')],
models.CharField(
choices=[
("pending", "Pending"),
("fulfilled", "Fulfilled"),
("canceled", "Canceled"),
("declined", "Declined"),
("errored", "Errored"),
("refunded", "Refunded"),
("review", "Review"),
("partially_refunded", "Partially Refunded"),
],
default="pending",
max_length=50,
),
Expand Down
12 changes: 11 additions & 1 deletion ecommerce/migrations/0012_model_related_field_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,17 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="order",
name="state",
field=models.CharField(choices=[('pending', 'Pending'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled'), ('declined', 'Declined'), ('errored', 'Errored'), ('refunded', 'Refunded'), ('review', 'Review'), ('partially_refunded', 'Partially Refunded')],
field=models.CharField(
choices=[
("pending", "Pending"),
("fulfilled", "Fulfilled"),
("canceled", "Canceled"),
("declined", "Declined"),
("errored", "Errored"),
("refunded", "Refunded"),
("review", "Review"),
("partially_refunded", "Partially Refunded"),
],
default="pending",
max_length=50,
),
Expand Down
12 changes: 11 additions & 1 deletion ecommerce/migrations/0015_add_review_status_to_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,17 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="order",
name="state",
field=models.CharField(choices=[('pending', 'Pending'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled'), ('declined', 'Declined'), ('errored', 'Errored'), ('refunded', 'Refunded'), ('review', 'Review'), ('partially_refunded', 'Partially Refunded')],
field=models.CharField(
choices=[
("pending", "Pending"),
("fulfilled", "Fulfilled"),
("canceled", "Canceled"),
("declined", "Declined"),
("errored", "Errored"),
("refunded", "Refunded"),
("review", "Review"),
("partially_refunded", "Partially Refunded"),
],
default="pending",
max_length=50,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="order",
name="state",
field=models.CharField(choices=[('pending', 'Pending'), ('fulfilled', 'Fulfilled'), ('canceled', 'Canceled'), ('declined', 'Declined'), ('errored', 'Errored'), ('refunded', 'Refunded'), ('review', 'Review'), ('partially_refunded', 'Partially Refunded')],
field=models.CharField(
choices=[
("pending", "Pending"),
("fulfilled", "Fulfilled"),
("canceled", "Canceled"),
("declined", "Declined"),
("errored", "Errored"),
("refunded", "Refunded"),
("review", "Review"),
("partially_refunded", "Partially Refunded"),
],
default="pending",
max_length=50,
),
Expand Down
Loading

0 comments on commit bc3353b

Please sign in to comment.