Advertisement
Guest User

Untitled

a guest
Sep 9th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. import random
  2. from django.contrib.auth.models import User, Group
  3. from django.db import transaction
  4.  
  5. from core.models import Country, UserExtension
  6. from core.helpers import send_html_email
  7. from products.models import Product, CATEGORY_1, CATEGORY_2, CATEGORY_3
  8. from sales.models import Franchisee, FranchiseSettings
  9.  
  10.  
  11. def random_username():
  12. settings = FranchiseSettings.objects.first()
  13. name = ''.join(["%s" % random.randint(0, 9) for num in range(0, settings.username_length)])
  14. return name
  15.  
  16. franchisees = [
  17. ['Ben', 'McNamara', 'admin@organicblends.co', [
  18. '128B Ferme Park Road', 'Crouch End', 'N8 9SD', '07447 093768'
  19. ]],
  20. ['Matthew', 'Hill', 'mhilly6@aol.com', [
  21. '82 Douglas Lane', 'Grimsargh, Preston', 'PR2 5JF', '07921 295977'
  22. ]],
  23. ['Carl', 'Williams', 'carl_williams2@hotmail.co.uk', [
  24. '18 Charlton Place', 'Pembroke Dock, Pembrokeshire, Wales', 'SA72 6AY', '07545 610507'
  25. ]],
  26. ['Tim', 'College', 'random1@example.com', [
  27. '16 Ashdown Drive', 'Nuneaton, Warwickshire', 'CV10 7hh', '07816 076615'
  28. ]],
  29. ['Natalia', 'Spensley', 'nataliaspensley@gmail.com', [
  30. '45 Blubell hollow', 'Walton on the Hill, Stafford', 'ST17 0jp', '07725 591354'
  31. ]],
  32. ['Sam', 'Herrington', 'sam@tcpn.co.uk', [
  33. '2 Rectory Close', 'Crick, Northants', 'NN6 7SY', '07975 669158'
  34. ]],
  35. ['Karen', 'Leith', 'random2@example.com', [
  36. 'Rose Villa, 34 High Street', 'Wheatley, Oxfordshire', 'OX33 1XX', '07827 593130'
  37. ]],
  38. ['Pat', 'Lawrence', 'mrpatlawrence@gmail.com', [
  39. '31 Nelson Rd', 'Bognor Regis', 'PO21 2RY', '07887 870532'
  40. ]],
  41. ['Steve', 'Neal', 'stevejneal23@gmail.com', [
  42. '14 Copperfield Close', 'Gravesend, Kent', 'DA12 2NJ', '07957 616647'
  43. ]],
  44. ]
  45.  
  46.  
  47. with transaction.atomic():
  48. fil = open('franchisee_logins', 'w+b')
  49. parent = User.objects.get(email="hibbo28@gmail.com").franchisee
  50. for franchisee in franchisees:
  51. user = User.objects.create_user(
  52. random_username(),
  53. franchisee[2],
  54. 'Pas5w0rd!'
  55. )
  56. user.first_name = franchisee[0]
  57. user.last_name = franchisee[1]
  58. user.save()
  59. user.groups.add(Group.objects.get(name="franchisee"))
  60. UserExtension.forgot_password(user)
  61. fran = franchisee[3]
  62. f = Franchisee.objects.create(
  63. user=user,
  64. active=True,
  65. phone=fran[3],
  66. address=fran[0],
  67. zipcode=fran[2],
  68. city=fran[1],
  69. country=Country.objects.get(name="United Kingdom"),
  70. authorized=True,
  71. parent=parent,
  72. )
  73.  
  74. if not "example" in user.email:
  75. send_html_email(
  76. f.mail_context("Welcome to CityInformation"),
  77. 'sales/mails/welcome_franchisee'
  78. )
  79.  
  80. fil.write("Name: %s, login_number: %s, password: Pas5w0rd!\n" % (user.get_full_name(), user.username))
  81.  
  82. fil.write('Everyone should change his password as soon as possible')
  83. fil.close()
  84.  
  85.  
  86. products = [
  87. [CATEGORY_1, 1, Product.FRONTPAGE, 499],
  88. [CATEGORY_2, 1, Product.FRONTPAGE, 349],
  89. [CATEGORY_3, 1, Product.FRONTPAGE, 249],
  90.  
  91. [CATEGORY_1, 1, Product.SUBPAGE, 249],
  92. [CATEGORY_2, 1, Product.SUBPAGE, 179],
  93. [CATEGORY_3, 1, Product.SUBPAGE, 129],
  94.  
  95. [CATEGORY_1, 3, Product.FRONTPAGE, 249],
  96. [CATEGORY_2, 3, Product.FRONTPAGE, 199],
  97. [CATEGORY_3, 3, Product.FRONTPAGE, 149],
  98.  
  99. [CATEGORY_1, 3, Product.SUBPAGE, 119],
  100. [CATEGORY_2, 3, Product.SUBPAGE, 99],
  101. [CATEGORY_3, 3, Product.SUBPAGE, 69],
  102.  
  103. [CATEGORY_1, 6, Product.FRONTPAGE, 219],
  104. [CATEGORY_2, 6, Product.FRONTPAGE, 169],
  105. [CATEGORY_3, 6, Product.FRONTPAGE, 119],
  106.  
  107. [CATEGORY_1, 6, Product.SUBPAGE, 109],
  108. [CATEGORY_2, 6, Product.SUBPAGE, 89],
  109. [CATEGORY_3, 6, Product.SUBPAGE, 59],
  110.  
  111. [CATEGORY_1, 12, Product.FRONTPAGE, 199],
  112. [CATEGORY_2, 12, Product.FRONTPAGE, 149],
  113. [CATEGORY_3, 12, Product.FRONTPAGE, 99],
  114.  
  115. [CATEGORY_1, 12, Product.SUBPAGE, 99],
  116. [CATEGORY_2, 12, Product.SUBPAGE, 79],
  117. [CATEGORY_3, 12, Product.SUBPAGE, 49],
  118. ]
  119.  
  120. uk = Country.objects.get(name="United Kingdom")
  121. for product in products:
  122. p = Product.objects.get(
  123. country=uk,
  124. category=product[0],
  125. duration=product[1],
  126. type=product[2],
  127. )
  128. p.price = product[3]
  129. p.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement