Example #1
0
def index():
    n = bottle.request.POST.name

    if n:
        processed_ids = []

        if bottle.request.POST.get('id'):
            scheme = EntityManager().find_one_by_id('PaymentScheme', bottle.request.POST.id)
            existing_options_ids = [str(o._id) for o in EntityManager().find('PaymentOption', objfilter={'scheme_id':str(scheme._id)})]
        else:
            scheme = PaymentScheme()
            existing_options_ids = []

        scheme.name = n

        s = EntityManager().save('PaymentScheme', scheme)

        for opt in bottle.request.POST.getall('option[]'):
            optid = opt.split(':::')[0]
            optname = opt.split(':::')[1]
            optprice = opt.split(':::')[2]

            if optid not in existing_options_ids:
                o = PaymentOption()
                o.scheme_id = str(s._id)
                o.name = optname
                o.price = optprice

                EntityManager().save('PaymentOption', o)

            processed_ids.append(optid)


        #remove any existing payment options that havent been posted (because it means they were removed by the user)
        for id in set(existing_options_ids).difference(set(processed_ids)):
            EntityManager().remove_one('PaymentOption', id)

        return bottle.redirect('/admin/paymentschemes')

    else:
        viewdata = commonViewDataAdmin()
        viewdata['error'] = 'Required data is missing'

        return bottle.template('admin_paymentscheme', vd=viewdata)
Example #2
0
def index():
    n = bottle.request.POST.name
    d = bottle.request.POST.description
    s = bottle.request.POST.scheme

    if n:
        if bottle.request.POST.get('id'):
            cat = EntityManager().find_one_by_id('Category', bottle.request.POST.id)
        else:
            cat = Category()

        cat.name = n
        cat.description = d
        cat.payment_scheme_id = s

        EntityManager().save('Category', cat)

        return bottle.redirect('/admin/categories')

    else:
        viewdata = commonViewDataAdmin()
        viewdata['error'] = 'Required data is missing'

        return bottle.template('admin_category', vd=viewdata)