Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from django.contrib.auth.models import User, Group
- from django.db import transaction
- from core.models import Country, UserExtension
- from core.helpers import send_html_email
- from products.models import Product, CATEGORY_1, CATEGORY_2, CATEGORY_3
- from sales.models import Franchisee, FranchiseSettings
- def random_username():
- settings = FranchiseSettings.objects.first()
- name = ''.join(["%s" % random.randint(0, 9) for num in range(0, settings.username_length)])
- return name
- franchisees = [
- ['Ben', 'McNamara', 'admin@organicblends.co', [
- '128B Ferme Park Road', 'Crouch End', 'N8 9SD', '07447 093768'
- ]],
- ['Matthew', 'Hill', 'mhilly6@aol.com', [
- '82 Douglas Lane', 'Grimsargh, Preston', 'PR2 5JF', '07921 295977'
- ]],
- ['Carl', 'Williams', 'carl_williams2@hotmail.co.uk', [
- '18 Charlton Place', 'Pembroke Dock, Pembrokeshire, Wales', 'SA72 6AY', '07545 610507'
- ]],
- ['Tim', 'College', 'random1@example.com', [
- '16 Ashdown Drive', 'Nuneaton, Warwickshire', 'CV10 7hh', '07816 076615'
- ]],
- ['Natalia', 'Spensley', 'nataliaspensley@gmail.com', [
- '45 Blubell hollow', 'Walton on the Hill, Stafford', 'ST17 0jp', '07725 591354'
- ]],
- ['Sam', 'Herrington', 'sam@tcpn.co.uk', [
- '2 Rectory Close', 'Crick, Northants', 'NN6 7SY', '07975 669158'
- ]],
- ['Karen', 'Leith', 'random2@example.com', [
- 'Rose Villa, 34 High Street', 'Wheatley, Oxfordshire', 'OX33 1XX', '07827 593130'
- ]],
- ['Pat', 'Lawrence', 'mrpatlawrence@gmail.com', [
- '31 Nelson Rd', 'Bognor Regis', 'PO21 2RY', '07887 870532'
- ]],
- ['Steve', 'Neal', 'stevejneal23@gmail.com', [
- '14 Copperfield Close', 'Gravesend, Kent', 'DA12 2NJ', '07957 616647'
- ]],
- ]
- with transaction.atomic():
- fil = open('franchisee_logins', 'w+b')
- parent = User.objects.get(email="hibbo28@gmail.com").franchisee
- for franchisee in franchisees:
- user = User.objects.create_user(
- random_username(),
- franchisee[2],
- 'Pas5w0rd!'
- )
- user.first_name = franchisee[0]
- user.last_name = franchisee[1]
- user.save()
- user.groups.add(Group.objects.get(name="franchisee"))
- UserExtension.forgot_password(user)
- fran = franchisee[3]
- f = Franchisee.objects.create(
- user=user,
- active=True,
- phone=fran[3],
- address=fran[0],
- zipcode=fran[2],
- city=fran[1],
- country=Country.objects.get(name="United Kingdom"),
- authorized=True,
- parent=parent,
- )
- if not "example" in user.email:
- send_html_email(
- f.mail_context("Welcome to CityInformation"),
- 'sales/mails/welcome_franchisee'
- )
- fil.write("Name: %s, login_number: %s, password: Pas5w0rd!\n" % (user.get_full_name(), user.username))
- fil.write('Everyone should change his password as soon as possible')
- fil.close()
- products = [
- [CATEGORY_1, 1, Product.FRONTPAGE, 499],
- [CATEGORY_2, 1, Product.FRONTPAGE, 349],
- [CATEGORY_3, 1, Product.FRONTPAGE, 249],
- [CATEGORY_1, 1, Product.SUBPAGE, 249],
- [CATEGORY_2, 1, Product.SUBPAGE, 179],
- [CATEGORY_3, 1, Product.SUBPAGE, 129],
- [CATEGORY_1, 3, Product.FRONTPAGE, 249],
- [CATEGORY_2, 3, Product.FRONTPAGE, 199],
- [CATEGORY_3, 3, Product.FRONTPAGE, 149],
- [CATEGORY_1, 3, Product.SUBPAGE, 119],
- [CATEGORY_2, 3, Product.SUBPAGE, 99],
- [CATEGORY_3, 3, Product.SUBPAGE, 69],
- [CATEGORY_1, 6, Product.FRONTPAGE, 219],
- [CATEGORY_2, 6, Product.FRONTPAGE, 169],
- [CATEGORY_3, 6, Product.FRONTPAGE, 119],
- [CATEGORY_1, 6, Product.SUBPAGE, 109],
- [CATEGORY_2, 6, Product.SUBPAGE, 89],
- [CATEGORY_3, 6, Product.SUBPAGE, 59],
- [CATEGORY_1, 12, Product.FRONTPAGE, 199],
- [CATEGORY_2, 12, Product.FRONTPAGE, 149],
- [CATEGORY_3, 12, Product.FRONTPAGE, 99],
- [CATEGORY_1, 12, Product.SUBPAGE, 99],
- [CATEGORY_2, 12, Product.SUBPAGE, 79],
- [CATEGORY_3, 12, Product.SUBPAGE, 49],
- ]
- uk = Country.objects.get(name="United Kingdom")
- for product in products:
- p = Product.objects.get(
- country=uk,
- category=product[0],
- duration=product[1],
- type=product[2],
- )
- p.price = product[3]
- p.save()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement