Exemple #1
0
Fichier : forms.py Projet : 34/T
    def save_contact(self, request):
        log.debug("Saving contact")
        data = self.cleaned_data
        password = data['password1']
        email = data['email']
        username = data['username']

        verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL')

        if verify:
            site = Site.objects.get_current()
            from registration.models import RegistrationProfile
            # TODO:
            # In django-registration trunk this signature has changed.
            # Satchmo is going to stick with the latest release so I'm changing
            # this to work with 0.7
            # When 0.8 comes out we're going to have to refactor to this:
            #user = RegistrationProfile.objects.create_inactive_user(
            #    username, email, password, site)
            # See ticket #1028 where we checked in the above line prematurely
            user = RegistrationProfile.objects.create_inactive_user(username, '',
                    password, email)
        else:
            user = User.objects.create_user(username, email, password)

        user.save()

        # If the user already has a contact, retrieve it.
        # Otherwise, create a new one.
        try:
            contact = Contact.objects.from_request(request, create=False)

        except Contact.DoesNotExist:
            contact = Contact()

        contact.user = user
        contact.name = username
        contact.email = email
        contact.title = data.get('title', '')
        contact.save()

        if 'newsletter' not in data:
            subscribed = False
        else:
            subscribed = data['newsletter']

        signals.satchmo_registration.send(self, contact=contact, subscribed=subscribed, data=data)

        if not verify:
            user = authenticate(username=username, password=password)
            login(request, user)
            send_welcome_email(email, username, '')
            signals.satchmo_registration_verified.send(self, contact=contact)

        self.contact = contact

        return contact
Exemple #2
0
    def save_contact(self, request):
        log.debug("Saving contact")
        data = self.cleaned_data
        password = data['password1']
        email = data['email']
        first_name = data['first_name']
        last_name = data['last_name']
        username = generate_id(first_name, last_name, email)

        verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL')

        if verify:
            from registration.models import RegistrationProfile
            user = RegistrationProfile.objects.create_inactive_user(
                username, password, email, send_email=True)
        else:
            user = User.objects.create_user(username, email, password)

        user.first_name = first_name
        user.last_name = last_name
        user.save()

        # If the user already has a contact, retrieve it.
        # Otherwise, create a new one.
        try:
            contact = Contact.objects.from_request(request, create=False)

        except Contact.DoesNotExist:
            contact = Contact()

        contact.user = user
        contact.first_name = first_name
        contact.last_name = last_name
        contact.email = email
        contact.role = 'Customer'
        contact.title = data.get('title', '')
        contact.save()

        if 'newsletter' not in data:
            subscribed = False
        else:
            subscribed = data['newsletter']

        signals.satchmo_registration.send(self, contact=contact, subscribed=subscribed, data=data)

        if not verify:
            user = authenticate(username=username, password=password)
            login(request, user)
            send_welcome_email(email, first_name, last_name)
            signals.satchmo_registration_verified.send(self, contact=contact)

        self.contact = contact

        return contact
Exemple #3
0
    def save(self, site_skin):
        cd = self.cleaned_data

        user = User()
        user.username=cd['username']
        user.email = cd['email']
        user.first_name = cd['first_name']
        user.last_name = cd['last_name']
        user.is_active = True
        user.save()
        user.set_password(cd['password1'])
        
        contact = Contact()
        contact.user = user
        contact.role = ContactRole.objects.get(key='Concierge')
        contact.email = cd['email']
        contact.save()
        
        # the listeners.sfst_object_link creates the concierge and adds it to contact.concierge.
        concierge = contact.concierge
        concierge.site_skin = site_skin
        concierge.contact = contact
        concierge.booking_type = cd['booking_type']
        if 'send_checks_to_bool' in cd and cd['send_checks_to_bool']:
            concierge.send_checks_to = Concierge.SEND_CHECKS_TO_HOME
        concierge.save()

        super(ConciergeRegistrationForm, self).save(concierge)
        
        # create default commissions for this new concierge
        for tour_type in TourType.objects.filter(active=True):
            ConciergeCommission.objects.create(concierge=concierge, tour_type=tour_type, amount=tour_type.default_commission)
        
        # shoot emails to concierge about this
        c_subject = 'Your Concierge Account with SF Shuttle Tours / NY Sprinter Tours has been setup!'
        c_message = 'Thank you for creating your Concierge Account with us! You will now be able to easily book tours online, track your sales commission, request brochures, and send us messages through your own account.\n\n'
        c_message += 'PLEASE BOOKMARK THIS LINK: http://%s%s\n\n' % (django_settings.SITE_DOMAIN, reverse('concierges_home'))
        c_message += 'This is the link you will use on a daily basis. If you are having any trouble with your account, please call us at 415-513-5400 (for NY concierges call 1-888-996-9286) and we will be happy to help you!\n\n'
        c_message += 'Regards,\nSF Shuttle Tours / NY Sprinter Tours Team!\n\n'
        start_thread(send_mail, c_subject, c_message, django_settings.DEFAULT_FROM_EMAIL, [django_settings.DEFAULT_TO_EMAIL, contact.email])
        
        # shoot an email to admins about this
        a_subject = '"%s %s" has just created a Concierge Account' % (user.first_name, user.last_name)
        a_message = 'Concierge Name: %s %s\n' % (user.first_name, user.last_name)
        a_message += 'Hotel name: %s\n' % concierge.hotel_name
        a_message += 'Phone number: %s  %s\n' % (concierge.hotel_phone(), concierge.home_phone())
        a_message += 'How often they book our tours: %s\n' % concierge.frequency
        a_message += 'Average number of tours they book per week: %s\n' % concierge.per_week
        start_thread(send_mail, a_subject, a_message, django_settings.DEFAULT_FROM_EMAIL, [django_settings.DEFAULT_TO_EMAIL,])
