Example #1
0
    def load(self, path=None):
        if path is None or not isinstance(path, basestring):
            info = 'config input path is invalid'
            raise IException(ErrCode.ParamErr, info)
        self.path = path

        tree = None
        try:
            with open(self.path, 'rt') as f:
                tree = ElementTree.parse(f)
        except IOError:
            io_info = 'open %s failed' % path
            raise IException(ErrCode.ThirdErr, io_info)

        if tree is None:
            cinfo = 'parse xml %s failed' % self.path
            raise IException(ErrCode.ConfigErr, cinfo)
        app = tree.find('App')
        self.load_app(app)

        svr = tree.find('WebSvr')
        self.load_websvr(svr)

        db = tree.find('MongoDB')
        self.load_mongo(db)
Example #2
0
    def load(self, path=None):
        if path is None or not isinstance(path, basestring):
            info = 'menu.xml path is invalid'
            raise IException(ErrCode.ParamErr, info)
        self.path = path
        print self.path

        tree = None
        try:
            with open(self.path, 'rt') as f:
                tree = ElementTree.parse(f)
        except IOError:
            io_info = 'open %s failed' % path
            raise IException(ErrCode.ThirdErr, io_info)

        if tree is None:
            cinfo = 'parse xml %s failed' % self.path
            raise IException(ErrCode.ConfigErr, cinfo)

        node_menu = tree.find('Menus')
        self.load_menu(node_menu)

        node_now = tree.find('Now')
        self.load_now(node_now)

        node_time = tree.find('Time')
        self.load_time(node_time)
Example #3
0
 def load_menu(self, node=None):
     if node is None:
         raise IException(ErrCode.ParamErr, 'input invalid')
     menus = node.findall('menu')
     for item in menus:
         ele = {}
         id = item.get('id')
         price = item.get('price')
         title = item.get('title')
         max = item.get('max')
         type = item.get('type')
         purl = item.get('purl')
         des = item.get('des')
         if (id is None or price is None or title is None or 
             max is None or purl is None or des is None):
             raise IException(ErrCode.ParamErr, 'input is invalid')
         ele['id'] = id
         ele['price'] = price
         ele['title'] = title
         ele['max'] = int(max)
         ele['type'] = int(type)
         ele['purl'] = purl
         ele['des'] = des
         if id not in self.menus:
             self.menus[id] = ele
         else:
             raise IException(ErrCode.ParamErr, 'menu repeated')
     print 'load menu'
     print self.menus
Example #4
0
 def load_html(self, apath=None):
     if apath is None:
         raise IException(ErrCode.ParamErr, 'path not exist')
     try:
         with open(apath, 'r') as f:
             html_text = f.read()
     except IOError:
         io_info = 'open %s failed' % apath
         raise IException(ErrCode.ThirdErr, io_info)
     return html_text
Example #5
0
    def load_websvr(self, node=None):
        if node is None:
            dbinfo = 'WebSvr Element is null in %s' % self.path
            raise IException(ErrCode.ConfigErr, dbinfo)

        self.ip = node.get('ip')
        port = node.get('port')
        if self.ip is None or port is None:
            webinfo = 'ip or port is not find in WebSvr'
            raise IException(ErrCode.ConfigErr, webinfo)
        self.port = string.atoi(port)
Example #6
0
 def load_element(self, node):
     if node is None:
         raise IException(ErrCode.ConfigErr, 'un-find elements')
     elements = []
     sub_elements = node.findall('page')
     for item in sub_elements:
         ele_key = item.get('key')
         if ele_key is None:
             raise IException(ErrCode.ConfigErr, 'page lack key')
         if ele_key in self.pages:
             elements.append(self.pages[ele_key])
     return elements
Example #7
0
 def order_add_addr(self, openid=None, order_info=None):
     if openid is None or order_info is None:
         raise IException(ErrCode.ParamErr, 'input null')
     try:
         o_type = order_info['type']
         o_addr = order_info['addr']
         o_phone = order_info['phone']
     except KeyError:
         raise IException(ErrCode.ThirdErr, 'set-find error')
     if o_type == 0 or o_type == 1:
         self.mongo.user.update(openid, 0, o_phone, o_addr)
     return True, (o_addr, o_phone)
Example #8
0
    def __init__(self, conn=None, dbname=None):
        if conn is None:
            raise IException(ErrCode.TypeErr, "conn is null")
        if not isinstance(conn, pymongo.Connection):
            raise IException(ErrCode.TypeErr, "conn type err")
        self.conn = conn
        self.conn.write_concern = {'w': 1, 'wtimeout':1000, 'j': True}

        if dbname == None or not isinstance(dbname, basestring):
            self.db_name = self.DEF_DBNAME
        else:
            self.db_name = dbname 

        self.db = self.conn[self.db_name]
