-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmigrate_courses.py
66 lines (59 loc) · 1.87 KB
/
migrate_courses.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import os,django;os.environ['DJANGO_SETTINGS_MODULE']='main.settings';django.setup()
from course.models import Course, CourseEnrollment
from store.models import Consumable, CourseCheckout
from drop.models import CartItem
from tool.models import UserCriterion
import datetime
consumable_course_ids = [
(948, 37),
(949, 6),
(857, 48),
(1029, 62),
(1105, 180),
(858, 63),
(856, 3),
(952, 95),
(855, 42),
]
unpaid = 0
nouser = 0
for consumable_id,course_id in consumable_course_ids:
consumable = Consumable.objects.get(id=consumable_id)
course = Course.objects.get(id=course_id)
coursecheckout,new = CourseCheckout.objects.get_or_create(
name=consumable.name.split(" Check")[0],
active=True,
unit_price=consumable.unit_price,
course=course
)
if new:
print "new CC: %s"%coursecheckout
orderitems = consumable.orderitem_set.all()
for oi in orderitems:
oi.product_name = coursecheckout.get_name()
oi.product_reference = coursecheckout.get_product_reference()
oi.product = coursecheckout
oi.save()
user = oi.order.user
if not user:
nouser += 1
continue
if not oi.order.is_paid():
unpaid += 1
continue
coursecheckout.purchase(oi.order.user,oi.quantity)
ce = CourseEnrollment.objects.get(user=oi.order.user,course=course)
ce.datetime = oi.order.modified
ce.save()
ucs = UserCriterion.objects.filter(user=oi.order.user,criterion=ce.get_criteria())
if ucs:
for uc in ucs:
print ucs.count(),'\t',uc.content_object._meta.model_name,'\t',uc.content_object
if uc.content_object._meta.model_name == 'user':
ce.completed = oi.order.modified
ce.save()
print "converting %s"%ce
CartItem.objects.filter(product=consumable).update(product=coursecheckout)
print orderitems.count(),'\t',consumable
print "unpaid: ",unpaid
print "nouser: ",nouser