Exemple #4
0
def handler_create_profile(sender, user, **kwargs):
    try:
        contact = Contact.objects.get(user=user)
    except Contact.DoesNotExist:
        contact = Contact()
    
    contact.user = user
    #contact.first_name = first_name
    #contact.last_name = last_name
    contact.email = user.email
    contact.role = ContactRole.objects.get(pk='Customer')
    contact.title = ''
    contact.save()
    l.debug("Signal Profile Create default -> satchmo_registration_verified")
    signals.satchmo_registration_verified.send(sender=sender, contact=contact)
Exemple #5
0
def handler_create_profile(sender, user, **kwargs):
    try:
        contact = Contact.objects.get(user=user)
    except Contact.DoesNotExist:
        contact = Contact()

    contact.user = user
    #contact.first_name = first_name
    #contact.last_name = last_name
    contact.email = user.email
    contact.role = ContactRole.objects.get(pk='Customer')
    contact.title = ''
    contact.save()
    l.debug("Signal Profile Create default -> satchmo_registration_verified")
    signals.satchmo_registration_verified.send(sender=sender, contact=contact)
Exemple #6
0
    def register(self, request, **kwargs):
        """Use HtmlRegistrationProfile instead of default RegistrationProfile
        """
        username = kwargs['username']
        email = kwargs['email']
        password = kwargs['password1']
        first_name = kwargs['first_name']
        last_name = kwargs['last_name']
        if not username:
            username = generate_id(first_name, last_name, email)
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        new_user = HtmlRegistrationProfile.objects.create_inactive_user(
            username, email, password, site)
            
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.save()

        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)

        # If the user already has a contact, retrieve it.
        # Otherwise, create a new one.
        contact = None
        try:
            contact = Contact.objects.from_request(request, create=False)
        except Contact.DoesNotExist:
            pass

        if contact is None:
            contact = Contact()

        contact.user = new_user
        contact.first_name = first_name
        contact.last_name = last_name
        contact.email = email
        contact.role = ContactRole.objects.get(pk='Customer')
        contact.title = "%s %s" % (first_name, last_name)
        contact.save()
        
        return new_user
Exemple #7
0
    def register(self, request, **kwargs):
        """Use HtmlRegistrationProfile instead of default RegistrationProfile
        """
        username = kwargs['username']
        email = kwargs['email']
        password = kwargs['password1']
        first_name = kwargs['first_name']
        last_name = kwargs['last_name']
        if not username:
            username = generate_id(first_name, last_name, email)
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        new_user = HtmlRegistrationProfile.objects.create_inactive_user(
            username, email, password, site)

        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.save()

        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)

        # If the user already has a contact, retrieve it.
        # Otherwise, create a new one.
        contact = None
        try:
            contact = Contact.objects.from_request(request, create=False)
        except Contact.DoesNotExist:
            pass

        if contact is None:
            contact = Contact()

        contact.user = new_user
        contact.first_name = first_name
        contact.last_name = last_name
        contact.email = email
        contact.role = ContactRole.objects.get(pk='Customer')
        contact.title = "%s %s" % (first_name, last_name)
        contact.save()

        return new_user
