Example #1
0
class AdminOperateHandler(tornado.web.RequestHandler):
    def initialize(self, hinfo=''):
        self.cityid = self.get_secure_cookie('cityid').decode('utf-8')
        self.m_user = MUserInfo()
        self.minfo = MInfo(self.cityid)

    def get(self, input=''):
        # self.write(r'<h3>' + input + r'</h3>')
        if len(input) > 0:
            ip_arr = input.split(r'/')
            # self.render()
            if ip_arr[0] == 'vip':
                self.set_vip(ip_arr[1])
            elif ip_arr[0] == 'renzheng':
                self.set_credit(ip_arr[1])
            elif ip_arr[0] == 'valid':
                self.set_info_valid(ip_arr[1])
        else:
            self.render('404.html')

    def set_vip(self, def_uid):
        # print(def_uid)
        self.m_user.set_vip(def_uid)
        self.redirect('/admin/page_members')

    def set_credit(self, def_uid):
        # print(def_uid)
        self.m_user.set_credit(def_uid)
        self.redirect('/admin/page_members')

    def set_info_valid(self, info_uid):
        self.minfo.set_valid(info_uid)
        self.redirect('/admin/list/check')
        pass
Example #2
0
 def initialize(self, hinfo=''):
     self.init_condition()
     self.minfo = MInfo(self.city_name)
     self.mcat = MCatalog()
     self.mlink = MLink()
     self.mcity = MCity()
     self.muser_info = MUser(self.user_name)
Example #3
0
    def initialize(self, hinfo=''):

        self.init_condition()


        self.minfo = MInfo(self.city_name)
        self.mcat = MCatalog()
        self.mcity = MCity()
Example #4
0
 def initialize(self, hinfo=''):
     userid = self.get_secure_cookie('admin_user')
     if userid is None:
         self.userid = ''
     else:
         self.userid = userid.decode('utf-8')
     cityid = self.get_secure_cookie('cityid')
     if cityid is None:
         self.cityid = 'changchun'
         self.set_secure_cookie('cityid', 'changchun')
     else:
         self.cityid = cityid.decode('utf-8')
     self.madmin = MAdminUser()
     self.mcat = MCatalog()
     self.mcity = MCity()
     self.minfo = MInfo(self.cityid)
Example #5
0
class ListHandler(base_handler.BaseHandler):
    def initialize(self, hinfo=''):
        self.init_condition()
        self.minfo = MInfo(self.city_name)
        self.mcat = MCatalog()
        self.mlink = MLink(self.city_name)
        self.mcity = MCity()

    def get(self, input=''):
        if len(input) == 4:
            self.list(input)
        # elif input == 'search':
        #     keywords = self.request.arguments['keywords'][0]
        #     self.search(keywords)
        elif len(input) > 4:
            # 如果带条件传回
            self.echo_html(input)
        else:
            self.render('404.html')

    # 2014-12-20
    #   def post(self, input=''):
    #       pass
    #       # print('*' * 20)
    #       # if len(input) > 0:
    #     #     self.add()

    def echo_html(self, input):
        input_arr = input.split('/')

        pa_arr = input.split('/')
        sig = pa_arr[0]

        num = (len(pa_arr) - 2) // 2

        # 包装成条件字典# condition 为用于查询的条件. 字典

        if sig.endswith('00'):
            condition = {'parentid': sig}
        else:
            condition = {'catid': sig}
        fenye_num = 1
        for ii in range(num):
            ckey = pa_arr[ii * 2 + 2]

            tval = pa_arr[ii * 2 + 3]
            if tval == '0':
                continue
            if ckey == 'fenye':
                # 分页参数。单独处理。
                fenye_num = int(tval)
                continue
            if ckey == 'fabiaoshijian':
                if tval == '1':
                    cval = 1
                elif tval == '2':
                    cval = 2
            else:
                cval = tval
            ckey = 'extra_' + ckey
            condition[ckey] = cval

        # 有效的条件
        condition['def_banned'] = 0
        condition['def_valid'] = 1

        print(condition)

        if input_arr[1] == 'con':
            infos = self.minfo.get_list_fenye(condition, fenye_num)
            for x in infos:
                for y in x:
                    print(y)
            self.echo_html_list_str(infos)
        elif input_arr[1] == 'num':
            allinfos = self.minfo.get_list(condition)
            self.echo_html_fenye_str(len(allinfos), fenye_num)

    def echo_html_list_str(self, infos):
        '''
        生成 list 后的 HTML 格式的字符串
        '''
        outstr = ''

        for info in infos:

            zhiding_str = ''
            tuiguang_str = ''
            imgname = 'fixed/zhanwei.png'
            if len(info['mymps_img']) > 0:
                imgname = info['mymps_img'][0]
            # print(imgname)
            if info['def_zhiding'] == 1:
                zhiding_str = '<span class="red">(已置顶)</span>'
            if info['def_tuiguang'] == 1:
                tuiguang_str = '<span class="red">(已推广)</span>'

            list_type = info['catid'][0]

            html_top_str = ''
            if 'extra_fangjia' in info:
                html_top_str = '''
                房价: <span class="red">{0}</span>
                '''.format(info['extra_fangjia'][0])
            html_bottom_str = ''

            kwd = {
                'imgname': imgname,
                'zhiding': zhiding_str,
                'tuiguang': tuiguang_str,
                'html_right_top': html_top_str,
                'html_right_bottom': html_bottom_str,
            }

            outstr += self.render_string('infolist/infolist_{0}.html'.format(list_type),
                                         kwd=kwd, post_info=info,
                                         widget_info = kwd).decode('utf-8')

        self.write(outstr)

    def echo_html_fenye_str(self, rec_num, fenye_num):
        '''
        生成分页的导航
        '''
        pagination_num = int(math.ceil(rec_num * 1.0 / c.info_list_per_page))

        if pagination_num == 1 or pagination_num == 0:
            # 只有一页时,不出现。
            fenye_str = ''
        elif pagination_num > 1:
            fenye_str = '<ul class="iga_pagination">'
            for num in range(1, pagination_num + 1):
                if num == fenye_num:
                    checkstr = 'active'
                else:
                    checkstr = 'disable'
                tmp_str_df = '''
                  <li class='{0}' name='fenye' onclick='change(this);'
                  value='{1}'><a>{1}</a></li>'''.format(checkstr, num)
                fenye_str += tmp_str_df
            fenye_str += '</ul>'

        else:
            pass
        self.write(fenye_str)


    def list(self, input):
        '''
        页面打开后的渲染方法,不包含 list 的查询结果与分页导航
        '''
        sig = input

        # 面包屑导航
        bread_crumb_nav_str = '当前位置:<a href="/">数据中心</a>'
        bread_crumb_nav_str += ' > '
        if input.endswith('00'):
            # 在打开一级类的情况下
            parent_id = input
            parent_catname = self.mcat.get_by_id(parent_id).catname
            condition = {'parentid': parent_id}
            catname = self.mcat.get_by_id(sig).catname
            bread_crumb_nav_str += '<a href="/list/{0}">{1}</a>'.format(sig, catname)

        else:
            # 在list 二级类的情况下
            condition = {'catid': sig}
            parent_id = sig[:2] + '00'
            parent_catname = self.mcat.get_by_id(parent_id).catname
            catname = self.mcat.get_by_id(sig).catname
            bread_crumb_nav_str += '<a href="/list/{0}">{1}</a>'.format(parent_id, parent_catname)
            bread_crumb_nav_str += ' > '
            bread_crumb_nav_str += '<a href="/list/{0}">{1}</a>'.format(sig, catname)
        # 右侧图片广告
        link_recs = self.mlink.query_links_by_parentid(parent_id)
        out_link_str = libs.core.get_out_link_str(link_recs, self.static_url)
        # 有效的条件
        condition['def_banned'] = 0
        condition['def_valid'] = 1
        condition['def_refresh'] = 1

        num = self.minfo.get_num_condition(condition)
        # 左侧二级菜单
        rnage2_list = self.mcat.get_range2_without_parent(parent_id)
        sub_menu_str = libs.core.get_sub_menu_str(rnage2_list, parent_catname)

        kwd = {
            'catid': input,
            'cityname': self.mcity.get_cityname_by_id(self.city_name),
            'daohangstr': bread_crumb_nav_str,
            'linkstr': out_link_str,
            'parentid': parent_id,
            'parentlist': self.mcat.get_parent_list(),
            'condition': condition,
            'sub_menu': sub_menu_str,
            'catname': catname,
            'rec_num': num,
        }
        self.render('list/list_{0}.html'.format(input), kwd=kwd, widget_info = kwd,)
Example #6
0
class AdminHandler(tornado.web.RequestHandler):
    def initialize(self, hinfo=''):
        userid = self.get_secure_cookie('admin_user')
        if userid is None:
            self.userid = ''
        else:
            self.userid = userid.decode('utf-8')
        cityid = self.get_secure_cookie('cityid')
        if cityid is None:
            self.cityid = 'changchun'
            self.set_secure_cookie('cityid', 'changchun')
        else:
            self.cityid = cityid.decode('utf-8')
        self.madmin = MAdminUser()
        self.mcat = MCatalog()
        self.mcity = MCity()
        self.minfo = MInfo(self.cityid)


    def post(self, input=''):
        if input == '':
            # ip_arr = input.split(r'/')
            infos = self.request.arguments
            for x in infos:
                # self.write(str(x))
                pass
        elif input == 'user_set':
            self.set_vip()
        self.set_secure_cookie(config.cookie_str['admin_user'], 'admin')
        self.render('tpl_admin/main.html')

    def set_vip(self):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)
        if post_data['isvip'][0] == '1':
            self.madmin.set_vip(post_data['user_name'][0], post_data['cats'])
        else:
            self.madmin.cancel_vip(post_data['user_name'][0])

        self.redirect('/admin/userinfo/{0}'.format(post_data['user_name'][0]))

    def get(self, input=''):
        # self.write(r'<h3>' + input + r'</h3>')
        url_arr = input.split('/')
        if input == '':
            self.view_main()
        elif input == 'left':
            pass
        elif input == 'list_renzheng':
            self.list_renzheng()
        elif input == 'page_members':
            self.page_published()
        elif input.startswith('p_'):
            self.open_p(input)
        elif url_arr[0] == 'user':
            self.get_user_frame(url_arr[1])
        elif url_arr[0] == 'userinfo':
            self.get_user(url_arr[1])
        elif input.startswith('list/'):
            self.listinfo(input)
        else:
            pass
    def open_p(self, input):
        self.render('tpl_admin/%s.html' % (input))
    def get_user_frame(self, user_name):
        self.render('tpl_admin/p_user_toset_frame.html', user_name=user_name)
    def get_user(self, user_name):
        uinfo = self.madmin.get_by_username(user_name)
        clas = self.mcat.get_parent_list()
        vip_cat = uinfo.vip_cat
        if uinfo:
            self.render('tpl_admin/p_user_toset.html', uinfo=uinfo,  cats = clas, vip_cat=vip_cat)
        else:
            self.open_p('p_set_vip')

    def listinfo(self, input):
        # opter, cityid, sig = input.split('/')

        opter, switch = input.split('/')

        # cityid = input.split('_')[1]

        if switch == 'check':
            condition = {'def_valid': 0, 'def_banned': 0}
        # elif switch == 'tuiguang':
        # condition = {"catid": {"$in": self.vip_cat}, 'userid': self.userid}
        # elif switch == 'notg':
        #     condition = {"catid": {"$nin": self.vip_cat}, 'userid': self.userid}
        user_published_infos = self.minfo.get_by_condition(condition)
        kwd = {
            'cityid': self.cityid,
            'cityname': self.mcity.get_cityname_by_id(self.cityid),
            'action': switch
        }
        self.render('tpl_admin/p_listcity.html', user_published_infos=user_published_infos, kwd=kwd)

    def get_top_page(self):
        m_user = self.muser.get_by_username()
        self.render('tpl_admin/top.html', username=self.userid, userinfo=m_user)

    def page_published(self):
        if self.userid != '':
            user_recs = self.muser.get_all()
            out_str = '<ul>'
            for user_rec in user_recs:
                tmp_str = '<li>{0}</li>'.format(user_rec.user_name)
                out_str += tmp_str
            out_str += '</ul'
            return out_str

        else:
            self.render('tpl_admin/index.html')


    def list_renzheng(self):
        if self.userid != '':
            user_recs = self.madmin.get_uncredit()
            for u in user_recs:
                print (u.user_name)
            self.render('tpl_admin/p_members.html',
                        wuser_recs = user_recs)

        else:
            self.render('tpl_admin/index.html')

    def view_main(self):
        if self.userid == '':
            self.render('tpl_admin/index.html')
        else:
            self.render('tpl_admin/main.html')
