Пример #1
0
    def get(self, cid):
        page = int(
            self.get_argument("page", '1')
            if len(self.get_argument("page", '1')) > 0 else '1')
        pagesize = self.settings['admin_pagesize']

        category = Category_Store.get(id=cid)

        ft = ((Product.status > 0) & (Product.category_store == category))
        q = Product.select().where(ft)
        total = q.count()

        if total % pagesize > 0:
            totalpage = total / pagesize + 1
        else:
            totalpage = total / pagesize
        products = q.paginate(page, pagesize)

        self.render('/store/category/category_product.html',
                    products=products,
                    total=total,
                    page=page,
                    pagesize=pagesize,
                    totalpage=totalpage,
                    category=category,
                    active='categorys')
Пример #2
0
 def get(self):
     store_user = self.get_store_user()
     subquery = Product.select(db.fn.COUNT(
         Product.id)).where(Product.category_store == Category_Store.id)
     categorys = Category_Store.select(
         Category_Store, subquery.alias('p_count')).where(
             Category_Store.store == store_user.store.id).order_by(
                 Category_Store.name)
     if categorys.count() == 0:
         categorys = None
     self.render('store/category/category.html',
                 categorys=categorys,
                 active='categorys')
Пример #3
0
    def get(self):
        store_user = self.get_store_user()
        page = int(
            self.get_argument("page", '1')
            if len(self.get_argument("page", '1')) > 0 else '1')
        cid = int(self.get_argument("pcategory", 0))
        pagesize = self.settings['admin_pagesize']
        keyword = self.get_argument("keyword", None)
        defaultstandard = self.get_argument("defaultstandard", None)
        status = int(self.get_argument("status", 1))
        ft = (Product.status > 0) & (Product.store == store_user.store.id)

        if cid > 0:
            ft = ft & (Product.category_store == cid)
        if keyword:
            keyw = '%' + keyword + '%'
            ft = ft & (Product.name % keyw)
        if defaultstandard:
            ft = ft & (Product.defaultstandard % defaultstandard)
        ft = ft & (Product.status == status)
        q = Product.select(Product,
                           Category_Store).join(Category_Store).where(ft)
        total = q.count()
        if total % pagesize > 0:
            totalpage = total / pagesize + 1
        else:
            totalpage = total / pagesize
        products = q.order_by(Product.created.desc()).paginate(
            page, pagesize).aggregate_rows()

        categorys = Category_Store.select().where(
            Category_Store.store == store_user.store.id)
        print categorys.count()
        self.render('store/product/products.html',
                    products=products,
                    total=total,
                    page=page,
                    pagesize=pagesize,
                    totalpage=totalpage,
                    categorys=categorys,
                    cid=cid,
                    active='ps',
                    status=status,
                    keyword=keyword,
                    dp=defaultstandard)
Пример #4
0
 taxes = load_taxes()
 rules = load_specific_price_rules(dt_now)
 prod_cat, cat_prod = load_product_categories()
 attr_name, attr_val = load_attributes()
 #print("loaded specific {} price rules + {} catalog price "
 #      "rules ".format(len(specific_prices), len(rules)))
 for product in Product.select(Product,
                               peewee.fn.min(Image.id_image).alias('image'),
                               ProductLang,
                               CategoryLang.link_rewrite\
                                       .alias('cat_link_rewrite'),
                               Stock.quantity.alias('stock'))\
                .join(ProductLang).join(Image, on=(Product.id_product ==
                                                   Image.id_product),
                                        attr='image')\
                .join(Stock, on=(Stock.id_product ==
                                 Product.id_product))\
                .join(CategoryLang, on=(CategoryLang.id_category ==
                                 Product.id_category_default))\
                .where((ProductLang.id_lang == LANG_ID) &
                       (ProductLang.id_shop ==
                        SHOP_ID) & (Stock.id_shop == SHOP_ID) &
                        (Stock.id_product_attribute == 0) &
                        (CategoryLang.id_lang == LANG_ID))\
                .group_by(Product.id_product).dicts():
     el = Element("PRODUCT")
     product_id = product['id_product']
     i = SubElement(el, "PRODUCT_ID")
     i.text = str("{}-0".format(product_id))
     i = SubElement(el, "TITLE")
     i.text = product['name']
Пример #5
0
    def _render_admin_panel(self, req, cat, page, product):
        req.perm.require('PRODUCT_VIEW')

        name = req.args.get('name')
        description = req.args.get('description', '')
        prefix = req.args.get('prefix') if product is None else product
        owner = req.args.get('owner')
        keys = {'prefix': prefix}
        field_data = {
            'name': name,
            'description': description,
            'owner': owner,
        }

        # Detail view?
        if product:
            prod = Product(self.env, keys)
            if req.method == 'POST':
                if req.args.get('save'):
                    req.perm.require('PRODUCT_MODIFY')
                    prod.update_field_dict(field_data)
                    prod.update()
                    add_notice(req, _('Your changes have been saved.'))
                    req.redirect(req.href.admin(cat, page))
                elif req.args.get('cancel'):
                    req.redirect(req.href.admin(cat, page))

            Chrome(self.env).add_wiki_toolbars(req)
            data = {'view': 'detail', 'product': prod}
        else:
            default = self.config.get('ticket', 'default_product')
            if req.method == 'POST':
                # Add Product
                if req.args.get('add') and req.args.get('prefix'):
                    req.perm.require('PRODUCT_CREATE')
                    try:
                        prod = Product(self.env, keys)
                    except ResourceNotFound:
                        prod = Product(self.env)
                        prod.update_field_dict(keys)
                        prod.update_field_dict(field_data)
                        prod.insert()
                        add_notice(
                            req,
                            _('The product "%(id)s" has been '
                              'added.',
                              id=prefix))
                        req.redirect(req.href.admin(cat, page))
                    else:
                        if prod.prefix is None:
                            raise TracError(_('Invalid product id.'))
                        raise TracError(
                            _("Product %(id)s already exists.", id=prefix))

                # Remove product
                elif req.args.get('remove'):
                    req.perm.require('PRODUCT_DELETE')
                    sel = req.args.get('sel')
                    if not sel:
                        raise TracError(_('No product selected'))
                    if not isinstance(sel, list):
                        sel = [sel]
                    with self.env.db_transaction:
                        for prefix in sel:
                            prod = Product(self.env, {'prefix': prefix})
                            prod.delete()
                    add_notice(
                        req, _("The selected products have been "
                               "removed."))
                    req.redirect(req.href.admin(cat, page))

                # Set default product
                elif req.args.get('apply'):
                    prefix = req.args.get('default')
                    if prefix and prefix != default:
                        self.log.info("Setting default product to %s", prefix)
                        self.config.set('ticket', 'default_product', prefix)
                        _save_config(self.config, req, self.log)
                        req.redirect(req.href.admin(cat, page))

            products = Product.select(self.env)
            data = {'view': 'list', 'products': products, 'default': default}
        if self.config.getbool('ticket', 'restrict_owner'):
            perm = PermissionSystem(self.env)

            def valid_owner(username):
                return perm.get_user_permissions(username).get('TICKET_MODIFY')

            data['owners'] = [
                username
                for username, name, email in self.env.get_known_users()
                if valid_owner(username)
            ]
            data['owners'].insert(0, '')
            data['owners'].sort()
        else:
            data['owners'] = None
        return 'admin_products.html', data