示例#1
0
    def initialize(self, hinfo=''):
        self.init_condition()

        self.mlink = MLink()
        self.mcat = MCatalog()
        self.mcoupon = MCoupon()
示例#2
0
 def initialize(self, hinfo=''):
     self.init_condition()
     # self.minfo = MInfo(self.city_name)
     self.mcat = MCatalog()
     # self.mcity = MCity()
     self.mcoupon = MCoupon()
示例#3
0
class CouponHandler(base_handler.BaseHandler):
    def initialize(self, hinfo=''):
        self.init_condition()

        self.mlink = MLink()
        self.mcat = MCatalog()
        self.mcoupon = MCoupon()


    def get(self, input=''):
        # Todo: 验证
        if input.startswith('grap'):
            # self.render()
            self.grap(input)
        elif input.startswith('getinfo'):
            self.get_info(input)
        else:
            op, catid = input.split(r'/')
            if op == 'get_list':
                self.get_list()

    def delete_by_id(self, input):
        op, uid = input.split('/')
        self.mlink.delete_by_uid(uid)
        self.list()
        # self.redirect('/link/list')

    def get_info(self, input):
        tel = input.split('/')[1]

        if len(tel) < 11:
            self.write('')
            return
        user_info = self.muser_info.get_by_tel(tel)
        if user_info is None:
            self.write('没找到用户')
            return

        coupon_id = user_info['coupon_uid']
        coupon_info = self.mcoupon.get_by_id(coupon_id)
        if coupon_info is None:
            self.write('没找到该用户的优惠!')
            return

        kwd = {
            'title': coupon_info['title'],
            'address': coupon_info['address'],
            'username': user_info['user_name'],
            'company': coupon_info['company'],
        }
        self.render('coupon/user_info.html', kwd=kwd)

    def grap(self, input):
        self.muser_info.coupon_num_decrease(self.user_name)

        coupon_uid = input.split('/')[1]
        user_info = self.muser_info.get_by_username(self.user_name)
        now = libs.tool.get_timestamp()
        if now - user_info['coupon_timestamp'] < 30 * 24 * 3600:
            self.render_yiyou()
        elif user_info['coupon_num'] == 0:
            self.render_out_num()

        else:
            coupon_info = {
                'coupon_uid': coupon_uid,
                'coupon_timestamp': now,
                'userid': self.user_name,
                'remainnum': user_info['coupon_num'],
            }
            self.muser_info.update_coupon(coupon_info)


    def render_out_num(self):
        self.render('coupon/out_num.html')

    def render_yiyou(self):
        user_info = self.muser_info.get_by_username(self.user_name)

        coupon_id = user_info['coupon_uid']
        coupon_info = self.mcoupon.get_by_id(coupon_id)
        if coupon_info is None:
            self.write('没找到该用户的优惠!')
            return

        kwd = {
            'title': coupon_info['title'],
            'address': coupon_info['address'],
            'username': user_info['user_name'],
            'company': coupon_info['company'],
        }
        self.render('coupon/coupy.html', kwd=kwd)

    def post(self, input=''):
        pass
示例#4
0
class MainHandler(base_handler.BaseHandler):
    def initialize(self, hinfo=''):
        self.init_condition()
        # self.minfo = MInfo(self.city_name)
        self.mcat = MCatalog()
        # self.mcity = MCity()
        self.mcoupon = MCoupon()


    def get(self, input=''):
        if input == '':
            self.main()
        else:
            self.render('404.html')

    def main(self, input=''):
        # dbdata = self.mdb.getall()
        t1 = self.mcat.get_qian2('01')
        s1 = self.format_cat(t1, 1)
        t2 = self.mcat.get_qian2('02')
        s2 = self.format_cat(t2, 2)
        t3 = self.mcat.get_qian2('03')
        s3 = self.format_cat(t3, 3)
        t4 = self.mcat.get_qian2('04')
        s4 = self.format_cat(t4, 4)
        t5 = self.mcat.get_qian2('05')
        s5 = self.format_cat(t5, 5)
        t6 = self.mcat.get_qian2('06')
        s6 = self.format_cat(t6, 6)
        t7 = self.mcat.get_qian2('07')
        s7 = self.format_cat(t7, 7)
        t8 = self.mcat.get_qian2('08')
        s8 = self.format_cat(t8, 8)
        t9 = self.mcat.get_qian2('09')
        s9 = self.format_cat(t9, 9)
        t10 = self.mcat.get_qian2('10')
        s10 = self.format_cat(t10, 10)

        kwd = {
            'cityname': self.mcity.get_cityname_by_id(self.city_name),
            's1': s1,
            's2': s2,
            's3': s3,
            's4': s4,
            's5': s5,
            's6': s6,
            's7': s7,
            's8': s8,
            's9': s9,
            's10': s10,
            'parentid': '0000',
            'parentlist': self.mcat.get_parent_list()
        }

        coupon_infos = self.mcoupon.getall()
        self.render('mainpage/index.html', kwd=kwd,
                    coupon_infos=coupon_infos)

    def format_cat(self, input, sig):
        '''
        根据分类,生成不同的区域
        '''

        headstr = '''<div class="panel panel-info"><div class="panel-heading">
            <span id="title_{sig1}"></span>
            <span><a href='/list/{catid1}'>{catname1}</a></span>
          </div>
            <ul class="list-group">
            '''

        outstr = ''

        for rec_cat in input:
            # 记录的数目
            if rec_cat.catid == rec_cat.parentid:
                # 头
                headstr = headstr.format(sig1=sig, catid1=rec_cat.catid, catname1=rec_cat.catname )
                continue
            recout = self.minfo.get_cat_recs_count(rec_cat.catid)
            if recout > 0:
                recout = str(recout)
            else:
                recout = ''
            tmpstr = '''<li class="list-group-item">
                <a href="/list/{scatid}" title="{scatname}">{scatname}</a>
                <span>{scount}</span></li>
                '''.format(scatid=rec_cat.catid, scatname=rec_cat.catname, scount=recout)

            outstr += tmpstr

        outstr += '''</ul></div>'''
        outstr = headstr + outstr
        return (outstr)