From 6294766c244165b4963975b9233b4dfe7e08f2db Mon Sep 17 00:00:00 2001 From: John Eskew Date: Tue, 19 Sep 2017 17:50:05 -0400 Subject: [PATCH] Split emitted signals from the student models file. --- .../student/management/tests/test_transfer_students.py | 3 ++- common/djangoapps/student/models.py | 8 ++------ common/djangoapps/student/signals/__init__.py | 6 ++++++ common/djangoapps/student/signals/signals.py | 3 +++ common/djangoapps/student/tests/test_views.py | 3 ++- common/djangoapps/student/views.py | 4 ++-- lms/djangoapps/badges/handlers.py | 3 ++- lms/djangoapps/commerce/signals.py | 2 +- lms/djangoapps/commerce/tests/test_signals.py | 2 +- lms/djangoapps/grades/signals/handlers.py | 2 +- lms/djangoapps/shoppingcart/models.py | 3 ++- 11 files changed, 24 insertions(+), 15 deletions(-) diff --git a/common/djangoapps/student/management/tests/test_transfer_students.py b/common/djangoapps/student/management/tests/test_transfer_students.py index 62d2527d3b..6431f60095 100644 --- a/common/djangoapps/student/management/tests/test_transfer_students.py +++ b/common/djangoapps/student/management/tests/test_transfer_students.py @@ -10,8 +10,9 @@ import ddt from shoppingcart.models import Order, CertificateItem # pylint: disable=import-error from course_modes.models import CourseMode from student.management.commands import transfer_students -from student.models import CourseEnrollment, UNENROLL_DONE, EVENT_NAME_ENROLLMENT_DEACTIVATED, \ +from student.models import CourseEnrollment, EVENT_NAME_ENROLLMENT_DEACTIVATED, \ EVENT_NAME_ENROLLMENT_ACTIVATED, EVENT_NAME_ENROLLMENT_MODE_CHANGED +from student.signals import UNENROLL_DONE from student.tests.factories import UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory diff --git a/common/djangoapps/student/models.py b/common/djangoapps/student/models.py index 5717f377be..459342a493 100644 --- a/common/djangoapps/student/models.py +++ b/common/djangoapps/student/models.py @@ -31,7 +31,7 @@ from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.db import IntegrityError, models from django.db.models import Count from django.db.models.signals import post_save, pre_save -from django.dispatch import Signal, receiver +from django.dispatch import receiver from django.utils import timezone from django.utils.functional import cached_property from django.utils.translation import ugettext_lazy as _ @@ -48,6 +48,7 @@ from slumber.exceptions import HttpClientError, HttpServerError import dogstats_wrapper as dog_stats_api import lms.lib.comment_client as cc import request_cache +from student.signals import UNENROLL_DONE, ENROLL_STATUS_CHANGE, REFUND_ORDER, ENROLLMENT_TRACK_UPDATED from certificates.models import GeneratedCertificate from course_modes.models import CourseMode from courseware.models import DynamicUpgradeDeadlineConfiguration, CourseDynamicUpgradeDeadlineConfiguration @@ -63,11 +64,6 @@ from util.milestones_helpers import is_entrance_exams_enabled from util.model_utils import emit_field_changed_events, get_changed_fields_dict from util.query import use_read_replica_if_available -from .signals.signals import ENROLLMENT_TRACK_UPDATED - -UNENROLL_DONE = Signal(providing_args=["course_enrollment", "skip_refund"]) -ENROLL_STATUS_CHANGE = Signal(providing_args=["event", "user", "course_id", "mode", "cost", "currency"]) -REFUND_ORDER = Signal(providing_args=["course_enrollment"]) log = logging.getLogger(__name__) AUDIT_LOG = logging.getLogger("audit") SessionStore = import_module(settings.SESSION_ENGINE).SessionStore # pylint: disable=invalid-name diff --git a/common/djangoapps/student/signals/__init__.py b/common/djangoapps/student/signals/__init__.py index e69de29bb2..6a50ccf072 100644 --- a/common/djangoapps/student/signals/__init__.py +++ b/common/djangoapps/student/signals/__init__.py @@ -0,0 +1,6 @@ +from student.signals.signals import ( + ENROLLMENT_TRACK_UPDATED, + UNENROLL_DONE, + ENROLL_STATUS_CHANGE, + REFUND_ORDER +) diff --git a/common/djangoapps/student/signals/signals.py b/common/djangoapps/student/signals/signals.py index 7f280b98b0..d1c080584d 100644 --- a/common/djangoapps/student/signals/signals.py +++ b/common/djangoapps/student/signals/signals.py @@ -4,3 +4,6 @@ Enrollment track related signals. from django.dispatch import Signal ENROLLMENT_TRACK_UPDATED = Signal(providing_args=['user', 'course_key']) +UNENROLL_DONE = Signal(providing_args=["course_enrollment", "skip_refund"]) +ENROLL_STATUS_CHANGE = Signal(providing_args=["event", "user", "course_id", "mode", "cost", "currency"]) +REFUND_ORDER = Signal(providing_args=["course_enrollment"]) diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index 4dc046093a..d44c4d948e 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -20,7 +20,8 @@ from opaque_keys import InvalidKeyError from milestones.tests.utils import MilestonesTestCaseMixin from student.cookies import get_user_info_cookie_data from student.helpers import DISABLE_UNENROLL_CERT_STATES -from student.models import CourseEnrollment, REFUND_ORDER, UserProfile +from student.models import CourseEnrollment, UserProfile +from student.signals import REFUND_ORDER from student.tests.factories import CourseEnrollmentFactory, UserFactory from util.milestones_helpers import set_prerequisite_courses, remove_prerequisite_course, get_course_milestones from xmodule.modulestore import ModuleStoreEnum diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 47223681f2..463e56f557 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -118,9 +118,9 @@ from student.models import ( UserStanding, anonymous_id_for_user, create_comments_service_user, - unique_id_for_user, - REFUND_ORDER + unique_id_for_user ) +from student.signals import REFUND_ORDER from student.tasks import send_activation_email from third_party_auth import pipeline, provider from util.bad_request_rate_limiter import BadRequestRateLimiter diff --git a/lms/djangoapps/badges/handlers.py b/lms/djangoapps/badges/handlers.py index 79887d5330..d53a50b762 100644 --- a/lms/djangoapps/badges/handlers.py +++ b/lms/djangoapps/badges/handlers.py @@ -5,7 +5,8 @@ from django.dispatch import receiver from lms.djangoapps.badges.events.course_meta import award_enrollment_badge from lms.djangoapps.badges.utils import badges_enabled -from student.models import ENROLL_STATUS_CHANGE, EnrollStatusChange +from student.models import EnrollStatusChange +from student.signals import ENROLL_STATUS_CHANGE @receiver(ENROLL_STATUS_CHANGE) diff --git a/lms/djangoapps/commerce/signals.py b/lms/djangoapps/commerce/signals.py index a9c8feb62e..58e7ffe712 100644 --- a/lms/djangoapps/commerce/signals.py +++ b/lms/djangoapps/commerce/signals.py @@ -19,7 +19,7 @@ from openedx.core.djangoapps.commerce.utils import ecommerce_api_client, is_comm from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.theming import helpers as theming_helpers from request_cache.middleware import RequestCache -from student.models import REFUND_ORDER +from student.signals import REFUND_ORDER log = logging.getLogger(__name__) diff --git a/lms/djangoapps/commerce/tests/test_signals.py b/lms/djangoapps/commerce/tests/test_signals.py index 2954f22d2b..f74f1f2500 100644 --- a/lms/djangoapps/commerce/tests/test_signals.py +++ b/lms/djangoapps/commerce/tests/test_signals.py @@ -23,7 +23,7 @@ from commerce.signals import create_zendesk_ticket, generate_refund_notification from commerce.tests import JSON from commerce.tests.mocks import mock_create_refund, mock_process_refund from course_modes.models import CourseMode -from student.models import REFUND_ORDER +from student.signals import REFUND_ORDER from student.tests.factories import CourseEnrollmentFactory, UserFactory ZENDESK_URL = 'http://zendesk.example.com/' diff --git a/lms/djangoapps/grades/signals/handlers.py b/lms/djangoapps/grades/signals/handlers.py index a5420049ec..3651bb6519 100644 --- a/lms/djangoapps/grades/signals/handlers.py +++ b/lms/djangoapps/grades/signals/handlers.py @@ -9,7 +9,7 @@ from django.dispatch import receiver from openedx.core.djangoapps.course_groups.signals.signals import COHORT_MEMBERSHIP_UPDATED from openedx.core.lib.grade_utils import is_score_higher_or_equal from student.models import user_by_anonymous_id -from student.signals.signals import ENROLLMENT_TRACK_UPDATED +from student.signals import ENROLLMENT_TRACK_UPDATED from submissions.models import score_reset, score_set from track.event_transaction_utils import get_event_transaction_id, get_event_transaction_type from util.date_utils import to_timestamp diff --git a/lms/djangoapps/shoppingcart/models.py b/lms/djangoapps/shoppingcart/models.py index 144df4bbed..82906b772a 100644 --- a/lms/djangoapps/shoppingcart/models.py +++ b/lms/djangoapps/shoppingcart/models.py @@ -37,7 +37,8 @@ from eventtracking import tracker from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.xmodule_django.models import CourseKeyField from shoppingcart.pdf import PDFInvoice -from student.models import UNENROLL_DONE, CourseEnrollment, EnrollStatusChange +from student.models import CourseEnrollment, EnrollStatusChange +from student.signals import UNENROLL_DONE from util.query import use_read_replica_if_available from xmodule.modulestore.django import modulestore