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
c866b526
Unverified
Commit
c866b526
authored
Nov 02, 2017
by
Troy Sankey
Committed by
GitHub
Nov 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #16426 from edx/pwnage101/mailing_mgmt_cleanup
Mailing management command cleanup for Django 1.11
parents
a711fb81
e0697905
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
72 deletions
+51
-72
lms/djangoapps/mailing/management/commands/mailchimp_id.py
+17
-22
lms/djangoapps/mailing/management/commands/mailchimp_sync_announcements.py
+11
-19
lms/djangoapps/mailing/management/commands/mailchimp_sync_course.py
+23
-31
No files found.
lms/djangoapps/mailing/management/commands/mailchimp_id.py
View file @
c866b526
...
...
@@ -2,10 +2,11 @@
mailchimp_id: Returns whether or not a given mailchimp key represents
a valid list.
"""
from
__future__
import
print_function
import
sys
from
optparse
import
make_option
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
mailsnake
import
MailSnake
...
...
@@ -14,30 +15,24 @@ class Command(BaseCommand):
Given a mailchimp key, validates that a list with that key
exists in mailchimp.
"""
args
=
'<mailchimp_key web_id>'
help
=
'Get the list id from a web_id'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--key'
,
action
=
'store'
,
help
=
'mailchimp api key'
),
make_option
(
'--webid'
,
action
=
'store'
,
dest
=
'web_id'
,
type
=
int
,
help
=
'mailchimp list web id'
),
)
def
parse_options
(
self
,
options
):
"""Parses `options` of the command."""
if
not
options
[
'key'
]:
raise
CommandError
(
'missing key'
)
if
not
options
[
'web_id'
]:
raise
CommandError
(
'missing list web id'
)
return
options
[
'key'
],
options
[
'web_id'
]
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--key'
,
required
=
True
,
help
=
'mailchimp api key'
)
parser
.
add_argument
(
'--webid'
,
dest
=
'web_id'
,
type
=
int
,
required
=
True
,
help
=
'mailchimp list web id'
)
def
handle
(
self
,
*
args
,
**
options
):
"""
Validates that the id passed in exists in mailchimp.
"""
key
,
web_id
=
self
.
parse_options
(
options
)
key
=
options
[
'key'
]
web_id
=
options
[
'web_id'
]
mailchimp
=
MailSnake
(
key
)
...
...
@@ -47,8 +42,8 @@ class Command(BaseCommand):
list_with_id
=
by_web_id
.
get
(
web_id
,
None
)
if
list_with_id
:
print
"id: {} for web_id: {}"
.
format
(
list_with_id
[
'id'
],
web_id
)
print
"list name: {}"
.
format
(
list_with_id
[
'name'
]
)
print
(
"id: {} for web_id: {}"
.
format
(
list_with_id
[
'id'
],
web_id
)
)
print
(
"list name: {}"
.
format
(
list_with_id
[
'name'
])
)
else
:
print
"list with web_id: {} not found."
.
format
(
web_id
)
print
(
"list with web_id: {} not found."
.
format
(
web_id
)
)
sys
.
exit
(
1
)
lms/djangoapps/mailing/management/commands/mailchimp_sync_announcements.py
View file @
c866b526
...
...
@@ -2,10 +2,9 @@
Synchronizes the announcement list with all active students.
"""
import
logging
from
optparse
import
make_option
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
.mailchimp_sync_course
import
connect_mailchimp
,
get_cleaned
,
get_subscribed
,
get_unsubscribed
,
subscribe_with_data
...
...
@@ -16,27 +15,20 @@ class Command(BaseCommand):
"""
Synchronizes the announcement list with all active students.
"""
args
=
'<mailchimp_key mailchimp_list course_id>'
help
=
'Synchronizes the announcement list with all active students.'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--key'
,
action
=
'store'
,
help
=
'mailchimp api key'
),
make_option
(
'--list'
,
action
=
'store'
,
dest
=
'list_id'
,
help
=
'mailchimp list id'
),
)
def
parse_options
(
self
,
options
):
"""Parses `options` of the command."""
if
not
options
[
'key'
]:
raise
CommandError
(
'missing key'
)
if
not
options
[
'list_id'
]:
raise
CommandError
(
'missing list id'
)
return
(
options
[
'key'
],
options
[
'list_id'
])
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--key'
,
required
=
True
,
help
=
'mailchimp api key'
)
parser
.
add_argument
(
'--list'
,
dest
=
'list_id'
,
required
=
True
,
help
=
'mailchimp list id'
)
def
handle
(
self
,
*
args
,
**
options
):
key
,
list_id
=
self
.
parse_options
(
options
)
key
=
options
[
'key'
]
list_id
=
options
[
'list_id'
]
log
.
info
(
'Syncronizing announcement mailing list'
)
...
...
lms/djangoapps/mailing/management/commands/mailchimp_sync_course.py
View file @
c866b526
...
...
@@ -7,12 +7,10 @@ import math
import
random
from
collections
import
namedtuple
from
itertools
import
chain
from
optparse
import
make_option
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
from
mailsnake
import
MailSnake
from
opaque_keys.edx.keys
import
CourseKey
from
student.models
import
UserProfile
,
unique_id_for_user
BATCH_SIZE
=
15000
...
...
@@ -29,38 +27,32 @@ class Command(BaseCommand):
"""
Synchronizes a mailchimp list with the students of a course.
"""
args
=
'<mailchimp_key mailchimp_list course_id>'
help
=
'Synchronizes a mailchimp list with the students of a course.'
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'--key'
,
action
=
'store'
,
help
=
'mailchimp api key'
),
make_option
(
'--list'
,
action
=
'store'
,
dest
=
'list_id'
,
help
=
'mailchimp list id'
),
make_option
(
'--course'
,
action
=
'store'
,
dest
=
'course_id'
,
help
=
'xmodule course_id'
),
make_option
(
'--segments'
,
action
=
'store'
,
dest
=
'segments'
,
default
=
0
,
type
=
int
,
help
=
'number of static random segments to create'
),
)
def
parse_options
(
self
,
options
):
"""Parses `options` of the command."""
if
not
options
[
'key'
]:
raise
CommandError
(
'missing key'
)
if
not
options
[
'list_id'
]:
raise
CommandError
(
'missing list id'
)
if
not
options
[
'course_id'
]:
raise
CommandError
(
'missing course id'
)
return
(
options
[
'key'
],
options
[
'list_id'
],
options
[
'course_id'
],
options
[
'segments'
])
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--key'
,
required
=
True
,
help
=
'mailchimp api key'
)
parser
.
add_argument
(
'--list'
,
dest
=
'list_id'
,
required
=
True
,
help
=
'mailchimp list id'
)
parser
.
add_argument
(
'--course'
,
dest
=
'course_id'
,
required
=
True
,
help
=
'edx course_id'
)
parser
.
add_argument
(
'--segments'
,
dest
=
'num_segments'
,
type
=
int
,
default
=
0
,
help
=
'number of static random segments to create'
)
def
handle
(
self
,
*
args
,
**
options
):
"""Synchronizes a mailchimp list with the students of a course."""
key
,
list_id
,
course_id
,
nsegments
=
self
.
parse_options
(
options
)
key
=
options
[
'key'
]
list_id
=
options
[
'list_id'
]
course_id
=
options
[
'course_id'
]
num_segments
=
options
[
'num_segments'
]
log
.
info
(
'Syncronizing email list for
%
s'
,
course_id
)
...
...
@@ -87,7 +79,7 @@ class Command(BaseCommand):
unsubscribe
(
mailchimp
,
list_id
,
non_enrolled_emails
)
subscribed
=
subscribed
.
union
(
set
(
d
[
'EMAIL'
]
for
d
in
to_subscribe
))
make_segments
(
mailchimp
,
list_id
,
nsegments
,
subscribed
)
make_segments
(
mailchimp
,
list_id
,
n
um_
segments
,
subscribed
)
def
connect_mailchimp
(
api_key
):
...
...
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