Example #9
0
 def load_time(self, node=None):
     if node is None:
         raise IException(ErrCode.ParamErr, 'input invalid')
     self.time_discount = node.get('discount')
     week = node.findall('week')
     for day in week:
         day_num = day.get('num')
         day_menu = day.get('list').split(',')
         if int(day_num) < 1 or int(day_num) > 7:
             raise IException(ErrCode.ParamErr, 'day value invalid')
         if day_num not in self.week_time:
             raise IException(ErrCode.ParamErr, 'day invalid')
         self.menu_time[day_num] = day_menu
     print 'load time'
     print self.menu_time
Example #10
0
 def add_shopping(self, id=None, order_id=None):
     if (id is None or order_id is None):
         raise IException(ErrCode.ParamErr, 'param is null')
     self.coll.update({'_id': id}, {"$push": {
         'history': order_id
     }},
                      upsert=True)
Example #11
0
    def page_info_add_old(self, page=None, info={}):
        if page is None:
            raise IException(ErrCode.ParamErr, 'page null')
        div_info = None
        if 'lastest_info' in info and len(info['lastest_info']) > 0:
            div_info = div(cl='fyy-info')
            last_info = info['lastest_info']
            if 'addr' in last_info:
                div_info << span(last_info['addr'], cl='fyy-i-addr')
            else:
                div_info << span(cl='fyy-i-addr')

            if 'phone' in last_info:
                div_info << span(last_info['phone'], cl='fyy-i-tel')
            else:
                div_info << span(cl='fyy-i-tel')

            div_info << span(html_const.WX_ADDR_EDIT, cl='fyy-i-edit')
            page << div_info
            return True
        else:
            div_info = div(cl='fyy-info hide')
            div_info << span(cl='fyy-i-addr')
            div_info << span(cl='fyy-i-tel')
            div_info << span(html_const.WX_ADDR_EDIT, cl='fyy-i-edit')
            page << div_info
            return False
Example #12
0
 def add_menu(self, id=None, menu={}):
     if ('id' not in menu or 'price' not in menu or
         'title' not in menu or 'discount' not in menu or
         'max' not in menu or 'type' not in menu or 
         'purl' not in menu):
         raise IException(ErrCode.ParamErr, 'menu lack kv')
     self.coll.update({'_id': id}, {"$push":{'menu':menu, 'menu_id_arr':menu['id']}})
Example #13
0
    def get_collection(self, name=None):
        if name is None or not isinstance(name, basestring):
            raise IException(ErrCode.ParamErr, "input collection name err")

        coll = None
        coll = self.db[name]
        return coll
Example #14
0
 def get_user_info(self, openid=None):
     if openid is None:
         raise IException(ErrCode.ParamErr, 'access is null')
     info = self.mongo.user.find_last_info(openid)
     if info is None:
         self.mongo.user.subscribe(openid)
     return info
Example #15
0
 def add_area(self, area=None, addr=None, pos_x=0.0,
              pos_y=0.0, range=0.0):
     if (area is None or addr is None):
         raise IException(ErrCode.ParamErr, 'coll is null')
     self.coll.insert({'_id': area, 'addr':addr,
                       'position':{'location_x': pos_x, 'location_y': pos_y}, 
                       'range': range})
Example #16
0
 def update_menu(self, id=None, price=None, title=None, 
         type=MenuType.WMRecommend, purl="", max=0, des=''):
     if (id is None or price is None or title is None):
         raise IException(ErrCode.ParamErr, 'input is null')
     self.coll.update({'_id':id}, 
         {"$set": {'price':price, 'title':title, 'type':type, 'purl':purl, 'max':max, 'des':des}}, 
         upsert=True)
Example #17
0
    def generate_page(self, openid=None, info={}, discount={}):
        if openid is None:
            raise IException(ErrCode.ParamErr, 'input err')

        page = PyH(html_const.WM_ORDER_TITLE)
        page << meta(charset='utf-8')
        page << meta(
            name="viewport",
            content=
            "width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
        )
        page.addCSS(html_const.WX_BASE_CSS)
        page.addCSS(html_const.WX_WM_CSS)
        page.addJS(html_const.WX_CORE_JS)

        page << div(cl='hide') << span(
            openid, cl='fyy-openid hide')  #, data-id='openid')
        self.page_discount_add(page, discount)
        display = self.page_info_add(page, info)
        self.page_addr_add(page, display)
        self.page_order_add(page, display)

        self.page_address_add(page)
        page << br()
        page << br()
        page << br()
        page << div(cl='fyy-submit') << span(cl='submit checkmark')
        page << script(html_js.submit_js, type='text/javascript')
        return page.printString()
Example #18
0
 def load_wm(self, node=None):
     if node is None:
         wminfo = 'WM Element is null in %s' % self.path
         raise IException(ErrCode.ConfigErr, wminfo)
     wm_html = node.find('WmHtml')
     if wm_html is None:
         html_info = 'wm html is not found in %s' % self.path
         raise IException(ErrCode.ConfigErr, wm_html)
     self.fpath = wm_html.get('file_path')
     self.pre = wm_html.get('pre')
     self.suf = wm_html.get('suf')
     bnum = int(wm_html.get('begin_num'))
     if (self.fpath is None or self.pre is None or self.suf is None
             or bnum is None):
         load_info = 'lack wm html field in %s' % self.path
         raise IException(ErrCode.ConfigErr, load_info)
     self.bnum = int(bnum)
Example #19
0
 def find_unsub(self, key=None):
     if key is None:
         raise IException(ErrCode.ParamErr, 'input is null')
     unsubs = self.coll.find_one({'_id':key}, {'_id': 0, 'unsubscribe': 1})
     if unsubs is None or 'unsubscribe' not in unsubs:
         return None
     else:
         return unsubs['unsubscribe']
Example #20
0
 def find_order(self, key=None):
     if key is None:
         raise IException(ErrCode.ParamErr, 'input is null')
     orders = self.coll.find_one({'_id':key}, {'_id': 0, 'order': 1})
     if orders is None or 'order' not in orders:
         return []
     else:
         return orders['order']
Example #21
0
 def process_location(self, msg, to_id, from_id):
     latitude = wx_xml.get_wxmsg(msg, 'Latitude')
     longitude = wx_xml.get_wxmsg(msg, 'Longitude')
     precision = wx_xml.get_wxmsg(msg, 'Precision')
     if latitude == None or longitude == None or precision == None:
         linfo = 'lack latitude longitude or precision while location'
         raise IException(ErrCode.APPErr, linfo)
     return wx_xml.MsgType.FORMAT, ''
Example #22
0
    def find_pri(self, user=None):
        if user is None:
            raise IException(ErrCode.ParamErr, 'user is null')

        user_doc = self.coll.find_one({'_id':user}, {'_id':0, 'pri':1})
        if user_doc is None:
            return None
        else:
            return user_doc['pri']
Example #23
0
 def update_weektime(self, id=None, menus=[], menu_ids=[]):
     if id is None:
         raise IException(ErrCode.ParamErr, 'coll is null')
     self.coll.update({'_id': id},
                      {"$set": {
                          'menu': menus,
                          'menu_id_arr': menu_ids
                      }},
                      upsert=True)
Example #24
0
 def page_discount_add(self, page=None, discount={}):
     if (page is None or 'type' not in discount or 'price' not in discount
             or 'title' not in discount):
         raise IException(ErrCode.ParamErr, 'input err')
     div_dc = div(cl='discount hide')
     div_dc.addData(type=discount['type'],
                    price=discount['price'],
                    title=discount['title'])
     page << div_dc
Example #25
0
 def discount(self, id=None):
     if id is None:
         raise IException(ErrCode.ParamErr, 'input openid is invalid')
     dc_r = self.mongo.dc_record.get_record(id)
     print dc_r
     if dc_r is None or dc_r['first'] is False:
         return self.discounts['1']
     else:
         return self.discounts['2']
Example #26
0
    def load(self):
        print self.path
        tree = None
        try:
            with open(self.path, 'rt') as f:
                tree = ElementTree.parse(f)
        except IOError:
            io_info = 'open %s failed' % self.path
            raise IException(ErrCode.ThirdErr, io_info)

        if tree is None:
            cinfo = 'parse xml %s failed' % self.path
            raise IException(ErrCode.ConfigErr, cinfo)

        all_node = tree.find('Pages')
        self.load_pages(all_node)

        view_node = tree.find('PageView')
        self.load_pageviews(view_node)
Example #27
0
 def find_name(self, name=None):
     if name is None:
         raise IException(ErrCode.ParamErr, 'name is null')
     cursor = self.coll.find({'name': name}, {'_id':1, 'pri':1})
     zys = []
     if 0 == cursor.count():
         return None 
     for ele in cursor:
         zys.append(ele)
     return zys
Example #28
0
 def get_order_history_html(self, access_ret=None):
     if access_ret is None:
         raise IException(ErrCode.ParamErr, 'access is null')
     openid = self.parse(access_ret)
     if openid is None:
         return False, None
     arr = self.get_order_info(openid)
     #print '***order_list***:',arr
     hg = html_generator.HtmlGenerator()
     return hg.generate_order_page(arr)
Example #29
0
    def get_order_html(self, access_ret=None):
        if access_ret is None:
            raise IException(ErrCode.ParamErr, 'access is null')
        openid = self.parse(access_ret)
        if openid is None:
            return False, None

        info = self.get_user_info(openid)
        dc_info = self.dm.discount(openid)
        hg = html_generator.HtmlGenerator()
        return hg.generate_page(openid, info, dc_info)
Example #30
0
 def del_admin(self, user=None, name=None):
     if user is None and name is None:
         raise IException(ErrCode.ParamErr, 'input user is null')
     input = {}
     if user is not None:
         input['_id'] = user
     if name is not None:
         input['name'] = name
     if 0 == len(input):
         return
     return self.coll.remove(input)