Exemple #8
0
    def save_contact(self, request, force_new_contact = False):
        log.debug("Saving contact")
        data = self.cleaned_data
        password = data['password1']
        email = data['email']
        first_name = data['first_name']
        last_name = data['last_name']
        allow_nickname = config_value('SHOP', 'ALLOW_NICKNAME_USERNAME')
        if allow_nickname and data['username']:
            username = data['username']
        else:
            username = generate_id(first_name, last_name, email)
        verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL')

        if verify:
            site = Site.objects.get_current()
            from registration.models import RegistrationProfile
            user = RegistrationProfile.objects.create_inactive_user(
                username, email, password, site)
        else:
            user = User.objects.create_user(username, email, password)

        user.first_name = first_name
        user.last_name = last_name
        user.save()

        # If the user already has a contact, retrieve it.
        # Otherwise, create a new one.
        contact = None
        if not force_new_contact:
            try:
                contact = Contact.objects.from_request(request, create=False)
            except Contact.DoesNotExist:
                pass

        if contact is None:
            contact = Contact()

        contact.user = user
        contact.first_name = first_name
        contact.last_name = last_name
        contact.email = email
        contact.role = ContactRole.objects.get(pk='Customer')
        contact.title = data.get('title', '')
        contact.save()

        if 'newsletter' not in data:
            subscribed = False
        else:
            subscribed = data['newsletter']

        signals.satchmo_registration.send(self, contact=contact, subscribed=subscribed, data=data)

        if not verify:
            username_field = getattr(User, "USERNAME_FIELD", 'username')
            if username_field == 'username':
                user = authenticate(username=username, password=password)
            else:
                user = authenticate(username=email, password=password)
            login(request, user)
            send_welcome_email(email, first_name, last_name)
            signals.satchmo_registration_verified.send(self, contact=contact)

        self.contact = contact

        return contact
Exemple #9
0
    def handle_noargs(self, **options):
        from satchmo_store.contact.models import (
            AddressBook,
            Contact,
            ContactOrganization,
            ContactOrganizationRole,
            ContactRole,
            Organization,
            PhoneNumber,
        )
        from product.models import (
            Category,
            OptionGroup,
            Option,
            Price,
            Product,
        )
        from product.modules.configurable.models import ConfigurableProduct

        from satchmo_store.shop.models import Config
        from django.conf import settings
        from l10n.models import Country
        from django.contrib.sites.models import Site
        from django.contrib.auth.models import User
        #idempotency test

        print "Checking for existing sample data."
        try:
            p = Product.objects.get(slug="dj-rocks")
            print "It looks like you already have loaded the sample store data, quitting."
            import sys
            sys.exit(1)
        except Product.DoesNotExist:
            pass

        print "Loading sample store data."

        #Load basic configuration information

        print "Creating site..."
        try:
            site = Site.objects.get(id=settings.SITE_ID)
            print "Using existing site #%i" % settings.SITE_ID
        except Site.DoesNotExist:
            print "Creating Example Store Site"
            site = Site(domain="localhost", name="Sample Store")
        site.domain = settings.SITE_DOMAIN
        site.name = settings.SITE_NAME
        site.save()
        try:
            store_country = Country.objects.get(iso3_code='USA')
        except Country.DoesNotExist:
            print "\nError: Country data should be first loaded by:  python manage.py satchmo_load_l10n"
            import sys
            sys.exit(1)
        config = Config(site=site,
                        store_name=settings.SITE_NAME,
                        country=store_country,
                        sales_country=store_country)
        config.save()
        config.shipping_countries.add(store_country)
        config.save()
        print "Creating Customers..."
        # Import some customers

        customer = ContactRole.objects.get(pk='Customer')
        c1 = Contact(first_name="Chris",
                     last_name="Smith",
                     email="*****@*****.**",
                     role=customer,
                     notes="Really cool stuff")
        c1.save()
        p1 = PhoneNumber(contact=c1,
                         phone="601-555-5511",
                         type="Home",
                         primary=True)
        p1.save()
        c2 = Contact(first_name="John",
                     last_name="Smith",
                     email="*****@*****.**",
                     role=customer,
                     notes="Second user")
        c2.save()
        p2 = PhoneNumber(contact=c2,
                         phone="999-555-5111",
                         type="Work",
                         primary=True)
        p2.save()
        # Import some addresses for these customers
        us = Country.objects.get(iso2_code='US')
        a1 = AddressBook(description="Home",
                         street1="8235 Pike Street",
                         city="Anywhere Town",
                         state="TN",
                         postal_code="38138",
                         country=us,
                         is_default_shipping=True,
                         contact=c1)
        a1.save()
        a2 = AddressBook(description="Work",
                         street1="1245 Main Street",
                         city="Stillwater",
                         state="MN",
                         postal_code="55082",
                         country=us,
                         is_default_shipping=True,
                         contact=c2)
        a2.save()
        print "Creating Suppliers..."
        #Import some suppliers

        supplier = ContactOrganizationRole.objects.get(pk='Supplier')
        company = ContactOrganization.objects.get(pk='Company')
        contactsupplier = ContactRole.objects.get(pk='Supplier')
        org1 = Organization(name="Rhinestone Ronny",
                            type=company,
                            role=supplier)
        org1.save()
        c4 = Contact(first_name="Fred",
                     last_name="Jones",
                     email="*****@*****.**",
                     role=contactsupplier,
                     organization=org1)
        c4.save()
        p4 = PhoneNumber(contact=c4,
                         phone="800-188-7611",
                         type="Work",
                         primary=True)
        p4.save()
        p5 = PhoneNumber(contact=c4, phone="755-555-1111", type="Fax")
        p5.save()
        a3 = AddressBook(contact=c4,
                         description="Mailing address",
                         street1="Receiving Dept",
                         street2="918 Funky Town St",
                         city="Fishkill",
                         state="NJ",
                         country=us,
                         postal_code="19010")
        a3.save()
        #s1 = Supplier(name="Rhinestone Ronny", address1="918 Funky Town St", address2="Suite 200",
        #              city="Fishkill", state="NJ", zip="19010", phone1="800-188-7611", fax="900-110-1909", email="*****@*****.**",
        #              notes="My main supplier")
        #s1.save()

        #s2 = Supplier(name="Shirt Sally", address1="9 ABC Lane",
        #    city="Happyville", state="MD", zip="190111", phone1="888-888-1111", fax="999-110-1909", email="*****@*****.**",
        #              notes="Shirt Supplier")
        #s2.save()

        print "Creating Categories..."
        #Create some categories
        cat1 = Category(site=site,
                        name="Shirts",
                        slug="shirts",
                        description="Women's Shirts")
        cat1.save()
        cat2 = Category(site=site,
                        name="Short Sleeve",
                        slug="shortsleeve",
                        description="Short sleeve shirts",
                        parent=cat1)
        cat2.save()
        cat3 = Category(site=site,
                        name="Books",
                        slug="book",
                        description="Books")
        cat3.save()
        cat4 = Category(site=site,
                        name="Fiction",
                        slug="fiction",
                        description="Fiction Books",
                        parent=cat3)
        cat4.save()
        cat5 = Category(site=site,
                        name="Science Fiction",
                        slug="scifi",
                        description="Science Fiction",
                        parent=cat4)
        cat5.save()
        cat6 = Category(site=site,
                        name="Non Fiction",
                        slug="nonfiction",
                        description="Non Fiction",
                        parent=cat3)
        cat6.save()
        cat7 = Category(site=site, name="Software", slug="software")
        cat7.save()

        print "Creating products..."
        #Create some items
        i1 = Product(site=site,
                     name="Django Rocks shirt",
                     slug="dj-rocks",
                     description="Really cool shirt",
                     active=True,
                     featured=True)
        i1.save()
        p1 = Price(price="20.00", product=i1)
        p1.save()
        i1.category.add(cat1)
        i1.save()
        i2 = Product(
            site=site,
            name="Python Rocks shirt",
            slug="PY-Rocks",
            description="Really cool python shirt - One Size Fits All",
            active=True,
            featured=True)
        i2.save()
        p2 = Price(price="19.50", product=i2)
        p2.save()
        i2.category.add(cat2)
        i2.save()
        i3 = Product(site=site,
                     name="A really neat book",
                     slug="neat-book",
                     description="A neat book.  You should buy it.",
                     active=True,
                     featured=True)
        i3.save()
        p3 = Price(price="5.00", product=i3)
        p3.save()
        i3.category.add(cat4)
        i3.save()
        i4 = Product(site=site,
                     name="Robots Attack!",
                     slug="robot-attack",
                     description="Robots try to take over the world.",
                     active=True,
                     featured=True)
        i4.save()
        p4 = Price(price="7.99", product=i4)
        p4.save()
        i4.category.add(cat5)
        i4.save()

        #    i5 = Product(site=site, name="Really Neat Software", slug="neat-software", description="Example Configurable/Downloadable product", active=True, featured=True)
        #    i5.save()
        #    i5.category.add(cat7)
        #    i5.save()

        #Create an attribute set
        optSet1 = OptionGroup(site=site, name="sizes", sort_order=1)
        optSet2 = OptionGroup(site=site, name="colors", sort_order=2)
        optSet1.save()
        optSet2.save()

        optSet3 = OptionGroup(site=site, name="Book type", sort_order=1)
        optSet3.save()

        optSet4 = OptionGroup(site=site, name="Full/Upgrade", sort_order=5)
        optSet4.save()

        optItem1a = Option(name="Small",
                           value="S",
                           sort_order=1,
                           option_group=optSet1)
        optItem1a.save()
        optItem1b = Option(name="Medium",
                           value="M",
                           sort_order=2,
                           option_group=optSet1)
        optItem1b.save()
        optItem1c = Option(name="Large",
                           value="L",
                           sort_order=3,
                           price_change="1.00",
                           option_group=optSet1)
        optItem1c.save()

        optItem2a = Option(name="Black",
                           value="B",
                           sort_order=1,
                           option_group=optSet2)
        optItem2a.save()
        optItem2b = Option(name="White",
                           value="W",
                           sort_order=2,
                           option_group=optSet2)
        optItem2b.save()
        optItem2c = Option(name="Blue",
                           value="BL",
                           sort_order=3,
                           price_change="2.00",
                           option_group=optSet2)
        optItem2c.save()

        optItem3a = Option(name="Hard cover",
                           value="hard",
                           sort_order=1,
                           option_group=optSet3)
        optItem3a.save()
        optItem3b = Option(name="Soft cover",
                           value="soft",
                           sort_order=2,
                           price_change="1.00",
                           option_group=optSet3)
        optItem3b.save()
        optItem3c = Option(name="On tape",
                           value="tape",
                           sort_order=3,
                           option_group=optSet3)
        optItem3c.save()

        optItem4a = Option(name="Full Version",
                           value="full",
                           option_group=optSet4,
                           sort_order=1)
        optItem4a.save()
        optItem4b = Option(name="Upgrade Version",
                           value="upgrade",
                           option_group=optSet4,
                           sort_order=2)
        optItem4b.save()

        #Add the option group to our items
        pg1 = ConfigurableProduct(product=i1)
        pg1.save()
        pg1.option_group.add(optSet1)
        pg1.save()
        pg1.option_group.add(optSet2)
        pg1.save()

        pg3 = ConfigurableProduct(product=i3)
        pg3.save()
        pg3.option_group.add(optSet3)
        pg3.save()

        pg4 = ConfigurableProduct(product=i4)
        pg4.save()
        pg4.option_group.add(optSet3)
        pg4.save()

        #    pg5 = ConfigurableProduct(product=i5)
        #    pg5.option_group.add(optSet4)
        #    pg5.save()

        print "Creating product variations..."
        #Create the required sub_items
        pg1.create_all_variations()
        pg3.create_all_variations()
        pg4.create_all_variations()
        #pg5.create_all_variations()

        #set prices for full and upgrade versions of neat-software, this is an alternative to using the price_change in options, it allows for more flexability when required.
        #    pv1 = pg5.get_product_from_options([optItem4a])
        #    Price(product=pv1, price='5.00').save()
        #    Price(product=pv1, price='2.00', quantity='50.00').save()
        #    DownloadableProduct(product=pv1).save()

        #    pv2 = pg5.get_product_from_options([optItem4b])
        #    Price(product=pv2, price='1.00').save()
        #    DownloadableProduct(product=pv2).save()

        print "Create a test user..."
        #First see if our test user is still there, then use or create that user
        try:
            test_user = User.objects.get(username="******")
        except:
            test_user = User.objects.create_user('csmith',
                                                 '*****@*****.**', 'test')
            test_user.save()
        c1.user = test_user
        c1.save()
Exemple #10
0
    def save_contact(self, request):
        log.debug("Saving contact")
        data = self.cleaned_data
        password = data['password1']
        email = data['email']
        first_name = data['first_name']
        last_name = data['last_name']
        username = generate_id(first_name, last_name, email)

        verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL')

        if verify:
            site = Site.objects.get_current()
            from registration.models import RegistrationProfile
            # TODO:
            # In django-registration trunk this signature has changed.
            # Satchmo is going to stick with the latest release so I'm changing
            # this to work with 0.7
            # When 0.8 comes out we're going to have to refactor to this:
            #user = RegistrationProfile.objects.create_inactive_user(
            #    username, email, password, site)
            # See ticket #1028 where we checked in the above line prematurely
            user = RegistrationProfile.objects.create_inactive_user(
                username, password, email)
        else:
            user = User.objects.create_user(username, email, password)

        user.first_name = first_name
        user.last_name = last_name
        user.save()

        # If the user already has a contact, retrieve it.
        # Otherwise, create a new one.
        try:
            contact = Contact.objects.from_request(request, create=False)

        except Contact.DoesNotExist:
            contact = Contact()

        contact.user = user
        contact.first_name = first_name
        contact.last_name = last_name
        contact.email = email
        contact.role = ContactRole.objects.get(pk='Customer')
        contact.title = data.get('title', '')
        contact.save()

        if 'newsletter' not in data:
            subscribed = False
        else:
            subscribed = data['newsletter']

        signals.satchmo_registration.send(self,
                                          contact=contact,
                                          subscribed=subscribed,
                                          data=data)

        if not verify:
            user = authenticate(username=username, password=password)
            login(request, user)
            send_welcome_email(email, first_name, last_name)
            signals.satchmo_registration_verified.send(self, contact=contact)

        self.contact = contact

        return contact
    def handle_noargs(self, **options):
        from satchmo_store.contact.models import (
            AddressBook,
            Contact,
            ContactOrganization,
            ContactOrganizationRole,
            ContactRole,
            Organization,
            PhoneNumber,
        )
        from product.models import (
            Category,
            OptionGroup,
            Option,
            Price,
            Product,
        )
        from product.modules.configurable.models import ConfigurableProduct

        from satchmo_store.shop.models import Config
        from django.conf import settings
        from l10n.models import Country
        from django.contrib.sites.models import Site
        from django.contrib.auth.models import User
        #idempotency test

        print "Checking for existing sample data."
        try:
            p = Product.objects.get(slug="dj-rocks")
            print "It looks like you already have loaded the sample store data, quitting."
            import sys
            sys.exit(1)
        except Product.DoesNotExist:
            pass

        print "Loading sample store data."

        #Load basic configuration information

        print "Creating site..."
        try:
            site = Site.objects.get(id=settings.SITE_ID)
            print "Using existing site #%i" % settings.SITE_ID
        except Site.DoesNotExist:
            print "Creating Example Store Site"
            site = Site(domain="localhost", name="Sample Store")
        site.domain = settings.SITE_DOMAIN
        site.name = settings.SITE_NAME
        site.save()
        try:
            store_country = Country.objects.get(iso3_code='USA')
        except Country.DoesNotExist:
            print "\nError: Country data should be first loaded by:  python manage.py satchmo_load_l10n"
            import sys
            sys.exit(1)
        config = Config(site=site, store_name=settings.SITE_NAME, country=store_country, sales_country=store_country)
        config.save()
        config.shipping_countries.add(store_country)
        config.save()
        print "Creating Customers..."
        # Import some customers

        customer = ContactRole.objects.get(pk='Customer')
        c1 = Contact(first_name="Chris", last_name="Smith", email="*****@*****.**", role=customer, notes="Really cool stuff")
        c1.save()
        p1 = PhoneNumber(contact=c1, phone="601-555-5511", type="Home",primary=True)
        p1.save()
        c2 = Contact(first_name="John", last_name="Smith", email="*****@*****.**", role=customer, notes="Second user")
        c2.save()
        p2 = PhoneNumber(contact=c2, phone="999-555-5111", type="Work",primary=True)
        p2.save()
        # Import some addresses for these customers
        us = Country.objects.get(iso2_code='US');
        a1 = AddressBook(description="Home", street1="8235 Pike Street", city="Anywhere Town", state="TN",
                     postal_code="38138", country=us, is_default_shipping=True, contact=c1)
        a1.save()
        a2 = AddressBook(description="Work", street1="1245 Main Street", city="Stillwater", state="MN",
                     postal_code="55082", country=us, is_default_shipping=True, contact=c2)
        a2.save()
        print "Creating Suppliers..."
        #Import some suppliers

        supplier = ContactOrganizationRole.objects.get(pk='Supplier')
        company = ContactOrganization.objects.get(pk='Company')
        contactsupplier = ContactRole.objects.get(pk='Supplier')
        org1 = Organization(name="Rhinestone Ronny", type=company, role=supplier)
        org1.save()
        c4 = Contact(first_name="Fred", last_name="Jones", email="*****@*****.**",
            role=contactsupplier, organization=org1)
        c4.save()
        p4 = PhoneNumber(contact=c4,phone="800-188-7611", type="Work", primary=True)
        p4.save()
        p5 = PhoneNumber(contact=c4,phone="755-555-1111",type="Fax")
        p5.save()
        a3 = AddressBook(contact=c4, description="Mailing address", street1="Receiving Dept",
            street2="918 Funky Town St", city="Fishkill",
             state="NJ", country=us, postal_code="19010")
        a3.save()
        #s1 = Supplier(name="Rhinestone Ronny", address1="918 Funky Town St", address2="Suite 200",
        #              city="Fishkill", state="NJ", zip="19010", phone1="800-188-7611", fax="900-110-1909", email="*****@*****.**",
        #              notes="My main supplier")
        #s1.save()

        #s2 = Supplier(name="Shirt Sally", address1="9 ABC Lane",
        #    city="Happyville", state="MD", zip="190111", phone1="888-888-1111", fax="999-110-1909", email="*****@*****.**",
        #              notes="Shirt Supplier")
        #s2.save()


        print "Creating Categories..."
        #Create some categories
        '''cat1 = Category(site=site, name="Shirts",slug="shirts",description="Women's Shirts")
        cat1.save()
        cat2 = Category(site=site, name="Short Sleeve",slug="shortsleeve",description="Short sleeve shirts", parent=cat1)
        cat2.save()'''
        cat3 = Category(name="Books",slug="book",description="Books")
        cat3.save()
        cat3.site.add(site)
        
        '''cat4 = Category(site=site, name="Fiction",slug="fiction",description="Fiction Books", parent=cat3)
        cat4.save()
        cat5 = Category(site=site, name="Science Fiction",slug="scifi",description="Science Fiction",parent=cat4)
        cat5.save()
        cat6 = Category(site=site, name="Non Fiction",slug="nonfiction",description="Non Fiction",parent=cat3)
        cat6.save()
        cat7 = Category(site=site, name="Software", slug="software")
        cat7.save()'''


        print "Creating products..."
        #Create some items
        '''i1 = Product(name="Django Rocks shirt", slug="dj-rocks", description="Really cool shirt",
                 active=True, featured=True)
        i1.save()
        p1 = Price(price="20.00", product=i1)
        p1.save()
        i1.category.add(cat1)
        i1.save()
        i2 = Product(name="Python Rocks shirt", slug="PY-Rocks",
            description="Really cool python shirt - One Size Fits All",
            active=True, featured=True)
        i2.save()
        p2 = Price(price="19.50", product=i2)
        p2.save()
        i2.category.add(cat2)
        i2.save()'''
        i3 = Product(name="Purusha Suktam", slug="Advyata",
            description="A neat book.  You should buy it.",
            active=True, featured=True)
        i3.save()
        i3.site.add(site)
        p3 = Price(price="5.00", product=i3)
        p3.save()
        i3.category.add(cat3)
        i3.save()
        i3.site.add(site)


        '''i4 = Product(name="Robots Attack!", slug="robot-attack",
            description="Robots try to take over the world.",
            active=True, featured=True)
        i4.save()
        p4 = Price(price="7.99", product=i4)
        p4.save()
        i4.category.add(cat5)
        i4.save()

    #    i5 = Product(site=site, name="Really Neat Software", slug="neat-software", description="Example Configurable/Downloadable product", active=True, featured=True)
    #    i5.save()
    #    i5.category.add(cat7)
    #    i5.save()

        #Create an attribute set
        optSet1 = OptionGroup(site=site, name="sizes", sort_order=1)
        optSet2 = OptionGroup(site=site, name="colors", sort_order=2)
        optSet1.save()
        optSet2.save()'''

        optSet3 = OptionGroup(name="Book type", sort_order=1)
        optSet3.save()
        optSet3.site.add(site)

        '''optSet4 = OptionGroup(site=site, name="Full/Upgrade", sort_order=5)
        optSet4.save()

        optItem1a = Option(name="Small", value="S", sort_order=1, option_group=optSet1)
        optItem1a.save()
        optItem1b = Option(name="Medium", value="M", sort_order=2, option_group=optSet1)
        optItem1b.save()
        optItem1c = Option(name="Large", value="L", sort_order=3, price_change="1.00", option_group=optSet1)
        optItem1c.save()

        optItem2a = Option(name="Black", value="B", sort_order=1, option_group=optSet2)
        optItem2a.save()
        optItem2b = Option(name="White", value="W", sort_order=2, option_group=optSet2)
        optItem2b.save()
        optItem2c = Option(name="Blue", value="BL", sort_order=3, price_change="2.00", option_group=optSet2)
        optItem2c.save()'''

        optItem3a = Option(name="Hard cover", value="hard", sort_order=1, option_group=optSet3)
        optItem3a.save()
        optItem3b = Option(name="Soft cover", value="soft", sort_order=2, price_change="1.00", option_group=optSet3)
        optItem3b.save()
        optItem3c = Option(name="On tape", value="tape", sort_order=3, option_group=optSet3)
        optItem3c.save()

        '''optItem4a = Option(name="Full Version", value="full", option_group=optSet4, sort_order=1)
        optItem4a.save()
        optItem4b = Option(name="Upgrade Version", value="upgrade", option_group=optSet4, sort_order=2)
        optItem4b.save()'''


        #Add the option group to our items
        '''pg1 = ConfigurableProduct(product=i1)
        pg1.save()
        pg1.option_group.add(optSet1)
        pg1.save()
        pg1.option_group.add(optSet2)
        pg1.save()'''

        pg3 = ConfigurableProduct(product=i3)
        pg3.save()
        pg3.option_group.add(optSet3)
        pg3.save()

        '''pg4 = ConfigurableProduct(product=i4)
        pg4.save()
        pg4.option_group.add(optSet3)
        pg4.save()'''

    #    pg5 = ConfigurableProduct(product=i5)
    #    pg5.option_group.add(optSet4)
    #    pg5.save()

        print "Creating product variations..."
        #Create the required sub_items
        #pg1.create_all_variations()
        pg3.create_all_variations()
        #pg4.create_all_variations()
        #pg5.create_all_variations()

        #set prices for full and upgrade versions of neat-software, this is an alternative to using the price_change in options, it allows for more flexability when required.
    #    pv1 = pg5.get_product_from_options([optItem4a])
    #    Price(product=pv1, price='5.00').save()
    #    Price(product=pv1, price='2.00', quantity='50.00').save()
    #    DownloadableProduct(product=pv1).save()

    #    pv2 = pg5.get_product_from_options([optItem4b])
    #    Price(product=pv2, price='1.00').save()
    #    DownloadableProduct(product=pv2).save()

        print "Create a test user..."
        #First see if our test user is still there, then use or create that user
        try:
            test_user = User.objects.get(username="******")
        except:
            test_user = User.objects.create_user('csmith', '*****@*****.**', 'test')
            test_user.save()
        c1.user = test_user
        c1.save()