Example #7
0
 def initialize(self, hinfo=''):
     self.cityid = self.get_secure_cookie('cityid').decode('utf-8')
     self.m_user = MUserInfo()
     self.minfo = MInfo(self.cityid)
Example #8
0
class SearchHandler(base_handler.BaseHandler):
    def initialize(self, hinfo=''):
        self.init_condition()
        self.minfo = MInfo(self.city_name)
        self.mcat = MCatalog()
        self.mlink = MLink()
        self.mcity = MCity()
        self.muser_info = MUser(self.user_name)

    def get(self, input=''):
        kw = (tornado.escape.url_unescape(self.get_cookie('search_keyword')))
        if input == '':
            # 注释掉的为使用数据库存储
            # self.search(self.muser.get_last_keyword())
            self.search(kw)
        elif len(input) > 0:
            # 注释掉的为使用数据库存储
            # self.search(self.muser.get_last_keyword(), int(input))
            self.search(kw, int(input))
        else:
            self.write('Hello')

    # Todo: 可以使用Tornado处理
    def post(self, input=''):
        if self.user_name == '':
            self.render('search_login.html')
            return
        if input == '':
            keywords = self.get_argument('searchheader')
            '''
            其实这是因为文字编码而造成的,汉字是两个编码,所以才会搞出这么个乱码出来!
            其实解决的方法很简单:只要在写入Cookie时,先将其用Url编码,然后再写入,当我们读取时再解码就OK了,
            '''
            self.set_cookie('search_keyword', tornado.escape.url_escape(keywords))
            # 下面是使用数据库存储
            # self.muser.set_last_keyword(keywords)
            self.search(keywords)

    def search(self, kw, current=1):
        # Todo: 限定在当前分类
        bread_crumb_nav_str = '<li>当前位置: </li><li><a href="/">吉合营</a></li>'
        condition = {'title': {"$regex": kw}}

        condition['def_banned'] = 0
        condition['def_valid'] = 1
        condition['def_refresh'] = 1
        record_num = self.minfo.get_by_condition(condition).count()
        page_num = int(record_num / c.info_list_per_page) + 1
        cat_slug = 'search'
        kwd = {
            'imgname': 'fixed/zhanwei.png',
            'catid': input,
            'cityname': self.mcity.get_cityname_by_id(self.city_name),
            'daohangstr': bread_crumb_nav_str,
            'linkstr': '',
            'parentid': '0000',
            'parentlist': '',
            'condition': condition,
            'sub_menu': '',
            'catname': '',
            'rec_num': record_num,
            'pager': libs.tool.gen_pager(cat_slug, page_num, current)
        }
        dbdata = self.minfo.get_list_fenye(condition, current)
        self.render('search/list_res.html', kwd=kwd, info_list=dbdata)
        # def echo_html(self, input):
        # kw = self.muser.get_last_keyword()
        # condition = {'title': {"$regex": kw}}
        # tmp = input.split('/')
        #
        # pa_arr = input.split('/')
        #     sig = pa_arr[0]
        #
        #     num = (len(pa_arr) - 2) // 2
        #
        #     # 包装成条件字典
        #     # condition 为用于查询的条件. 字典
        #
        #     fenye_num = 1
        #     for ii in range(num):
        #         ckey = pa_arr[ii * 2 + 2]
        #         tval = pa_arr[ii * 2 + 3]
        #         if tval == '0':
        #             continue
        #         if ckey == 'fenye':
        #             # 分页参数。单独处理。
        #             fenye_num = int(tval)
        #             continue
        #         if ckey == 'fabiaoshijian':
        #             if tval == '1':
        #                 cval = 1
        #             elif tval == '2':
        #                 cval = 2
        #         else:
        #             cval = tval
        #         ckey = 'extra_' + ckey
        #         condition[ckey] = cval
        #
        #     # 有效的条件
        #     condition['def_banned'] = 0
        #     condition['def_valid'] = 1
        #     infos = self.minfo.get_list_fenye(condition, fenye_num)
        #
        #     if tmp[1] == 'con':
        #         self.echo_html_list_str(infos)
        #     elif tmp[1] == 'num':
        #         allinfos = self.minfo.get_list(condition)
        #         self.echo_html_fenye_str(len(allinfos), fenye_num)

        # def echo_html_fenye_str(self, rec_num, fenye_num):
        #     '''
        #     生成分页的导航
        #     '''
        #     # 页面的数目
        #     input = int(math.ceil(rec_num * 1.0 / c.info_list_per_page))
        #
        #     if input == 1 or input == 0:
        #         # 只有一页时,不出现。
        #         fenye_str = ''
        #     elif input > 1:
        #         fenye_str = '<ul class="pagination">'
        #         for num in range(1, input + 1):
        #             if num == fenye_num:
        #                 checkstr = 'active'
        #             else:
        #                 checkstr = 'disable'
        #             tmp_str_df = '''
        #               <li class='{0}' name='fenye' onclick='change(this);'
        #               value='{1}'><a>{1}</a></li>'''.format(checkstr, num)
        #             fenye_str += tmp_str_df
        #         fenye_str += '</ul>'
        #
        #     else:
        #         return
        #     self.write(fenye_str)

        # def echo_html_list_str(self, infos):
        #     '''
        #     生成 list 后的 HTML 格式的字符串
        #     '''
        #     outstr = ''
        #     # uu = InfoList
        #     for info in infos:
        #         # outstr  += uu.renderit(info=info)
        #
        #         zhiding_str = ''
        #         tuiguang_str = ''
        #         imgname = 'fixed/zhanwei.png'
        #         if len(info['mymps_img']) > 0:
        #             imgname = info['mymps_img'][0]
        #         # print(imgname)
        #         if info['def_zhiding'] == 1:
        #             zhiding_str = '<span class="red">(已置顶)</span>'
        #         if info['def_tuiguang'] == 1:
        #             tuiguang_str = '<span class="red">(已推广)</span>'
        #
        #         list_type = info['catid'][0]
        #
        #         html_top_str = ''
        #         if 'extra_fangjia' in info:
        #             html_top_str = '''
        #             房价: <span class="red">{0}</span>
        #             '''.format(info['extra_fangjia'][0])
        #         html_bottom_str = ''
        #
        #         kwd = {
        #             'imgname': imgname,
        #             'zhiding': zhiding_str,
        #             'tuiguan': tuiguang_str,
        #             'html_right_top': html_top_str,
        #             'html_right_bottom': html_bottom_str,
        #         }
        #         outstr += self.render_string('infolist/infolist_{0}.html'.format(list_type),
        #                                      kwd=kwd, post_info=info).decode('utf-8')
        #     self.write(outstr)

        # def get_out_str(self, infos):
        #     '''
        #     更好的方式,是放到模板中 ?
        #     '''
        #     outstr = ''
        #     switcher = False
        #     for info in infos:
        #         style_str = ''
        #         zhiding_str = ''
        #         tuiguang_str = ''
        #         if switcher == True:
        #             switcher = False
        #             class_str = 'hover_odd'
        #         else:
        #             switcher = True
        #             class_str = 'hover_even'
        #         imgname = ''
        #         if len(info['mymps_img']) > 0:
        #             imgname = info['mymps_img'][0]
        #         if info['def_zhiding'] == 1:
        #             zhiding_str = '<span style="color:red;">(已置顶)</span>'
        #         if info['def_tuiguang'] == 1:
        #             tuiguang_str = '<span style="color:red;">(已推广)</span>'
        #         title_str = ' '.join([info['title'][0], zhiding_str, tuiguang_str])
        #
        #         outstr += '''<div class="{str_class}" >
        #         <span class="ltitlevalue">
        #         <a href="/view/{str_infoid}" target="_blank" style=" ">
        #         <font size=2 >{str_title}</font></a>
        #         <font class="area"></font> <span class="ltitle">
        #         <font size=2 style="font-family:Microsoft YaHei">
        #         <li size=3>
        #         <nobr> {str_content} </nobr>
        #         </li>
        #         <br/><br/>
        #         发布时间: {str_time}
        #         <span></span>
        #         </font></span></span>
        #         </BR>
        #         <span class="ltime"><font color=red size=3><b></b></font></span>
        #         </div>
        #         '''.format(str_class=class_str, str_infoid=info['def_uid'], str_img=self.static_url(imgname),
        #                    str_title=title_str, str_content=info['content'][0], str_time=info['def_update_time_str'])
        #
        #     return (outstr)
