Пример #1
0
    def get(self, sid):
        try:
            shop = Shop.get(id=sid)
        except:
            self.flash("此商品不存在")
            self.redirect("/admin/addshop")
            return

        try:
            category = Category.get(id=shop.cid)
        except:
            pass

        categoryattrs = CategoryAttr.select().where(
            CategoryAttr.cid == shop.cid)

        pics = [
            shoppic.path
            for shoppic in ShopPic.select().where(ShopPic.sid == sid)
        ]
        shop.args = simplejson.loads(shop.args)

        self.render('admin/editshop.html',
                    shop=shop,
                    pics=pics,
                    category=category,
                    categoryattrs=categoryattrs)
Пример #2
0
    def get(self, ename):

        try:
            shop = Shop.get(ename=ename)
            shop.views = shop.views + 1
            shop.save()
            category = Category.get(id=shop.cid)
        except:
            raise HTTPError(404)
            return

        categoryattrs = CategoryAttr.select().where(
            CategoryAttr.cid == shop.cid)
        shopattrs = ShopAttr.select().where(ShopAttr.sid == shop.id)
        if shop.args:
            shop.args = simplejson.loads(shop.args)
        pics = ShopPic.select().where(ShopPic.sid == shop.id)

        recomshops = Shop.select().where((Shop.status == 1)
                                         & (Shop.id != shop.id)).paginate(
                                             1, 5)
        self.render("shop/shop.html",
                    shop=shop,
                    category=category,
                    categoryattrs=categoryattrs,
                    shopattrs=shopattrs,
                    pics=pics,
                    recomshops=recomshops)
Пример #3
0
 def get(self, ename):
     
     try:
         shop = Shop.get(ename = ename)
         shop.views = shop.views + 1
         shop.save()
         category = Category.get(id = shop.cid)
     except:
         raise HTTPError(404)
         return
     
     categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == shop.cid)
     shopattrs = ShopAttr.select().where(ShopAttr.sid == shop.id)
     if shop.args:
         shop.args = simplejson.loads(shop.args)
     pics = ShopPic.select().where(ShopPic.sid == shop.id)
     
     recomshops = Shop.select().where((Shop.status == 1) & (Shop.id != shop.id)).paginate(1, 5)
     self.render("shop/shop.html", shop = shop, category = category, categoryattrs = categoryattrs, shopattrs = shopattrs, pics = pics, recomshops = recomshops)
Пример #4
0
 def get(self, sid):
     try:
         shop = Shop.get(id = sid)
     except:
         self.flash("此商品不存在")
         self.redirect("/admin/addshop")
         return
     
     try:
         category = Category.get(id = shop.cid)
     except:
         pass
     
     categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == shop.cid)
     
     pics = [shoppic.path for shoppic in ShopPic.select().where(ShopPic.sid == sid)]
     shop.args = simplejson.loads(shop.args)
     
     self.render('admin/editshop.html', shop = shop, pics = pics, category = category, categoryattrs = categoryattrs)
Пример #5
0
    def post(self, sid):
        try:
            shop = Shop.get(id=sid)
        except:
            self.flash("此商品不存在")
            self.redirect("/admin/addshop")
            return

        try:
            category = Category.get(id=shop.cid)
        except:
            pass

        categoryattrs = CategoryAttr.select().where(
            CategoryAttr.cid == shop.cid)

        opics = [
            shoppic.path
            for shoppic in ShopPic.select().where(ShopPic.sid == sid)
        ]

        cover = self.get_argument("cover", None)
        pics = self.get_argument("pics", None)
        name = self.get_argument("name", None)
        ename = self.get_argument("ename", None)
        price = self.get_argument("price", 0.0)
        views = int(self.get_argument("views", 0))

        if category.id == 2:
            price = str(float(price))

        level = int(self.get_argument("level", 3))
        resume = self.get_argument("resume", "")
        intro = self.get_argument("intro", "")
        prompt = self.get_argument("prompt", "")

        try:
            shop.name = name
            shop.ename = ename
            shop.level = level
            shop.resume = resume
            shop.intro = intro
            shop.prompt = prompt
            shop.price = price
            shop.views = views

            args = {}
            for categoryattr in categoryattrs:
                caid = str(categoryattr.id)
                args['attr_' + caid] = self.get_argument('attr_' + caid, '')

            shop.args = simplejson.dumps(args)

            if pics:
                pics = pics.split(',')
                pics = [pic.replace('/upload/', '') for pic in pics]
                if not cover:
                    cover = pics[0]

            if not cover:
                cover = ''

            shop.cover = cover.replace('/upload/', '')
            shop.validate()
            shop.save()

            if isinstance(pics, list):
                for pic in pics:
                    if pic not in opics:
                        shoppic = ShopPic()
                        shoppic.sid = shop.id
                        shoppic.path = pic
                        shoppic.save()

                for pic in opics:
                    if pic not in pics:
                        ShopPic.delete().where(ShopPic.path == pic).execute()

            self.flash(u"修改商品%s成功" % name, 'ok')
            self.redirect("/admin/shops")
            return
        except Exception, ex:
            shop.args = simplejson.loads(shop.args)
            self.flash(str(ex))
Пример #6
0
 def post(self, sid):
     try:
         shop = Shop.get(id = sid)
     except:
         self.flash("此商品不存在")
         self.redirect("/admin/addshop")
         return
     
     try:
         category = Category.get(id = shop.cid)
     except:
         pass
     
     categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == shop.cid)
     
     opics = [shoppic.path for shoppic in ShopPic.select().where(ShopPic.sid == sid)]
     
     cover = self.get_argument("cover", None)
     pics = self.get_argument("pics", None)
     name = self.get_argument("name", None)
     ename = self.get_argument("ename", None)
     price = self.get_argument("price", 0.0)
     views = int(self.get_argument("views", 0))
     
     if category.id == 2:
         price = str(float(price))
     
     level = int(self.get_argument("level", 3))
     resume = self.get_argument("resume", "")
     intro = self.get_argument("intro", "")
     prompt = self.get_argument("prompt", "")
     
     try:
         shop.name = name
         shop.ename = ename
         shop.level = level
         shop.resume = resume
         shop.intro = intro
         shop.prompt = prompt
         shop.price = price
         shop.views = views
         
         args = {}
         for categoryattr in categoryattrs:
             caid = str(categoryattr.id)
             args['attr_' + caid] = self.get_argument('attr_' + caid, '')
         
         shop.args = simplejson.dumps(args)
         
         if pics:
             pics = pics.split(',')
             pics = [pic.replace('/upload/', '') for pic in pics]
             if not cover:
                 cover = pics[0]
         
         if not cover:
             cover = ''
         
         shop.cover = cover.replace('/upload/', '')
         shop.validate()
         shop.save()
         
         if isinstance(pics, list):
             for pic in pics:
                 if pic not in opics:
                     shoppic = ShopPic()
                     shoppic.sid = shop.id
                     shoppic.path = pic
                     shoppic.save()
             
             for pic in opics:
                 if pic not in pics:
                     ShopPic.delete().where(ShopPic.path == pic).execute()
         
         self.flash(u"修改商品%s成功" % name, 'ok')
         self.redirect("/admin/shops")
         return
     except Exception, ex:
         shop.args = simplejson.loads(shop.args)
         self.flash(str(ex))
Пример #7
0
 def post(self, cid):
     try:
         category = Category.get(id = cid)
     except:
         self.flash("此分类不存在")
         self.redirect("/admin/addshop")
         return
     
     categoryattrs = CategoryAttr.select().where(CategoryAttr.cid == cid)
     
     cover = self.get_argument("cover", None)
     pics = self.get_argument("pics", None)
     name = self.get_argument("name", None)
     ename = self.get_argument("ename", None)
     price = str(float(str(self.get_argument("price", 0.0))))
     level = int(self.get_argument("level", 3))
     resume = self.get_argument("resume", "")
     intro = self.get_argument("intro", "")
     prompt = self.get_argument("prompt", "")
     views = int(self.get_argument("views", 0))
     
     try:
         shop = Shop()
         shop.name = name
         shop.ename = ename
         shop.cid = cid
         shop.level = level
         shop.resume = resume
         shop.intro = intro
         shop.prompt = prompt
         shop.price = price
         shop.views = views
         
         args = {}
         for categoryattr in categoryattrs:
             caid = str(categoryattr.id)
             args['attr_' + caid] = self.get_argument('attr_' + caid, '')
         
         shop.args = simplejson.dumps(args)
         
         if pics:
             pics = pics.split(',')
             pics = [pic.replace('/upload/', '') for pic in pics]
             
             if not cover:
                 cover = pics[0]
         
         if not cover:
             cover = ''
         
         shop.cover = cover.replace('/upload/', '')
         shop.validate()
         shop.save()
         
         if isinstance(pics, list):
             for pic in pics:
                 shoppic = ShopPic()
                 shoppic.sid = shop.id
                 shoppic.path = pic
                 shoppic.save()
         
         self.flash("添加商品%s成功" % name, 'ok')
         if category.id == 2:
             self.redirect("/admin/shops")
         else:
             self.redirect("/admin/addshopattr/" + str(shop.id))
         return
     except Exception as ex:
         self.flash(str(ex))
     
     self.render('admin/addcshop.html', category = category, categoryattrs = categoryattrs)