Exemple #12
0
    def save_contact(self, request, force_new_contact = False):
        log.debug("Saving contact")
        data = self.cleaned_data
        password = data['password1']
        email = data['email']
        first_name = data['first_name']
        last_name = data['last_name']
        allow_nickname = config_value('SHOP', 'ALLOW_NICKNAME_USERNAME')
        if allow_nickname and data['username']:
            username = data['username']
        else:
            username = generate_id(first_name, last_name, email)
        verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL')

        if verify:
            site = Site.objects.get_current()
            from registration.models import RegistrationProfile
            user = RegistrationProfile.objects.create_inactive_user(
                username, email, password, site)
        else:
            user = User.objects.create_user(username, email, password)

        user.first_name = first_name
        user.last_name = last_name
        user.save()

        # If the user already has a contact, retrieve it.
        # Otherwise, create a new one.
        contact = None
        if not force_new_contact:
            try:
                contact = Contact.objects.from_request(request, create=False)
            except Contact.DoesNotExist:
                pass

        if contact is None:
            contact = Contact()

        contact.user = user
        contact.first_name = first_name
        contact.last_name = last_name
        contact.email = email
        contact.role = ContactRole.objects.get(pk='Customer')
        contact.title = data.get('title', '')
        contact.save()

        if 'newsletter' not in data:
            subscribed = False
        else:
            subscribed = data['newsletter']

        signals.satchmo_registration.send(self, contact=contact, subscribed=subscribed, data=data)

        if not verify:
            user = authenticate(username=username, password=password)
            login(request, user)
            send_welcome_email(email, first_name, last_name)
            signals.satchmo_registration_verified.send(self, contact=contact)

        self.contact = contact

        return contact