Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3c250e56
Commit
3c250e56
authored
Oct 12, 2017
by
Tyler Hallada
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address Gabe's comments
parent
5bfb322f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
20 deletions
+40
-20
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
+1
-1
openedx/core/djangoapps/schedules/tasks.py
+39
-19
No files found.
openedx/core/djangoapps/schedules/management/commands/tests/test_send_recurring_nudge.py
View file @
3c250e56
...
@@ -150,7 +150,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
...
@@ -150,7 +150,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
enrollment__user
=
user1
,
enrollment__user
=
user1
,
)
)
schedule
.
enrollment
.
course
=
CourseOverviewFactory
()
schedule
.
enrollment
.
course
=
CourseOverviewFactory
()
schedule
.
enrollment
.
course
.
end
=
datetime
.
datetime
.
now
()
-
datetime
.
timedelta
(
days
=
1
)
schedule
.
enrollment
.
course
.
end
=
datetime
.
datetime
.
now
(
pytz
.
UTC
)
-
datetime
.
timedelta
(
days
=
1
)
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_time
=
datetime
.
datetime
(
2017
,
8
,
3
,
20
,
tzinfo
=
pytz
.
UTC
)
test_time_str
=
serialize
(
test_time
)
test_time_str
=
serialize
(
test_time
)
...
...
openedx/core/djangoapps/schedules/tasks.py
View file @
3c250e56
...
@@ -90,12 +90,15 @@ def _recurring_nudge_schedule_send(site_id, msg_str):
...
@@ -90,12 +90,15 @@ def _recurring_nudge_schedule_send(site_id, msg_str):
def
recurring_nudge_schedule_bin
(
def
recurring_nudge_schedule_bin
(
site_id
,
target_day_str
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
,
override_recipient_email
=
None
,
site_id
,
target_day_str
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
,
override_recipient_email
=
None
,
):
):
target_day
=
deserialize
(
target_day_str
)
target_date
=
deserialize
(
target_day_str
)
# TODO: in the next refactor of this task, pass in current_date instead of reproducing it here
current_date
=
target_date
-
datetime
.
timedelta
(
days
=
day_offset
)
msg_type
=
RecurringNudge
(
abs
(
day_offset
))
msg_type
=
RecurringNudge
(
abs
(
day_offset
))
for
(
user
,
language
,
context
)
in
_recurring_nudge_schedules_for_bin
(
for
(
user
,
language
,
context
)
in
_recurring_nudge_schedules_for_bin
(
Site
.
objects
.
get
(
id
=
site_id
),
Site
.
objects
.
get
(
id
=
site_id
),
target_day
,
current_date
,
target_date
,
bin_num
,
bin_num
,
org_list
,
org_list
,
exclude_orgs
exclude_orgs
...
@@ -111,11 +114,11 @@ def recurring_nudge_schedule_bin(
...
@@ -111,11 +114,11 @@ def recurring_nudge_schedule_bin(
_recurring_nudge_schedule_send
.
apply_async
((
site_id
,
str
(
msg
)),
retry
=
False
)
_recurring_nudge_schedule_send
.
apply_async
((
site_id
,
str
(
msg
)),
retry
=
False
)
def
_recurring_nudge_schedules_for_bin
(
site
,
target_day
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
def
_recurring_nudge_schedules_for_bin
(
site
,
current_date
,
target_date
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
beginning_of_day
=
target_day
.
replace
(
hour
=
0
,
minute
=
0
,
second
=
0
,
microsecond
=
0
)
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'start'
,
schedule_date_field
=
'start'
,
target_date
=
beginning_of_day
,
current_date
=
current_date
,
target_date
=
target_date
,
bin_num
=
bin_num
,
bin_num
=
bin_num
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
org_list
=
org_list
,
org_list
=
org_list
,
...
@@ -154,12 +157,15 @@ class UpgradeReminder(ScheduleMessageType):
...
@@ -154,12 +157,15 @@ class UpgradeReminder(ScheduleMessageType):
def
upgrade_reminder_schedule_bin
(
def
upgrade_reminder_schedule_bin
(
site_id
,
target_day_str
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
,
override_recipient_email
=
None
,
site_id
,
target_day_str
,
day_offset
,
bin_num
,
org_list
,
exclude_orgs
=
False
,
override_recipient_email
=
None
,
):
):
target_day
=
deserialize
(
target_day_str
)
target_date
=
deserialize
(
target_day_str
)
# TODO: in the next refactor of this task, pass in current_date instead of reproducing it here
current_date
=
target_date
-
datetime
.
timedelta
(
days
=
day_offset
)
msg_type
=
UpgradeReminder
()
msg_type
=
UpgradeReminder
()
for
(
user
,
language
,
context
)
in
_upgrade_reminder_schedules_for_bin
(
for
(
user
,
language
,
context
)
in
_upgrade_reminder_schedules_for_bin
(
Site
.
objects
.
get
(
id
=
site_id
),
Site
.
objects
.
get
(
id
=
site_id
),
target_day
,
current_date
,
target_date
,
bin_num
,
bin_num
,
org_list
,
org_list
,
exclude_orgs
exclude_orgs
...
@@ -185,12 +191,11 @@ def _upgrade_reminder_schedule_send(site_id, msg_str):
...
@@ -185,12 +191,11 @@ def _upgrade_reminder_schedule_send(site_id, msg_str):
ace
.
send
(
msg
)
ace
.
send
(
msg
)
def
_upgrade_reminder_schedules_for_bin
(
site
,
target_day
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
def
_upgrade_reminder_schedules_for_bin
(
site
,
current_date
,
target_date
,
bin_num
,
org_list
,
exclude_orgs
=
False
):
beginning_of_day
=
target_day
.
replace
(
hour
=
0
,
minute
=
0
,
second
=
0
,
microsecond
=
0
)
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'upgrade_deadline'
,
schedule_date_field
=
'upgrade_deadline'
,
target_date
=
beginning_of_day
,
current_date
=
current_date
,
target_date
=
target_date
,
bin_num
=
bin_num
,
bin_num
=
bin_num
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
org_list
=
org_list
,
org_list
=
org_list
,
...
@@ -227,6 +232,7 @@ def _upgrade_reminder_schedules_for_bin(site, target_day, bin_num, org_list, exc
...
@@ -227,6 +232,7 @@ def _upgrade_reminder_schedules_for_bin(site, target_day, bin_num, org_list, exc
yield
(
user
,
first_schedule
.
enrollment
.
course
.
language
,
template_context
)
yield
(
user
,
first_schedule
.
enrollment
.
course
.
language
,
template_context
)
<<<<<<<
HEAD
class
CourseUpdate
(
ScheduleMessageType
):
class
CourseUpdate
(
ScheduleMessageType
):
pass
pass
...
@@ -319,23 +325,30 @@ def get_course_week_summary(course_id, week_num):
...
@@ -319,23 +325,30 @@ def get_course_week_summary(course_id, week_num):
def
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
,
target_date
,
bin_num
,
num_bins
=
DEFAULT_NUM_BINS
,
def
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
,
target_date
,
bin_num
,
num_bins
=
DEFAULT_NUM_BINS
,
org_list
=
None
,
exclude_orgs
=
False
,
order_by
=
'enrollment__user__id'
):
org_list
=
None
,
exclude_orgs
=
False
,
order_by
=
'enrollment__user__id'
):
|||||||
parent
of
c6f507c4b7
...
Address
Gabe
's comments
def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, target_date, bin_num, num_bins=DEFAULT_NUM_BINS,
org_list=None, exclude_orgs=False):
=======
def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, current_date, target_date, bin_num,
num_bins=DEFAULT_NUM_BINS, org_list=None, exclude_orgs=False):
>>>>>>> c6f507c4b7... Address Gabe'
s
comments
"""
"""
Returns Schedules with the target_date, related to Users whose id matches the bin_num, and filtered by org_list.
Returns Schedules with the target_date, related to Users whose id matches the bin_num, and filtered by org_list.
Arguments:
Arguments:
schedule_date_field -- string field name to query on the User's Schedule model
schedule_date_field -- string field name to query on the User's Schedule model
target_date -- datetime day (with zeroed-out time) that the User's Schedule's schedule_date_field value should fall
current_date -- datetime that will be used as "right now" in the query
under
target_date -- datetime that the User's Schedule's schedule_date_field value should fall
under
bin_num -- int for selecting the bin of Users whose id
%
num_bins == bin_num
bin_num -- int for selecting the bin of Users whose id
%
num_bins == bin_num
num_bin -- int specifying the number of bins to separate the Users into (default: DEFAULT_NUM_BINS)
num_bin -- int specifying the number of bins to separate the Users into (default: DEFAULT_NUM_BINS)
org_list -- list of course_org names (strings) that the returned Schedules must or must not be in (default: None)
org_list -- list of course_org names (strings) that the returned Schedules must or must not be in (default: None)
exclude_orgs -- boolean indicating whether the returned Schedules should exclude (True) the course_orgs in org_list
exclude_orgs -- boolean indicating whether the returned Schedules should exclude (True) the course_orgs in org_list
or strictly include (False) them (default: False)
or strictly include (False) them (default: False)
"""
"""
t
oday
=
datetime
.
datetime
.
now
()
.
replace
(
hour
=
0
,
minute
=
0
,
second
=
0
,
microsecond
=
0
)
t
arget_day
=
_get_datetime_beginning_of_day
(
target_date
)
schedule_date_equals_target_date_filter
=
{
schedule_date_equals_target_date_filter
=
{
'courseenrollment__schedule__{}__gte'
.
format
(
schedule_date_field
):
target_da
te
,
'courseenrollment__schedule__{}__gte'
.
format
(
schedule_date_field
):
target_da
y
,
'courseenrollment__schedule__{}__lt'
.
format
(
schedule_date_field
):
target_da
te
+
datetime
.
timedelta
(
days
=
1
),
'courseenrollment__schedule__{}__lt'
.
format
(
schedule_date_field
):
target_da
y
+
datetime
.
timedelta
(
days
=
1
),
}
}
users
=
User
.
objects
.
filter
(
users
=
User
.
objects
.
filter
(
courseenrollment__is_active
=
True
,
courseenrollment__is_active
=
True
,
...
@@ -347,8 +360,8 @@ def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, target_d
...
@@ -347,8 +360,8 @@ def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, target_d
)
)
schedule_date_equals_target_date_filter
=
{
schedule_date_equals_target_date_filter
=
{
'{}__gte'
.
format
(
schedule_date_field
):
target_da
te
,
'{}__gte'
.
format
(
schedule_date_field
):
target_da
y
,
'{}__lt'
.
format
(
schedule_date_field
):
target_da
te
+
datetime
.
timedelta
(
days
=
1
),
'{}__lt'
.
format
(
schedule_date_field
):
target_da
y
+
datetime
.
timedelta
(
days
=
1
),
}
}
schedules
=
Schedule
.
objects
.
select_related
(
schedules
=
Schedule
.
objects
.
select_related
(
'enrollment__user__profile'
,
'enrollment__user__profile'
,
...
@@ -356,7 +369,7 @@ def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, target_d
...
@@ -356,7 +369,7 @@ def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, target_d
)
.
prefetch_related
(
)
.
prefetch_related
(
'enrollment__course__modes'
'enrollment__course__modes'
)
.
filter
(
)
.
filter
(
Q
(
enrollment__course__end__isnull
=
True
)
|
Q
(
enrollment__course__end__gte
=
today
),
Q
(
enrollment__course__end__isnull
=
True
)
|
Q
(
enrollment__course__end__gte
=
current_date
),
enrollment__user__in
=
users
,
enrollment__user__in
=
users
,
enrollment__is_active
=
True
,
enrollment__is_active
=
True
,
**
schedule_date_equals_target_date_filter
**
schedule_date_equals_target_date_filter
...
@@ -401,3 +414,10 @@ def _get_link_to_purchase_verified_certificate(a_user, a_schedule):
...
@@ -401,3 +414,10 @@ def _get_link_to_purchase_verified_certificate(a_user, a_schedule):
return
None
return
None
return
verified_upgrade_deadline_link
(
a_user
,
enrollment
.
course
)
return
verified_upgrade_deadline_link
(
a_user
,
enrollment
.
course
)
def
_get_datetime_beginning_of_day
(
dt
):
"""
Truncates hours, minutes, seconds, and microseconds to zero on given datetime.
"""
return
dt
.
replace
(
hour
=
0
,
minute
=
0
,
second
=
0
,
microsecond
=
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment