示例#1
0
def create(request, keyname):
    "Backdoor to create a new entity"
    u = auth.get_current_user(request)
    if u.is_admin:
        p = Product(key_name=keyname)
        p.name = "New Product"
        p.description = "The description"        
        p.put()
        return HttpResponseRedirect(reverse('store-edit', args=(p.key(),)))
    return HttpResponseRedirect(reverse('store-index'))
示例#2
0
session = Session()

for site, info in SITES.items():
    mdb = getattr(pymongo.Connection(), site)
    pkname = SITES[site]['pk']
    siteid = site2id(site)
    for d in mdb.product.find():
        model = d.get('model')
        title = d.get('title')
        key = d.get(pkname)

        if model and key:
            print site, model, key

            p = session.query(Product).filter_by(site=site, key=key).first()
            isnew = False
            if not p:
                isnew = True
                p = Product()

            p.model = model.encode('utf-8')
            if title:
                p.title = title.encode('utf-8')
            p.key = key.encode('utf-8')
            p.site = site

            if isnew:
                session.add(p)

            session.commit()
def import_products():
    math_story_junior = Product(title="Maths Story",
        subtitle="Junior",
        icon_url=MEDIA_URL + "image/icon/128x128/cd_blue.png",
        display_rank=3)
    math_story_primary = Product(title="Maths Story",
        subtitle="Primary",
        icon_url=MEDIA_URL + "image/icon/128x128/cd_blue.png",
        display_rank=4)
    math_story_senior = Product(title="Maths Story",
        subtitle="Senior",
        icon_url=MEDIA_URL + "image/icon/128x128/cd_blue.png",
        display_rank=5)
    english_story = Product(title="English Story",
        subtitle="English",
        icon_url=MEDIA_URL + "image/icon/128x128/cd_green.png",
        display_rank=6)
    
    products = [math_story_junior, math_story_primary, math_story_senior, english_story]
    db.put(products)

    baskets = (
        Basket(
            title='All Maths',
            subtitle='Product collection',
            icon_url=MEDIA_URL + 'image/icon/128x128/cd_bunch.png',
            display_rank=0,
            product_keys=[math_story_junior.key(), math_story_primary.key(), math_story_senior.key()]
        ),
        Basket(
            title='All Maths + English',
            subtitle='Product collection',
            icon_url=MEDIA_URL + 'image/icon/128x128/cd_bunch.png',
            display_rank=0,
            product_keys=[math_story_junior.key(), math_story_primary.key(), math_story_senior.key(), english_story.key()]
        ),
    )
    db.put(baskets)

    subscriptions_list = (
        dict(price=Decimal("29.0"),
            general_sales_tax=Decimal("0.95"),
            period_in_months=1,
            ),
        dict(price=Decimal("49.0"),
            general_sales_tax=Decimal("0.95"),
            period_in_months=3,
            #free_period_in_months=1,
            ),
        dict(price=Decimal("149.0"),
            general_sales_tax=Decimal("0.95"),
            period_in_months=12,
            #free_period_in_months=2,
            ),
    )

    # Now that we have keys assigned to the products, 
    # assign to each product a bunch of subscriptions
    # and batch-dump into the datastore.
    subscriptions = []
    for product in products:
        for subscription in subscriptions_list:
            subscription['product'] = product
            subscriptions.append(Subscription(**subscription))
    for basket in baskets:
        for subscription in subscriptions_list:
            subscription['product'] = basket
            subscriptions.append(Subscription(**subscription))
    db.put(subscriptions)