示例#1
0
文件: referer.py 项目: XinMa1/work
    def save(self):
        inputParams= self.getInput()

        try:
            Products.create(
                name = inputParams['name'],
                description = self.htmlunquote(inputParams['desc']),
                price1 = inputParams['price1'],
                price2 = inputParams['price2'],
                category = int(inputParams['category']),
                diameter = inputParams['diameter'],
                type = int(inputParams['type']),
            )  
        except Exception, e:
            return self.error(msg = '新增失败: %s' % e, url=self.makeUrl('/admin/products/list'))
示例#2
0
文件: referer.py 项目: XinMa1/work
 def confirm_select_order(self):
     inputs = self.getInput()
     try:
         product = Products.get(Products.id == int(inputs['product']))
         user =Users.get(Users.name == self.isLogin())
         price = inputs['price']
         if inputs.has_key('add'):
             order = Orders.create(
                 owner = user,
                 price = price,
                 description = product.category.name,
             )
         else:
             if not inputs.has_key('selected'):
                 return self.orders_list()
             order = Orders.get(Orders.id == int(inputs['selected']))
         
         details = OrderDetails.create(
             name = product.category.name + "   "+product.diameter,
             product = product,
             count = user,
             price = price,
             ratio = 0.0,
             order = order,
         )
         return web.seeother(self.makeUrl('/wap/edit_price_sheet', {'id': order.id}))
     except Exception, e:
         print 'exc',e
         return self.error(msg='保存订单失败!')
示例#3
0
文件: referer.py 项目: XinMa1/work
    def select_order(self):
        inputs = self.getInput()
        if inputs.has_key('query'):
            return self.orders_list()

        try:
            price, product_id = inputs['product'].split(' ')
            product = Products.get(Products.id == int(product_id))
            order = int(inputs['order'])

            if order > 0:
                details = OrderDetails.create(
                    name = product.category.name +"   "+product.diameter,
                    product = product,
                    count = 1,
                    price = price,
                    ratio = 0.0,
                    order = order,
                )
                return web.seeother(self.makeUrl('/wap/edit_price_sheet', {'id': order}))
            else:
                ordersList = Orders.select().order_by(Orders.id.desc())
                self.privData['ORDERS_LIST'] = ordersList
                self.privData['PRICE'] = price
                self.privData['PRODUCT'] = product
                return self.display('select-order')
        except Exception, e:
            print e
            return self.error(msg='加入订单失败!')
示例#4
0
文件: referer.py 项目: XinMa1/work
    def delete(self):
        inputParams = self.getInput()

        try:
            product = Products.get(Products.id == int(inputParams['id']))
            product.delete_instance()
        except Exception, e:
            return self.success(msg='删除失败: %s' % e, url=self.makeUrl('/admin/products/list'))
示例#5
0
 def _get_trade_info(self, inputs, from_mobile):
     try:
         product = Products.get(Products.id == inputs.get("id",0))   
         total_fee = product.discount     
         count = int(inputs.get("count", 0))
         total_fee = total_fee*count 
     except Exception, e:
         raise e
示例#6
0
文件: referer.py 项目: XinMa1/work
 def product_prices(self):
     inputParams = self.getInput()
     try:
         productsList = Products.select().where(Products.category==int(inputParams['category'])).order_by(Products.id.desc())
         self.privData['PRODUCTS_LIST'] = productsList
         self.privData['ORDER'] = int(inputParams['order']) if inputParams.has_key('order') else -1
         self.privData['CATEGORY'] = Categories.get(Categories.id==int(inputParams['category']))
         return self.display('product-prices')
     except Exception, e:
         print e
         return self.error(msg='获取产品价格列表失败!')
示例#7
0
文件: referer.py 项目: XinMa1/work
    def list(self):
        inputParams = self.getInput()
        page = int(inputParams['page']) if inputParams.has_key('page') else 1
        count = config.COUNT_PER_PAGE
   
        productsList = Products.select().order_by(Products.id.desc())
        pageString = self.getPageStr('/admin/products/list', page, count, productsList.count())
        self.privData['PRODUCTS_LIST'] = productsList.paginate(page, count)
        self.privData['PAGE_STRING'] = pageString

        categoriesList = Categories().select()
        self.privData['CATEGORIES_LIST'] = categoriesList
        return self.display('productsList')
示例#8
0
文件: referer.py 项目: XinMa1/work
    def search_by_category(self):
        inputParams = self.getInput()
        category = int(inputParams['category']) if inputParams.has_key('category') else 0
        page = int(inputParams['page']) if inputParams.has_key('page') else 1
        count = config.COUNT_PER_PAGE
        offset= (page-1)*count if page > 0 else 0

        productsList = Products.select().where(Products.category == category).order_by(Products.id.desc())
        pageString = self.getPageStr('/admin/products/list', page, count, productsList.count())
        self.privData['PRODUCTS_LIST'] = productsList
        self.privData['PAGE_STRING'] = pageString
        categoriesList = Categories().select()
        self.privData['CATEGORIES_LIST'] = categoriesList

        return self.display('productsList')
示例#9
0
文件: referer.py 项目: XinMa1/work
    def update(self):
        inputParams= self.getInput() 
        product = Products.get(Products.id == int(inputParams['id']))

        try:
            product.name = inputParams['name']
            product.description = self.htmlunquote(inputParams['desc'])
            product.category = int(inputParams['category'])
            product.diameter = inputParams['diameter']
            product.price1 = inputParams['price1']
            product.price2 = inputParams['price2']
            product.type = int(inputParams['type'])
            product.save()
        except Exception, e:
            return self.error(msg = '修改失败: %s' % e, url=self.makeUrl('/admin/products/list'))
示例#10
0
def cust_home():
    allproducts = Products.fetch_all()
    if 'email' in session:
        if request.method == 'POST':
            email = session['email']
            product = request.form['productname']
            company = request.form['name']

            qun = request.form['quantity']

            date = request.form['date']

            ch = Orders(email=email,
                        product=product,
                        orderdate=date,
                        customer_id=session['uid'],
                        company=company)
            ch.create_record()
            flash('Order successfully made', 'success')
            return redirect(url_for('cust_home'))
        return render_template('customerorder.html', products=allproducts)
    else:
        flash('Please login', 'danger')
        return redirect(url_for('login'))
示例#11
0
def products_reports():
    if session:
        products = Products.fetch_all()
        return render_template('productsreport.html', products=products)
示例#12
0
def products_all():
    allp = Products.fetch_all()

    return render_template('allproducts.html', allp=allp)
示例#13
0
class Engine:
    """Engine class.
    """
    def __init__(self):
        self.connection_manager = ConnectionManager()
        self.database = Database()
        self.records = Records()
        self.categories = Categories()
        self.products = Products()
        self.substitutes = Substitutes()
        self.abandon = Abandon()
        self.menu = Menu()
        self.register = Register()
        self.research = Research()
        self.tests = Tests()
        self.initialize_database()

    def initialize_database(self):
        """Method that initialize the database. It checks if
        the DB exists and  its tables exists.
        - If it does, the program "datas" are strored into a list and the
        Menu program is started.
        - If it don't, the database and its componnents are created.
        """
        if self.connection_manager.verify(self.database.exists()):
            self.connection_manager.execute_one(self.database.use())
            if self.connection_manager.verify(
                    self.categories.exists()) and \
                    self.connection_manager.verify(
                        self.products.exists()) and \
                    self.connection_manager.verify(
                        self.substitutes.exists()):
                if self.connection_manager.verify(
                        self.categories.select_all()) and\
                        self.connection_manager.verify(
                            self.products.select_all()):
                    self.set_datas_list()
                    self.menu.start(self)
                else:
                    self.reinitialize_database()
            else:
                self.reinitialize_database()
        else:
            self.reinitialize_database()

    def reinitialize_database(self):
        """Method that resets the database (i.e. drop, create and use DB).
        """
        self.connection_manager.execute_one(self.database.delete())
        self.connection_manager.execute_one(self.database.create())
        self.connection_manager.execute_one(self.database.use())
        self.reinitialize_categories()

    def reinitialize_categories(self):
        """Method that resets categories into the database
        (i.e. download data, create table and insert data into table)
        It also resets the categories' list for next step product
        reinitialization.
        """
        self.connection_manager.execute_one(self.categories.create_table())
        self.connection_manager.download(self, self.categories.get_source())
        self.tests.test_categories_consistency(self.categories.source["tags"])
        self.connection_manager.execute_many([
            self.categories.insert_in_table(), self.tests.consistent_categories
        ])
        self.connection_manager.set_categories_list(
            self, self.categories.select_all())
        self.reinitialize_products()

    def reinitialize_products(self):
        """Method that resets products into the database
        (i.e. download data, create table and insert data into table).
        """
        self.connection_manager.execute_one(self.products.create_table())
        for category in self.categories.categories_list:
            self.connection_manager.download(
                self, self.products.get_source(category))
            self.tests.test_products_consistency(
                self.products.source["products"], category)
            self.connection_manager.execute_many(
                [self.products.insert_in_table(), self.tests.unique_products])
        self.reinitialize_substitutes()

    def reinitialize_substitutes(self):
        """Method that resets substitute table into the database
        (i.e. create table) and finally conclude the reinitilaization
        loop by re-settings all datas (i.e. reset all datas into their
        respective list).
        """
        self.connection_manager.execute_one(self.substitutes.create_table())
        self.set_datas_list()
        self.menu.start(self)

    def add_substitute_in_db(self, product_id, substitute_id):
        """Method that add substitute into the database
        (i.e. insert into table) and re-set all datas (i.e. reset
        all datas into their respective list).
        """
        parameters = [
            self.substitutes.insert_in_table(), [product_id, substitute_id]
        ]
        self.connection_manager.execute_one(parameters)
        self.set_datas_list()

    def set_datas_list(self):
        """Method that sets datas into their
        respective list.
        """
        self.connection_manager.set_categories_list(
            self, self.categories.select_all())
        self.connection_manager.set_products_list(self,
                                                  self.products.select_all())
        self.connection_manager.set_substitutes_list(
            self, self.substitutes.select_all())
        self.set_records_list()

    def set_records_list(self):
        """Method that create the records' list.
        """
        self.records.records_list.clear()
        for substitute in self.substitutes.substitutes_list:
            product = [
                product for product in self.products.products_list
                if product.id_product == substitute.product_id
            ]
            substitute = [
                product for product in self.products.products_list
                if product.id_product == substitute.substitute_id
            ]
            category = [
                category for category in self.categories.categories_list
                if category.id_category == product[0].category_id
            ]
            record = Record(category[0], product[0], substitute[0])
            self.records.records_list.append(record)
示例#14
0
 def test_get_product_by_id_success(self):
     product = ProductServiceImpl.get_product_by_id(1)
     self.assertEqual(type(product), type(Products()))
示例#15
0
 def get(self):
     metrics_req_count.labels(method='GET',
                              endpoint='/products',
                              status_code='200').inc()
     return Products.json()
示例#16
0
def get_detail(id):

    docs = Products.objects(id=id)
    return jsonify(docs), 200
示例#17
0
def prodjson():
    c = Products.fetch_all()
    return json.dumps(c, cls=AlchemyEncoder)
示例#18
0
def manual():
    allproducts = Products.fetch_all()

    return render_template('manualorder.html')
示例#19
0
def get_list():
    docs = Products.objects()
    return jsonify(docs), 200