generate_subscriptions.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. # intended to run in shell plus
  2. from django.contrib.auth.models import User
  3. from django.db import transaction
  4. from catalog.constants import INCOUNTY, INSTATE, OUTSTATE, REGULAR, FIRST_CLASS, FOREIGN
  5. from catalog.models import Subscription
  6. TITLES = ('The Weekly Packet', 'Island Advantages', 'Castine Patriot')
  7. PREFIXES = (('IC', INCOUNTY),
  8. ('IS', INSTATE),
  9. ('OOS', OUTSTATE)) # 'F'
  10. DURATIONS = ['9', '12', '24']
  11. SHIPPING = (('R', REGULAR),) # 'FC'
  12. pricing = {
  13. 'IC9R': 23.95,
  14. 'IS9R': 24.95,
  15. 'OOS9R': 34.95,
  16. 'IC12R': 29.95,
  17. 'IS12R': 31.95,
  18. 'OOS12R': 44.95,
  19. 'IC24R': 54.95,
  20. 'IS24R': 57.95,
  21. 'OOS24R': 79.95,
  22. }
  23. with transaction.commit_on_success():
  24. admin, rc = User.objects.get_or_create(username='admin')
  25. for title in TITLES:
  26. for prefix, value in PREFIXES:
  27. for duration in DURATIONS:
  28. for shipping_prefix, shipping_value in SHIPPING:
  29. sku = prefix + duration + shipping_prefix
  30. price = pricing[sku]
  31. # first letter in title
  32. title_abbrev = ''.join([i[0] for i in title.upper().split()])
  33. sku = title_abbrev + sku
  34. # regular flavor
  35. # subscription, rc = Subscription.objects.get_or_create(
  36. # sku=sku,
  37. # created_by=admin,
  38. # last_updated_by=admin,
  39. # price=price,
  40. # shipping_cost=0.00,
  41. # shipping_cost_multiple=1,
  42. # duration=duration,
  43. # title=title,
  44. # shipping_type=value,
  45. # shipping_method=shipping_value)
  46. # subscription.save()
  47. # renewal flavor
  48. sku += 'REN'
  49. subscription, rc = Subscription.objects.get_or_create(
  50. sku=sku,
  51. created_by=admin,
  52. last_updated_by=admin,
  53. price=price,
  54. shipping_cost=0.00,
  55. shipping_cost_multiple=1,
  56. duration=duration,
  57. title=title,
  58. shipping_type=value,
  59. shipping_method=shipping_value,
  60. renewal=True)
  61. subscription.save()
  62. # intended to run in shell plus
  63. from django.contrib.auth.models import User
  64. from django.db import transaction
  65. from catalog.constants import INCOUNTY, INSTATE, OUTSTATE, REGULAR, FIRST_CLASS, FOREIGN
  66. from catalog.models import Subscription
  67. TITLES = ('The Weekly Packet', 'Island Advantages', 'Castine Patriot')
  68. PREFIXES = (('IC', INCOUNTY),
  69. ('IS', INSTATE),
  70. ('OOS', OUTSTATE),
  71. ('F', FOREIGN),) # 'F'
  72. DURATIONS = ['12']
  73. SHIPPING = (('FC', FIRST_CLASS),) # 'FC'
  74. pricing = {
  75. 'IC12FC': 169.95,
  76. 'IS12FC': 169.95,
  77. 'OOS12FC': 169.95,
  78. 'F12FC': 279.95
  79. }
  80. with transaction.commit_on_success():
  81. admin = User.objects.get(username='admin')
  82. for title in TITLES:
  83. for prefix, value in PREFIXES:
  84. for duration in DURATIONS:
  85. for shipping_prefix, shipping_value in SHIPPING:
  86. sku = prefix + duration + shipping_prefix
  87. price = pricing[sku]
  88. # first letter in title
  89. title_abbrev = ''.join([i[0] for i in title.upper().split()])
  90. sku = title_abbrev + sku
  91. # regular flavor
  92. subscription, rc = Subscription.objects.get_or_create(
  93. sku=sku,
  94. created_by=admin,
  95. last_updated_by=admin,
  96. price=price,
  97. shipping_cost=0.00,
  98. shipping_cost_multiple=1,
  99. duration=duration,
  100. title=title,
  101. shipping_type=value,
  102. shipping_method=shipping_value)
  103. subscription.save()
  104. # renewal flavor
  105. sku += 'REN'
  106. subscription, rc = Subscription.objects.get_or_create(
  107. sku=sku,
  108. created_by=admin,
  109. last_updated_by=admin,
  110. price=price,
  111. shipping_cost=0.00,
  112. shipping_cost_multiple=1,
  113. duration=duration,
  114. title=title,
  115. shipping_type=value,
  116. shipping_method=shipping_value,
  117. renewal=True)
  118. subscription.save()