generate_subscriptions.py 4.7 KB

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