Commit 934207bf by Feanil Patel Committed by Sarina Canelake

Fixes to get it working with master.

parent 5c0adf04
...@@ -13,6 +13,7 @@ from django.core.management.base import BaseCommand, CommandError ...@@ -13,6 +13,7 @@ from django.core.management.base import BaseCommand, CommandError
from mailsnake import MailSnake from mailsnake import MailSnake
from student.models import UserProfile, unique_id_for_user from student.models import UserProfile, unique_id_for_user
from opaque_keys.edx.keys import CourseKey
BATCH_SIZE = 15000 BATCH_SIZE = 15000
...@@ -122,7 +123,7 @@ def verify_list(mailchimp, list_id, course_id): ...@@ -122,7 +123,7 @@ def verify_list(mailchimp, list_id, course_id):
def get_student_data(students, exclude=None): def get_student_data(students, exclude=None):
# To speed the query, we won't retrieve the full User object, only # To speed the query, we won't retrieve the full User object, only
# two of its values. The namedtuple simulates the User object. # two of its values. The namedtuple simulates the User object.
FakeUser = namedtuple('Fake', 'id username') FakeUser = namedtuple('Fake', 'id username is_anonymous')
exclude = exclude if exclude else set() exclude = exclude if exclude else set()
...@@ -130,8 +131,9 @@ def get_student_data(students, exclude=None): ...@@ -130,8 +131,9 @@ def get_student_data(students, exclude=None):
e = {'EMAIL': v['user__email'], e = {'EMAIL': v['user__email'],
'FULLNAME': v['name'].title()} 'FULLNAME': v['name'].title()}
e['EDX_ID'] = unique_id_for_user(FakeUser(v['user_id'], fake_user = FakeUser(v['user_id'], v['user__username'], lambda:True)
v['user__username'])) e['EDX_ID'] = unique_id_for_user(fake_user)
return e return e
fields = 'user__email', 'name', 'user_id', 'user__username' fields = 'user__email', 'name', 'user_id', 'user__username'
...@@ -143,7 +145,8 @@ def get_student_data(students, exclude=None): ...@@ -143,7 +145,8 @@ def get_student_data(students, exclude=None):
def get_enrolled_students(course_id): def get_enrolled_students(course_id):
objects = UserProfile.objects objects = UserProfile.objects
students = objects.filter(user__courseenrollment__course_id=course_id, course_key = CourseKey.from_string(course_id)
students = objects.filter(user__courseenrollment__course_id=course_key,
user__courseenrollment__is_active=True) user__courseenrollment__is_active=True)
return students return students
...@@ -232,7 +235,7 @@ def subscribe_with_data(mailchimp, list_id, user_data): ...@@ -232,7 +235,7 @@ def subscribe_with_data(mailchimp, list_id, user_data):
double_optin=False, double_optin=False,
update_existing=True) update_existing=True)
log.debug("Added: {} Error on: {}".format( log.debug("Added: {} Error on: {}".format(
result['add_count'], resurt['error_count'])) result['add_count'], result['error_count']))
def make_segments(mailchimp, list_id, count, emails): def make_segments(mailchimp, list_id, count, emails):
......
...@@ -1722,6 +1722,9 @@ INSTALLED_APPS = ( ...@@ -1722,6 +1722,9 @@ INSTALLED_APPS = (
'openedx.core.djangoapps.content.course_structures', 'openedx.core.djangoapps.content.course_structures',
'course_structure_api', 'course_structure_api',
# Mailchimp Syncing
'mailing',
# CORS and cross-domain CSRF # CORS and cross-domain CSRF
'corsheaders', 'corsheaders',
'cors_csrf', 'cors_csrf',
......
...@@ -149,3 +149,6 @@ testtools==0.9.34 ...@@ -149,3 +149,6 @@ testtools==0.9.34
# Used for Segment.io analytics # Used for Segment.io analytics
analytics-python==0.4.4 analytics-python==0.4.4
# Needed for mailchimp(mailing djangoapp)
mailsnake==1.6.2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment