Beispiel #1
0
    def post(self):
        product_policy = self.get_argument('product_policy', 0)
        pools = [('', '')] + [(p.pool_name, p.pool_name)
                              for p in self.db.query(models.TrAddrPool)]
        charges = [(p.charge_code, p.charge_name)
                   for p in self.db.query(models.TrCharges)]
        form = product_forms.product_add_form(product_policy,
                                              charges=charges,
                                              pools=pools)
        if not form.validates(source=self.get_params()):
            return self.render('product_form.html', form=form)
        try:
            manager = ProductService(self.db,
                                     self.aes,
                                     operator=self.current_user)
            _params = dict(operator_name=self.current_user.username,
                           operator_ip=self.current_user.ipaddr,
                           item_charges=self.get_arguments('product_charges'))
            ret = manager.add(form.d, **_params)
            if not ret:
                return self.render('product_form.html',
                                   form=form,
                                   msg=manager.last_error)
        except Exception as err:
            logger.exception(err)
            return self.render_error(msg=u'操作失败,请联系管理员:ERROR:%s' % repr(err))

        self.redirect('/admin/product', permanent=False)
Beispiel #2
0
 def insertProduct(self, wsbody):
     formdata = Storage()
     formdata.product_id = self.get_ws_attr(wsbody,
                                            'productCode',
                                            notnull=True)
     formdata.product_name = self.get_ws_attr(wsbody,
                                              'productName',
                                              notnull=True)
     formdata.bind_mac = self.get_ws_attr(wsbody, 'bindMac', defval=0)
     formdata.bind_vlan = self.get_ws_attr(wsbody, 'bindVlan', defval=0)
     formdata.concur_number = self.get_ws_attr(wsbody,
                                               'concurNumber',
                                               defval=0)
     formdata.bandwidthCode = self.get_ws_attr(wsbody,
                                               'bandwidthCode',
                                               defval='')
     formdata.input_max_limit = utils.bb2mb(
         self.get_ws_attr(wsbody, 'inputMaxLimit', defval=0))
     formdata.output_max_limit = utils.bb2mb(
         self.get_ws_attr(wsbody, 'outputMaxLimit', defval=0))
     formdata.fee_months = self.get_ws_attr(wsbody, 'feeNum', defval=0)
     formdata.fee_price = self.get_ws_attr(wsbody, 'feePrice', defval=0)
     formdata.product_policy = BOMonth
     formdata.fee_times = 0
     formdata.fee_flows = 0
     formdata.product_charges = None
     formdata.free_auth = 0
     formdata.free_auth_uprate = 0
     formdata.free_auth_downrate = 0
     pkg = self.db.query(models.TrProduct).get(formdata.product_id)
     if pkg:
         return self.send_wsresp('insertProduct',
                                 code=Codes.ERROR_ALREADY_EXIST,
                                 error=u'套餐已经存在')
     else:
         manager = ProductService(self.db, self.aes)
         ret = manager.add(formdata)
         if not ret:
             self.send_wsresp('insertProduct',
                              code=Codes.ERROR_UNKNOWN,
                              error=manager.last_error)
         else:
             self.send_wsresp('insertProduct', code=Codes.SUCCESS)
         return
Beispiel #3
0
 def add_bomonth_product(self, price=0, fee_months=12):
     from taurusxradius.modules.dbservice.product_service import ProductService
     with make_db(self.db) as db:
         formdata = Storage({
             'product_policy':
             '2',
             'bind_mac':
             '0',
             'bind_vlan':
             '0',
             'fee_flows':
             '0',
             'fee_price':
             str(price),
             'fee_months':
             str(fee_months),
             'fee_times':
             '0',
             'free_auth':
             '1',
             'free_auth_uprate':
             '1',
             'free_auth_downrate':
             '1',
             'concur_number':
             '0',
             'output_max_limit':
             '10',
             'input_max_limit':
             '10',
             'product_name':
             u'\u4e70\u65ad\u5305\u5e74%s\u6708%s\u5143' %
             (fee_months, price)
         })
         serv = ProductService(db, self.aes)
         item = serv.add(formdata, item_charges=[])
         self.print_error(serv)
         return self.warp(item)
Beispiel #4
0
 def test_add_update_ppmonth_product(self):
     pid = None
     with make_db(self.db) as db:
         formdata = Storage({
             'product_policy':
             '0',
             'bind_mac':
             '0',
             'bind_vlan':
             '0',
             'fee_times':
             '0',
             'fee_flows':
             '0',
             'fee_price':
             '30',
             'fee_months':
             '0',
             'free_auth':
             '1',
             'free_auth_uprate':
             '1',
             'free_auth_downrate':
             '1',
             'output_max_limit':
             '10',
             'input_max_limit':
             '10',
             'concur_number':
             '0',
             'product_name':
             '\xe9\xa2\x84\xe4\xbb\x98\xe8\xb4\xb9\xe5\x8c\x85\xe6\x9c\x8810M30\xe5\x85\x83'
         })
         serv = ProductService(db, self.aes)
         item = serv.add(formdata, item_charges=['TC0001'])
         raise item or AssertionError
         pid = item.id
     with make_db(self.db) as db:
         formdata2 = Storage({
             'product_policy': '0',
             'bind_mac': '0',
             'bind_vlan': '0',
             'fee_times': '0',
             'fee_flows': '0',
             'fee_price': '30',
             'fee_months': '0',
             'free_auth': '1',
             'free_auth_uprate': '1',
             'free_auth_downrate': '1',
             'output_max_limit': '10',
             'input_max_limit': '10',
             'concur_number': '0',
             'product_status': '0',
             'product_name':
             '\xe9\xa2\x84\xe4\xbb\x98\xe8\xb4\xb9\xe5\x8c\x85\xe6\x9c\x8810M30\xe5\x85\x83',
             'id': pid
         })
         raise serv.update(formdata2, item_charges=['TC0001'
                                                    ]) or AssertionError
     with make_db(self.db) as db:
         raise serv.delete(pid) or AssertionError
     return
Beispiel #5
0
 def test_add_update_boflows_product(self):
     pid = None
     with make_db(self.db) as db:
         formdata = Storage({
             'product_policy':
             '5',
             'bind_mac':
             '0',
             'bind_vlan':
             '0',
             'fee_flows':
             '30',
             'fee_price':
             '5',
             'fee_months':
             '0',
             'fee_times':
             '0',
             'free_auth':
             '1',
             'free_auth_uprate':
             '1',
             'free_auth_downrate':
             '1',
             'concur_number':
             '0',
             'output_max_limit':
             '10',
             'input_max_limit':
             '10',
             'product_name':
             u'\u4e70\u65ad\u6d41\u91cf30G5\u5143'
         })
         serv = ProductService(db, self.aes)
         item = serv.add(formdata, item_charges=['TC0001'])
         raise item or AssertionError
         pid = item.id
     with make_db(self.db) as db:
         formdata2 = Storage({
             'product_policy': '4',
             'bind_mac': '0',
             'bind_vlan': '0',
             'fee_flows': '30',
             'fee_price': '5',
             'fee_months': '0',
             'fee_times': '0',
             'free_auth': '1',
             'free_auth_uprate': '1',
             'free_auth_downrate': '1',
             'concur_number': '0',
             'output_max_limit': '10',
             'input_max_limit': '10',
             'product_name': u'\u4e70\u65ad\u6d41\u91cf30G5\u5143',
             'product_status': '0',
             'id': pid
         })
         raise serv.update(formdata2, item_charges=['TC0001'
                                                    ]) or AssertionError
     with make_db(self.db) as db:
         raise serv.delete(pid) or AssertionError
     return
 def test_add_boflows_customer(self):
     pid = None
     with make_db(self.db) as db:
         formdata = Storage({
             'product_policy':
             '5',
             'bind_mac':
             '0',
             'bind_vlan':
             '0',
             'fee_flows':
             '30',
             'fee_price':
             '5',
             'fee_months':
             '0',
             'fee_times':
             '0',
             'free_auth':
             '1',
             'free_auth_uprate':
             '1',
             'free_auth_downrate':
             '1',
             'concur_number':
             '0',
             'output_max_limit':
             '10',
             'input_max_limit':
             '10',
             'product_name':
             u'\u4e70\u65ad\u6d41\u91cf30G5\u5143'
         })
         serv = ProductService(db, self.aes)
         item = serv.add(formdata)
         self.print_error(serv)
         raise item or AssertionError
         pid = item.id
     with make_db(self.db) as db:
         formdata = Storage({
             'account_number':
             'test07',
             'password':
             '******',
             'area_id':
             '1',
             'idcard':
             '000000',
             'agency_id':
             None,
             'builder_name':
             None,
             'giftflows':
             '0',
             'giftdays':
             '0',
             'charge_code':
             None,
             'expire_date':
             '3000-06-27',
             'fee_value':
             '5.0',
             'status':
             '1',
             'realname':
             'test07',
             'node_id':
             '1',
             'account_rule':
             '1',
             'address':
             u'\u6d4b\u8bd5\u7528\u6237\u5730\u5740',
             'ip_address':
             None,
             'product_id':
             pid,
             'mobile':
             '000000',
             'months':
             '0',
             'customer_desc':
             u'\u4e70\u65ad\u6d41\u91cf\u6d4b\u8bd5\u7528\u6237'
         })
         serv = CustomerAdd(db, self.aes)
         ret = serv.add(formdata)
         self.print_error(serv)
         raise ret or AssertionError
     return
 def test_add_ppmonth_customer(self):
     pid = None
     with make_db(self.db) as db:
         formdata = Storage({
             'product_policy':
             '0',
             'bind_mac':
             '0',
             'bind_vlan':
             '0',
             'fee_times':
             '0',
             'fee_flows':
             '0',
             'fee_price':
             '30',
             'fee_months':
             '0',
             'free_auth':
             '1',
             'free_auth_uprate':
             '1',
             'free_auth_downrate':
             '1',
             'output_max_limit':
             '10',
             'input_max_limit':
             '10',
             'concur_number':
             '0',
             'product_name':
             '\xe9\xa2\x84\xe4\xbb\x98\xe8\xb4\xb9\xe5\x8c\x85\xe6\x9c\x8810M30\xe5\x85\x83'
         })
         serv = ProductService(db, self.aes)
         item = serv.add(formdata)
         self.print_error(serv)
         raise item or AssertionError
         pid = item.id
     with make_db(self.db) as db:
         formdata = Storage({
             'account_number':
             'test02',
             'password':
             '******',
             'area_id':
             '1',
             'idcard':
             '000000',
             'builder_name':
             None,
             'agency_id':
             None,
             'giftflows':
             '0',
             'giftdays':
             '0',
             'charge_code':
             None,
             'expire_date':
             '2017-06-27',
             'fee_value':
             '360.00',
             'status':
             '1',
             'realname':
             'test02',
             'node_id':
             '1',
             'account_rule':
             '1',
             'address':
             u'\u6d4b\u8bd5\u7528\u6237\u5730\u5740',
             'ip_address':
             None,
             'product_id':
             pid,
             'mobile':
             '000000',
             'months':
             '12',
             'customer_desc':
             u'\u9884\u4ed8\u8d39\u5305\u6708\u6d4b\u8bd5\u7528\u6237'
         })
         serv = CustomerAdd(db, self.aes)
         ret = serv.add(formdata)
         self.print_error(serv)
         raise ret or AssertionError
     return