Beispiel #1
0
    def get(self):
        status = self.get_argument("status", None)
        ft = (Order.status >= 0)
        if status:
            ft = ft & (Order.status == status)

        page = int(self.get_argument("page", 1))
        pagesize = self.settings['admin_pagesize']

        oq = Order.select().where(ft)
        total = oq.count()

        orders = []
        for order in oq.paginate(page, pagesize).order_by(
                Order.ordered.desc()).dicts():
            order['orderitems'] = []
            try:
                order['ua'] = UserAddr.get(id=order['uaid'])
            except:
                order['ua'] = UserAddr()

            try:
                order['distr'] = Distribution.get(id=order['distrid'])
            except:
                order['distr'] = Distribution()

            for orderitem in OrderItem.select().where(
                    OrderItem.oid == order['id']).dicts():

                try:
                    orderitem['shop'] = Shop.get(id=orderitem['sid'])
                    if orderitem['said'] > 0:
                        orderitem['shopattr'] = ShopAttr.get(
                            id=orderitem['said'])

                    order['orderitems'].append(orderitem)
                except:
                    orderitem['shop'] = Shop()

            if order['orderitems']:
                orders.append(order)

        self.render('admin/order.html',
                    orders=orders,
                    total=total,
                    page=page,
                    pagesize=pagesize)
Beispiel #2
0
    def post(self):
        pdid = int(self.get_argument('pdid', 0))
        name = self.get_argument('name', None)
        price = float(str(self.get_argument("price", 0.0)))
        content = self.get_argument('content', '')

        distribution = Distribution()
        distribution.pdid = pdid
        distribution.name = name
        distribution.price = price
        distribution.content = content

        try:
            distribution.validate()
            distribution.save()
            self.flash(u"配送方式%s添加成功" % name)
            self.redirect("/admin/distributions")
            return
        except Exception, ex:
            self.flash(str(ex))
Beispiel #3
0
 def load_dist(jd):
     return Distribution(jd["from"], jd["probs"])