示例#1
0
def init_data(app, created_models, verbosity, **kwargs):
    from shoppy.product.models import TaxClass

    if TaxClass in created_models:
        tc19 = TaxClass(percent=19, description="Standard 19%")
        tc19.save()
        tc7 = TaxClass(percent=7, description="Standard 7%")
        tc7.save()
    def handle_noargs(self, **options):
        from django.contrib.auth.models import User

        from shoppy.l10n.models import Language, DeliveryCountry
        from shoppy.product.models import Product, TaxClass, Productoption, Optionfield
        from shoppy.accounts.models import Customer
        from shoppy.payment.models import Payment, Paymentname
        from shoppy.shop.models import Settings
        print "Checking for existing sample data."
        try:
            p = Language.objects.get(code="de")
            print "It looks like you already have loaded the sample store data, quitting."
            import sys
            sys.exit(1)
        except Language.DoesNotExist:
            pass

        print "Loading sample store data."

        #create and import language-codes
        print 'import languages'
        lde = Language(code='de',description='Deutsch',isActive=True)
        lde.save()
        len = Language(code='en',description='English',isActive=False)
        len.save()

        #create and import delivery countries
        print 'import delivery countries'
        dc1 = DeliveryCountry(language=lde,country='Deutschland',isActive=True)
        dc1.save()
        dc2 = DeliveryCountry(language=len,country='Germany',isActive=True)
        dc2.save()
        dc3 = DeliveryCountry(language=lde,country=unicode('Österreich','latin-1'),isActive=False)
        dc3.save()
        dc4 = DeliveryCountry(language=len,country='Austria',isActive=False)
        dc4.save()

        #create and import shop settings
        print 'import shop settings'
        set1 = Settings(name='shop1')
        set1.shippingcharges = '3.50'
        set1.shippingchargescur = w1
        set1.freeshipping = '30.00'
        set1.freeshippingcur = w1
        set1.save()

        #create and import payment and paymentname
        print 'import payment and paymentname'
        pay1 = Payment(code='creditmb')
        pay1.pay_first = True
        pay1.save()
        payname1de = Paymentname(payment=pay1,language=lde,description='Kreditkarte (Moneybookers)')
        payname1de.save()
        payname1en = Paymentname(payment=pay1,language=len,description='credit (Moneybookers)')
        payname1en.save()
        pay2 = Payment(code='debitmb')
        pay2.pay_first = True
        pay2.save()
        payname2de = Paymentname(payment=pay2,language=lde,description='Lastschrift (Moneybookers)')
        payname2de.save()
        payname2en = Paymentname(payment=pay2,language=len,description='debit (Moneybookers)')
        payname2en.save()
        pay3 = Payment(code='bill')
        pay3.pay_first = False
        pay3.save()
        payname3de = Paymentname(payment=pay3,language=lde,description='Rechnung')
        payname3de.save()
        payname3en = Paymentname(payment=pay3,language=len,description='bill')
        payname3en.save()
        pay4 = Payment(code='transfer')
        pay4.pay_first = True
        pay4.save()
        payname4de = Paymentname(payment=pay4,language=lde,description=unicode('Überweisung','latin-1'))
        payname4de.save()
        payname4en = Paymentname(payment=pay4,language=len,description='transfer')
        payname4en.save()


        print 'import taxclass'
        tc1 = TaxClass(percent='19')
        tc1.save()

        print 'import products'
        p1 = Product(orderno=123,price='12.30',taxClass=tc1,isActive=True)
        p1.picture = 'images/handcreme.gif'
        p1.save()
        p1.save()
        
        print 'import optionfields'
        of1 = Optionfield(number=1,name='name')
        of1.save()
        of2 = Optionfield(number=2,name='short desc')
        of2.save()
        of3 = Optionfield(number=3,name='long desc')
        of3.save() 
        of4 = Optionfield(number=4,name='ml')
        of4.save()
        of5 = Optionfield(number=5,name='Anwendung')
        of5.save()
        of6 = Optionfield(number=6,name='Inhaltsstoffe')
        of6.save()
        of8 = Optionfield(number=8,name='meta_description')
        of8.save()
        of9 = Optionfield(number=9,name='meta_keywords')
        of9.save()

        print 'import productoptions'
        po1de1 = Productoption(language=lde,product=p1,optionfield=of1)
        po1de1.optionname = 'Produktname'
        po1de1.description = 'Testprodukt123'
        po1de1.save()
        po1de1 = Productoption(language=lde,product=p1,optionfield=of2)
        po1de1.optionname = 'kurze Beschreibung'
        po1de1.description = 'ein kleine Beschreibung des Testproduktes'
        po1de1.save()
        po1de1 = Productoption(language=lde,product=p1,optionfield=of3)
        po1de1.optionname = 'lange Beschreibung'
        po1de1.description = 'hier kann gaaaanz viel stehen, denn dies ist eine sehr lange beschreibung.'
        po1de1.save()
        po1de1 = Productoption(language=lde,product=p1,optionfield=of4)
        po1de1.optionname = 'Inhalt in ml: '
        po1de1.description = '50'
        po1de1.save()

        print 'import users and customers'
        cust1 = Customer(title=f1,name='Foo Bar',language=lde)
        user1 = User.objects.create_user('*****@*****.**', '*****@*****.**', 'foo')
        user1.save()
        cust1.user = user1
        cust1.save()