本文整理汇总了Python中django.db.models.signals.post_save方法的典型用法代码示例。如果您正苦于以下问题:Python signals.post_save方法的具体用法?Python signals.post_save怎么用?Python signals.post_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.signals
的用法示例。
在下文中一共展示了signals.post_save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ready
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def ready(self):
# Models that should be watched and cause creation and deletion of the
# related visibility object. The 2nd element of the tuple specifies the
# field; the 3rd the specific visibility model.
assets = [
('Profile', 'email', 'PublicEmail'),
('Phone', '', 'Phone'),
('Place', '', 'Place'),
('Place', 'family_members', 'FamilyMembers'),
]
for model, field, asset_type in assets:
make_visibility_receivers(
'hosting.' + model,
field + ('_' if field else '') + 'visibility',
self.get_model('VisibilitySettingsFor' + asset_type)
)
signals.post_save.connect(profile_post_save, sender='hosting.Profile')
示例2: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
with mute_signals(post_save):
cls.learner1 = UserFactory.create()
cls.learner1_username = 'learner1_username'
cls.learner1.social_auth.create(
provider=EdxOrgOAuth2.name,
uid=cls.learner1_username
)
cls.learner2 = UserFactory.create()
cls.learner2_username = 'learner2_username'
cls.learner2.social_auth.create(
provider=EdxOrgOAuth2.name,
uid=cls.learner2_username
)
cls.program = ProgramFactory.create()
cls.staff = UserFactory.create()
cls.staff_username = 'staff_username'
for learner in (cls.learner1, cls.learner2):
ProgramEnrollment.objects.create(
program=cls.program,
user=learner,
)
示例3: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
with mute_signals(post_save):
cls.profile = profile = ProfileFactory.create()
cls.user = profile.user
# Create non-FA program data
cls.non_fa_program = ProgramFactory.create()
_, course_runs = cls.generate_course_with_runs(
cls.non_fa_program,
course_params=dict(title='Non FA Course 1')
)
cls.non_fa_enrollments = [cls.verified_enroll(cls.user, course_runs[0])]
cls.non_fa_program_enrollment = ProgramEnrollment.objects.create(user=cls.user, program=cls.non_fa_program)
# Create FA program data
cls.fa_program = ProgramFactory.create(financial_aid_availability=False)
_, course_runs = cls.generate_course_with_runs(
cls.fa_program,
course_params=dict(title='FA Course 1')
)
cls.fa_enrollments = [cls.verified_enroll(cls.user, course_runs[0])]
cls.fa_program_enrollment = ProgramEnrollment.objects.create(user=cls.user, program=cls.fa_program)
示例4: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
with mute_signals(post_save):
profile = ProfileFactory.create()
cls.program, _ = create_program(past=True)
cls.user = profile.user
cls.course_run = cls.program.course_set.first().courserun_set.first()
with mute_signals(post_save):
CachedEnrollmentFactory.create(user=cls.user, course_run=cls.course_run)
cls.exam_run = ExamRunFactory.create(course=cls.course_run.course)
with mute_signals(post_save):
cls.final_grade = FinalGradeFactory.create(
user=cls.user,
course_run=cls.course_run,
passed=True,
course_run_paid_on_edx=False,
)
示例5: test_write_cdd_file_with_blank_romanized_name
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def test_write_cdd_file_with_blank_romanized_name(self):
"""
Tests cdd_writer against a profile without romanized name fields
"""
kwargs = {
'profile__id': 9876,
'profile__first_name': 'Jane',
'profile__last_name': 'Smith',
'profile__romanized_first_name': None,
'profile__romanized_last_name': None,
'profile__phone_number': '+1 617 293-3423',
}
with mute_signals(post_save):
exam_profiles = [ExamProfileFactory.create(**kwargs)]
exam_profiles[0].profile.updated_on = FIXED_DATETIME
self.cdd_writer.write(self.tsv_file, exam_profiles)
assert self.tsv_rows[0].startswith("9876\tJane\tSmith\t")
示例6: test_write_ead_file
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def test_write_ead_file(self):
"""
Tests that write_ead_file outputs correctly
"""
kwargs = {
'id': 143,
'operation': 'add',
'exam_run__exam_series_code': 'MM-DEDP',
'exam_run__date_first_eligible': date(2016, 5, 15),
'exam_run__date_last_eligible': date(2016, 10, 15),
}
with mute_signals(post_save):
profile = ProfileFactory(id=14879)
exam_auths = [ExamAuthorizationFactory.create(user=profile.user, **kwargs)]
exam_auths[0].updated_on = FIXED_DATETIME
self.ead_writer.write(self.tsv_file, exam_auths)
assert self.tsv_rows[0] == (
"add\t143\t"
"14879\tMM-DEDP\t\t"
"\t2016/05/15\t2016/10/15\t" # accommodation blank intentionally
"2016/05/15 15:02:55"
)
示例7: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
with mute_signals(post_save):
cls.profile = ProfileFactory.create()
cls.program, _ = create_program(past=True)
cls.course_run = cls.program.course_set.first().courserun_set.first()
CachedCurrentGradeFactory.create(
user=cls.profile.user,
course_run=cls.course_run,
data={
"passed": True,
"percent": 0.9,
"course_key": cls.course_run.edx_course_key,
"username": cls.profile.user.username
}
)
CachedCertificateFactory.create(user=cls.profile.user, course_run=cls.course_run)
cls.exam_run = ExamRunFactory.create(
course=cls.course_run.course,
date_first_schedulable=now_in_utc() - timedelta(days=1),
)
示例8: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
super().setUpTestData()
cls.program_enrollment_unsent = ProgramEnrollmentFactory.create()
cls.program_enrollment_sent = ProgramEnrollmentFactory.create()
cls.automatic_email = AutomaticEmailFactory.create(enabled=True)
cls.percolate_query = cls.automatic_email.query
cls.other_query = PercolateQueryFactory.create(source_type=PercolateQuery.DISCUSSION_CHANNEL_TYPE)
cls.percolate_queries = [cls.percolate_query, cls.other_query]
cls.automatic_email_disabled = AutomaticEmailFactory.create(enabled=False)
cls.percolate_query_disabled = cls.automatic_email_disabled.query
SentAutomaticEmail.objects.create(
automatic_email=cls.automatic_email,
user=cls.program_enrollment_sent.user,
status=SentAutomaticEmail.SENT,
)
# User was sent email connected to a different AutomaticEmail
SentAutomaticEmail.objects.create(
user=cls.program_enrollment_unsent.user,
automatic_email=AutomaticEmailFactory.create(enabled=True),
status=SentAutomaticEmail.SENT,
)
with mute_signals(post_save):
cls.staff_user = UserFactory.create()
示例9: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
super().setUpTestData()
with mute_signals(post_save):
staff_profile = ProfileFactory.create()
cls.staff_user = staff_profile.user
cls.course = CourseFactory.create(
contact_email='a@example.com',
program__financial_aid_availability=False
)
course_run = CourseRunFactory.create(course=cls.course)
ProgramEnrollmentFactory.create(user=cls.staff_user, program=cls.course.program)
CachedEnrollmentFactory.create(user=cls.staff_user, course_run=course_run)
cls.url_name = 'course_team_mail_api'
cls.request_data = {
'email_subject': 'email subject',
'email_body': 'email body'
}
示例10: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
with mute_signals(post_save):
profile = ProfileFactory.create()
cls.user = profile.user
cls.program = ProgramFactory.create()
Role.objects.create(
user=cls.user,
program=cls.program,
role=Staff.ROLE_ID
)
with mute_signals(post_save):
profile = ProfileFactory.create(email_optin=True, filled_out=True)
profile2 = ProfileFactory.create(email_optin=False, filled_out=True)
cls.learner = profile.user
cls.learner2 = profile2.user
# self.user with role staff on program
for user in [cls.learner, cls.learner2, cls.user]:
ProgramEnrollmentFactory(
user=user,
program=cls.program,
)
示例11: test_update_percolate_memberships
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def test_update_percolate_memberships(self, source_type, is_member, query_matches, mock_on_commit):
"""
Tests that existing memberships are updated where appropriate
"""
with mute_signals(post_save):
query = PercolateQueryFactory.create(source_type=source_type)
profile = ProfileFactory.create(filled_out=True)
program_enrollment = ProgramEnrollmentFactory.create(user=profile.user)
membership = PercolateQueryMembershipFactory.create(
user=profile.user,
query=query,
is_member=is_member,
needs_update=False
)
with patch(
'search.api._search_percolate_queries',
return_value=[query.id] if query_matches else []
) as search_percolate_queries_mock:
update_percolate_memberships(profile.user, source_type)
search_percolate_queries_mock.assert_called_once_with(program_enrollment)
membership.refresh_from_db()
assert membership.needs_update is (is_member is not query_matches)
示例12: test_populate_query_memberships
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def test_populate_query_memberships(self, source_type, is_member, query_matches, mock_on_commit):
"""
Tests that existing memberships are updated where appropriate
"""
with mute_signals(post_save):
query = PercolateQueryFactory.create(source_type=source_type)
profiles = [ProfileFactory.create(filled_out=True) for _ in range(3)]
program_enrollments = [ProgramEnrollmentFactory.create(user=profile.user) for profile in profiles]
with patch(
'search.api._search_percolate_queries',
return_value=[query.id] if query_matches else []
) as search_percolate_queries_mock:
populate_query_memberships(query.id)
assert search_percolate_queries_mock.call_count == len(program_enrollments)
for program_enrollment in program_enrollments:
search_percolate_queries_mock.assert_any_call(program_enrollment)
for profile in profiles:
membership = PercolateQueryMembership.objects.get(user=profile.user, query=query)
assert membership.is_member is query_matches
assert membership.needs_update is True
示例13: test_populate_query_inactive_memberships
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def test_populate_query_inactive_memberships(self, is_active, has_profile, mock_on_commit):
"""
Tests that memberships are handled correctly for users who are inactive or have no profiles
"""
with mute_signals(post_save):
query = PercolateQueryFactory.create(source_type=PercolateQuery.DISCUSSION_CHANNEL_TYPE)
user = UserFactory.create(is_active=is_active)
if has_profile:
ProfileFactory.create(user=user, filled_out=True)
ProgramEnrollmentFactory.create(user=user)
with patch('search.api.get_conn') as es_mock:
populate_query_memberships(query.id)
assert es_mock.return_value.search.call_count == (1 if has_profile and is_active else 0)
assert PercolateQueryMembership.objects.filter(user=user, query=query).count() == (
1 if is_active else 0
)
示例14: test_index_program_enrolled_users_missing_profiles
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def test_index_program_enrolled_users_missing_profiles(self, mock_on_commit):
"""
Test that index_program_enrolled_users doesn't index users missing profiles
"""
with mute_signals(post_save):
program_enrollments = [ProgramEnrollmentFactory.build() for _ in range(10)]
with patch(
'search.indexing_api._index_chunk', autospec=True, return_value=0
) as index_chunk, patch(
'search.indexing_api.serialize_program_enrolled_user',
autospec=True,
side_effect=lambda x: None # simulate a missing profile
) as serialize_mock, patch(
'search.indexing_api.serialize_public_enrolled_user', autospec=True, side_effect=lambda x: x
) as serialize_public_mock:
index_program_enrolled_users(program_enrollments)
assert index_chunk.call_count == 0
assert serialize_public_mock.call_count == 0
assert serialize_mock.call_count == len(program_enrollments)
示例15: setUpTestData
# 需要导入模块: from django.db.models import signals [as 别名]
# 或者: from django.db.models.signals import post_save [as 别名]
def setUpTestData(cls):
"""
Create a user
"""
with mute_signals(post_save):
cls.user1 = UserFactory.create()
username = "{}_edx".format(cls.user1.username)
cls.user1.social_auth.create(
provider=EdxOrgOAuth2.name,
uid=username
)
cls.url1 = reverse('profile-detail', kwargs={'user': username})
with mute_signals(post_save):
cls.user2 = UserFactory.create(username="test.dev.example")
username = "{}_edx".format(cls.user2.username)
cls.user2.social_auth.create(
provider=EdxOrgOAuth2.name,
uid=username
)
cls.url2 = reverse('profile-detail', kwargs={'user': username})