Example #9
0
class EditHandler(base_handler.BaseHandler):
    def initialize(self, hinfo=''):

        self.init_condition()


        self.minfo = MInfo(self.city_name)
        self.mcat = MCatalog()
        self.mcity = MCity()

    def get(self, input=''):
        if len(input) == 36:
            inf = self.minfo.get_by_id(input)
            if inf is None:
                self.render('404.html')
                return
            self.toedit(input)
        else:
            self.render('404.html')

    def post(self, input=''):
        if len(input) == 36:
            self.update(input)

    def is_editable(self, info):
        '''
        谁发布的谁编辑
        '''
        if info['userid'] == self.user_name:
            return True
        return False


    def toedit(self, infoid):
        rec_info = self.minfo.get_by_id(infoid)
        if self.is_editable(rec_info):
            pass
        else:
            return
        catid = rec_info['catid'][0]

        kwd = {
            'cityname': self.mcity.get_cityname_by_id(self.city_name),
            'catid': catid,
            'parentid': catid[:2] + '00',
            'parentname': self.mcat.get_by_id(catid[:2] + '00').catname,
            'catname': self.mcat.get_by_id(catid).catname,
            'parentlist': self.mcat.get_parent_list(),

        }
        self.render('edit/edit_{0}.html'.format(catid), kwd=kwd, post_info=rec_info)

    def update(self, par_uid):
        post_data = self.minfo.get_by_id(par_uid)
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)


        img_path_arr = []

        try:
            file_dict_list = self.request.files['mymps_img']
            for file_dict in file_dict_list:
                file_up_str = libs.upload.upload_imgfile(file_dict)
                img_path_arr.append(file_up_str)
        except:
            pass
        post_data['mymps_img'] = img_path_arr
        # 对面积进行处理
        if 'extra_mianji' in post_data:
            mianji_flt = float(post_data['extra_mianji'][0])
            if 'extra_mianji' in post_data:
                if mianji_flt < 20:
                    post_data['extra_mianji1'] = [1]
                elif mianji_flt < 40:
                    post_data['extra_mianji1'] = [2]
                elif mianji_flt < 60:
                    post_data['extra_mianji1'] = [3]
                elif mianji_flt < 90:
                    post_data['extra_mianji1'] = [4]
                elif mianji_flt < 120:
                    post_data['extra_mianji1'] = [5]
                elif mianji_flt < 200:
                    post_data['extra_mianji1'] = [6]
                elif mianji_flt >= 200:
                    post_data['extra_mianji1'] = [7]
        # self.write("finish")

        ts = libs.tool.get_timestamp()
        ts_str = libs.tool.get_time_str(ts)

        post_data['catname'] = self.mcat.get_by_id(post_data['catid'][0]).catname

        # Save in pg database.
        # infoid_data = {'info_uid': uid}
        post_data['userid'] = self.user_name
        post_data['def_uid'] = str(par_uid)
        post_data['update_time'] = ts
        post_data['def_update_time_str'] = ts_str

        # infoid_data['zhiding_out_time'] = ts
        # 刷新
        post_data['def_refresh'] = 1
        post_data['def_refresh_out_time'] = ts + config.c.refresh_timeout
        # 是否有效。是否通过审核
        # 需要重新审核
        post_data['def_valid'] = 1
        post_data['def_banned'] = 0
        udi = self.minfo.update(par_uid, post_data)
        if libs.dfa.filter.isContain(post_data['title'][0]):
            post_data['def_banned'] = 1
            self.render('banned.html')
        self.redirect('/list/{0}'.format(post_data['catid'][0]))