class ChangeCityHandler(base_handler.BaseHandler): def initialize(self, hinfo=''): self.init_condition() self.mcat = MCatalog() self.mcity = MCity() def get(self, input=''): uu = input.split('/') if input == '': self.changecity() elif len(uu) == 1: self.set_secure_cookie('cityid', uu[0]) self.redirect('/') def post(self, input=''): self.get('') def changecity(self): all_city = self.mcity.getall() kwd = { 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': '0000', 'parentlist': self.mcat.get_parent_list(), } self.render('changecity/city.html', kwd=kwd, city_infos=all_city)
def initialize(self, hinfo=''): self.init_condition() self.minfo = MInfo(self.city_name) self.mcat = MCatalog() self.mcity = MCity()
def initialize(self, hinfo=''): self.init_condition() self.mlink = MLink() self.mcat = MCatalog() self.muser_info = MUser(self.user_name) self.mcity = MCity() vip_cat = self.muser_info.get_by_username().vip_cat.strip().split(',') if vip_cat == ['']: self.vip_cat = [] else: self.vip_cat = vip_cat
class DocumentHandler(BaseHandler): def initialize(self, hinfo=''): self.init_condition() self.mlink = MLink(self.city_name) self.mcat = MCatalog() # self.muser_info = MUser(self.user_name) # self.mcat = MCatalog() # self.mcity = MCity() def get(self, url_str=''): tmp_uu = url_str.split(r'/') kwd = { 'cityname': self.city_name, 'parentid': '0000', 'parentlist': ['1 ','2'], } if len(tmp_uu) == 1: self.view_document(url_str) else: self.render('404.html') def view_document(self, html_name): bread_crumb_nav_str = '<li>当前位置: </li><li><a href="/">吉合营</a></li>' bread_crumb_nav_str += '<li> > </li>' link_recs = self.mlink.query_links_by_parentid('0100') out_link_str = libs.core.get_out_link_str(link_recs, self.static_url) parent_id = '0000' condition='' sub_menu_str = '' catname = '' num = 0 kwd = { 'catid': html_name, '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('document/{0}'.format(html_name), kwd=kwd)
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)
class OpHandler(base_handler.BaseHandler): def initialize(self, hinfo=""): self.init_condition() self.mrefresh = MRefresh() self.mcat = MCatalog() def op_redirect(self, input): """ """ tmp_uu = input.split(r"/") uid = tmp_uu[0] action = tmp_uu[1] if len(tmp_uu) == 3: re_str = """/tui/{0}/{1}""".format(tmp_uu[2], action) else: re_str = """/filter/{0}""".format(action) self.redirect(re_str) def active_info(self, def_uid, sig): """ switch the status. 用于刷新、推广、置顶 """ info_dic = self.minfo.get_by_id(def_uid) # 值大,则权重高。 weight = self.mcat.get_weight_id(info_dic["catid"][0]) sigit = "def_" + sig if info_dic[sigit] == 0: # 避免已经进行过操作 info_dic[sigit] = 1 sig_time = "def_" + sig + "_out_time" timestamp = libs.tool.get_timestamp() + int(config.timeout[sig] / weight) info_dic[sig_time] = timestamp # 首先保证更新成功 if self.minfo.update(def_uid, info_dic) == True: return True def update_userinfo(self, sig, parentid=""): if parentid == "": self.muser_num.num_decrease(sig) else: self.muser_vip.num_decrease(sig, parentid)
class LinkHandler(base_handler.BaseHandler): def initialize(self, hinfo=''): self.init_condition() self.mlink = MLink() self.mcat = MCatalog() self.muser_info = MUser(self.user_name) self.mcity = MCity() vip_cat = self.muser_info.get_by_username().vip_cat.strip().split(',') if vip_cat == ['']: self.vip_cat = [] else: self.vip_cat = vip_cat def get(self, input=''): # Todo: 验证 if input == 'add': self.to_add() elif input == 'list': self.list() elif input.startswith('delete'): self.delete_by_id(input) elif input.startswith('edit'): self.to_edit(input) else: op, catid = input.split(r'/') if op == 'get_list': self.get_list() @tornado.web.authenticated def delete_by_id(self, input): op, uid = input.split('/') self.mlink.delete_by_uid(uid) self.list() def post(self, input=''): if input == 'add': self.add() elif input.startswith('edit'): self.update() @tornado.web.authenticated def add(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) file_dict = self.request.files['link_image'][0] # 对上传的图片进行处理 file_up_str = libs.upload.upload_imgfile(file_dict) out_arr = {'img': file_up_str} out_arr['url'] = post_data['link_url'][0] out_arr['catid'] = post_data['catid'][0] out_arr['cityid'] = self.city_name out_arr['parentid'] = post_data['catid'][0][:2] + '00' out_arr['username'] = self.user_name self.mlink.insert_rec(out_arr) self.redirect('/link/list') def update(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) if 'elink_image' in self.request.files: file_dict = self.request.files['elink_image'][0] file_up_str = libs.upload.upload_imgfile(file_dict) out_arr = {'img': file_up_str} else: out_arr = {'img': post_data['old_img'][0]} out_arr['url'] = post_data['elink_url'][0] out_arr['catid'] = post_data['ecatid'][0] self.mlink.update(post_data['uid'][0], out_arr) self.redirect('/link/list') def list(self): cat_str = '''<option value='' selected >请选择</option>''' for cat_id in self.vip_cat: cat_name = self.mcat.get_by_id(cat_id).catname tmp_str = '''<option value="%s" >%s</option>''' % (cat_id, cat_name) cat_str += tmp_str infos = self.mlink.get_links_by_cityid(self.user_name,self.city_name) kwd = { 'userid': self.user_name, 'cityname': '', 'cityid': self.city_name, 'cat_str': cat_str, 'parentid': '0000', 'parentlist': self.mcat.get_parent_list(), } self.render('link/list.html', infos=infos, kwd=kwd, userinfo=self.muser_info.get_by_username()) def to_add(self): cat_str = '''<option value='' selected >请选择</option>''' for cat_id in self.vip_cat: cat_name = self.mcat.get_by_id(cat_id).catname tmp_str = '''<option value="%s" >%s</option>''' % (cat_id, cat_name) cat_str += tmp_str kwd = { 'userid': self.user_name, 'cityid': self.city_name, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'cat_str': cat_str, 'parentid': '0000', 'parentlist': self.mcat.get_parent_list(), } self.render('link/list.html', kwd=kwd) def to_edit(self, input): op, uid = input.split('/') linkinfo = self.mlink.get_by_id(uid) tmp_s1 = '' tmp_s2 = '' tmp_s3 = '' link_cityid = linkinfo.cityid.strip() if link_cityid == 'changchun': tmp_s1 = 'selected' elif link_cityid == 'tonghua': tmp_s2 = 'selected' elif link_cityid == 'jilin': tmp_s3 = 'selected' cat_str = '''<option value='' selected >请选择</option> ''' for cat_id in self.vip_cat: cat_name = self.mcat.get_by_id(cat_id).catname tmp_str_jcc = '' if cat_id == linkinfo.catid: tmp_str_jcc = 'selected=selected' tmp_str = '''<option value="{0}" {1}>{2}</option>'''.format(cat_id, tmp_str_jcc, cat_name) cat_str += tmp_str kwd = { 'userid': self.user_name, 'cityid': self.city_name, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'cat_str': cat_str, 'parentid': '0000', 'parentlist': self.mcat.get_parent_list(), } self.render('link/list.html', kwd=kwd, linkinfo=linkinfo)
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)
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]))
def initialize(self, hinfo=''): # self.userid = self.get_secure_cookie('login_user').decode('utf-8') self.init_condition() self.mlink = MLink(self.city_name) self.mcat = MCatalog()
def initialize(self, hinfo=''): self.init_condition() # self.muser_info = MUser(self.user_name) self.mcat = MCatalog()
class MemberHandler(base_handler.BaseHandler): def initialize(self, hinfo=''): self.init_condition() # self.muser_info = MUser(self.user_name) self.mcat = MCatalog() # self.mcity = MCity() def get(self, input): if input == '': self.render('member/user.html') elif input == 'regist': self.page_regist() elif input == 'todo2': self.page_regist2() elif input == 'login': self.page_login() elif input == 'logout': self.logout() else: self.set_status(400) def post(self, input=''): if input == 'regist': self.to_regist() elif input == 'login': self.login() elif input == 'checkpass': self.check_pass() elif input == 'changepass': self.changepass() elif input == 'charge': self.charge() elif input == 'convert': self.convert() elif input == 'buy_refresh': self.buy_refresh() elif input == 'buy_publish': self.buy_publish() elif input == 'buy_zhiding': self.buy_zhiding() else: self.set_status(400) def page_login(self): kwd = {'cityid': self.city_name, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': '0', 'parentlist': self.mcat.get_parent_list(), 'message': '', } self.render('member/login.html', kwd=kwd) def page_regist2(self): kwd = {'cityid': self.city_name, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': '0', 'parentlist': self.mcat.get_parent_list(), } self.render('member/todo2.html', kwd=kwd) def page_regist(self): kwd = {'cityid': self.city_name, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': '0', 'parentlist': self.mcat.get_parent_list(), } self.render('member/regist.html', kwd=kwd) def logout(self): ''' ''' self.set_secure_cookie(config.cookie_str['is_login'], 'False') self.set_secure_cookie(config.cookie_str['user'], '') self.redirect('/member/login') def to_regist(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) form = SumForm(post_data) if form.validate(): self.muser_info.insert_data(post_data) self.muser_num.insert_data(post_data) kwd = { 'message': '', } self.redirect('/member/login') # return (True) else: self.render('404.html') # return (False) def login(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) user_name = post_data['user_name'][0] user_pass = libs.tool.md5(post_data['user_pass'][0]) if self.muser_info.check_user_pass(user_name, user_pass) == True: self.set_secure_cookie(config.cookie_str['user'], user_name) self.set_secure_cookie(config.cookie_str['is_login'], 'True') self.set_status(200) self.redirect(self.get_argument('next', '/')) else: self.set_status(400) kwd = {'cityid': self.city_name, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': '0', 'parentlist': self.mcat.get_parent_list(), 'message': '用户名或密码不对,请重新输入。', } self.render('member/login.html', kwd=kwd) def changepass(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) if True == self.muser_info.update_password(post_data['newpass'][0]): self.set_status(200) return (True) else: self.set_status(400) return (False) def charge(self): amount = int(self.get_argument('amount')) self.muser_num.charge(amount) def convert(self): amount = int(self.get_argument('amount')) if self.muser_num.convert(amount): self.set_status(200) else: self.set_status(400) def buy_refresh(self): amount = int(self.get_argument('amount')) if self.muser_num.buy_refresh(amount): self.set_status(200) else: self.set_status(400) def buy_publish(self): amount = int(self.get_argument('amount')) if self.muser_num.buy_publish(amount): self.set_status(200) else: self.set_status(400) def buy_zhiding(self): amount = int(self.get_argument('amount')) if self.muser_num.buy_zhiding(amount): self.set_status(200) else: self.set_status(400) def check_pass(self): ''' 修改密码时,根据当前用户与用户输入的密码, ''' if self.user_name == '': self.redirect('/member/login') return post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) print(post_data) post_old_pass = libs.tool.md5(post_data['oldpass'][0]) db_old_pass = self.muser_info.get_by_username(self.user_name).user_pass print(db_old_pass) if post_old_pass == db_old_pass: self.set_status(200) return (True) else: self.set_status(400) return (False)
class AddHandler(base_handler.BaseHandler): def initialize(self, hinfo=''): self.init_condition() # self.minfo = MInfo(self.city_name) self.mcat = MCatalog() self.mcity = MCity() # self.muser_info = MUser(self.user_name) def get(self, input=''): url_arr = input.split('/') if len(input) == 4: self.toadd(input) elif len(url_arr[0]) == 4 and url_arr[1] == 'vip': self.toadd(url_arr[0], '1') else: self.render('404.html') def post(self, input=''): if len(input) > 0: self.add() @tornado.web.authenticated def toadd(self, catid, vip='0'): ip = self.request.remote_ip # if 'True' != self.get_secure_cookie(config.cookie_str['is_login']).decode('utf-8'): # self.redirect('/member/login') userinfo = self.muser_info.get_by_username() uid = str(uuid.uuid1()) kwd = { 'uid': uid, 'userid': self.user_name, 'cityid': self.city_name, '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(), 'chenghu': userinfo.chenghu, 'phone': userinfo.phone, 'qq': userinfo.qq, 'email': userinfo.email, 'userip': ip, 'vip': vip, } self.render('add/add_{0}.html'.format(catid), kwd=kwd) @tornado.web.authenticated def add(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) uid = post_data['uid'][0] # 对uid进行判断,防止反复发布同一信息。 uu = self.minfo.get_by_id(uid) if str(uu) == 'None': pass else: self.render('not_repeat.html') return # 保存上传之后的图片的相对路径( static ) 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] ts = libs.tool.get_timestamp() ts_str = libs.tool.get_time_str(ts) parentid = post_data['parentid'][0] post_data['catname'] = self.mcat.get_by_id(post_data['catid'][0]).catname post_data['userid'] = self.user_name post_data['views'] = 1 post_data['create_time'] = ts post_data['update_time'] = ts ## 添加控制字段 post_data['def_uid'] = str(uid) post_data['def_create_time_str'] = ts_str post_data['def_update_time_str'] = ts_str # 记录的超时的时间 # 推广 post_data['def_tuiguang_out_time'] = ts # 置顶 post_data['def_zhiding'] = 0 post_data['def_zhiding_out_time'] = ts # 刷新 post_data['def_refresh'] = 1 post_data['def_refresh_out_time'] = ts + c.refresh_timeout # 是否有效。是否通过审核 post_data['def_valid'] = 1 post_data['def_banned'] = 0 if post_data['vip'][0] == '1': post_data['def_tuiguang'] = 1 # print('>'* 80) # print(parentid) if self.muser_vip.get_vip_publish_num(parentid) <= 0: return False if self.__should_banned(post_data) == True: post_data['def_banned'] = 1 if self.minfo.insert_data(post_data) == True: self.muser_vip.publish_num_decrease(parentid) self.render('banned.html') else: self.render('error.html') else: if self.minfo.insert_data(post_data) == True: self.muser_vip.publish_num_decrease(parentid) self.muser_num.jifen_increase(num=2) self.redirect('/list/{0}'.format(post_data['catid'][0])) else: self.render('error.html') else: post_data['def_tuiguang'] = 0 if self.muser_num.get_free_publish_num() + self.muser_num.get_buy_publish_num() <= 0: return False if self.__should_banned(post_data) == True: post_data['def_banned'] = 1 if self.minfo.insert_data(post_data) == True: self.muser_num.publish_num_decrease() self.render('banned.html') else: self.render('error.html') else: if self.minfo.insert_data(post_data) == True: self.muser_num.publish_num_decrease() self.muser_num.jifen_increase(num=2) self.redirect('/list/{0}'.format(post_data['catid'][0])) else: self.render('error.html') def __should_banned(self, post_data): if libs.dfa.filter.isContain(post_data['title'][0]) == True: return True if libs.dfa.filter.isContain(post_data['content'][0]) == True: return True return False
def initialize(self, hinfo=""): self.init_condition() self.mrefresh = MRefresh() self.mcat = MCatalog()
class PublishHandler(base_handler.BaseHandler): def initialize(self, hinfo=''): self.init_condition() self.mcat = MCatalog() self.mcity = MCity() def to_login(self): # tools.markit() self.redirect('/member/login') return (True) @tornado.web.authenticated def get(self, input=''): url_arr = input.split('/') if input == '': self.view_class1() elif len(input) == 4: self.view_class2(input) elif len(input) == 5: self.echo_class2(input) elif len(url_arr) == 2 and url_arr[1] == 'vip': self.view_class2(url_arr[0], 1) def post(self, input=''): # print ('*' * 20) self.get('') @tornado.web.authenticated def echo_class2(self, input=''): ''' 弹出的二级发布菜单 ''' fatherid = input[1:] self.write(self.format_class2(fatherid)) @tornado.web.authenticated def format_class2(self, fatherid, vip=0): dbdata = self.mcat.get_range2_without_parent(fatherid) outstr = '<ul class="list-group">' for rec in dbdata: if vip == 1: outstr += ''' <a href="/add/{0}/vip" class="btn btn-primary" style="display: inline-block;margin:3px;" >{1}</a> '''.format(rec.catid, rec.catname) else: outstr += ''' <a href="/add/{0}" class="btn btn-primary" style="display: inline-block;margin:3px;" >{1}</a> '''.format(rec.catid, rec.catname) outstr += '</ul>' return (outstr) @tornado.web.authenticated def view_class1(self, fatherid=''): dbdata = self.mcat.get_parent_list() class1str = '' for rec in dbdata: class1str += ''' <a onclick="select('/publish/2{0}');" class="btn btn-primary" style="display: inline-block;margin:3px;" >{1}</a> '''.format(rec.catid, rec.catname) kwd = { 'class1str': class1str, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': '0', 'parentlist': self.mcat.get_parent_list(), } self.render('publish/publish.html', kwd=kwd) @tornado.web.authenticated def view_class2(self, fatherid='', vip=0): ''' 从第二级发布 :param fatherid: :return: ''' fatherid = fatherid[:2] + '00' kwd = { 'class1str': self.format_class2(fatherid, vip), 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': '0', 'parentlist': self.mcat.get_parent_list(), } self.render('publish/publish2.html', kwd=kwd)
def initialize(self, hinfo=''): self.init_condition() self.mlink = MLink(self.city_name) self.mcat = MCatalog()
class InfoHandler(base_handler.BaseHandler): def initialize(self, hinfo=''): # self.userid = self.get_secure_cookie('login_user').decode('utf-8') self.init_condition() self.mlink = MLink(self.city_name) self.mcat = MCatalog() def get(self, input=''): if len(input) == 36: self.view(input) elif input.startswith('shoucang'): info_uid = input.split('/')[1] self.shoucang(info_uid) else: self.render('404.html') def shoucang(self, info_uid): uid = libs.tool.md5(''.join([self.user_name, info_uid])) if self.mshoucang.has_record(uid): return info_dic = { 'uid': uid, 'timestamp': libs.tool.get_timestamp(), 'userid': self.user_name, 'info_uid': info_uid, 'catname': self.minfo.get_by_id(info_uid)['catname'], 'title': self.minfo.get_by_id(info_uid)['title'][0], } self.mshoucang.insert_data(info_dic) def post(self, input=''): self.update_jianli(input) def update_jianli(self, input): # print(input) post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) # for x in post_data: # print(post_data[x]) self.minfo.update_jianli(input, post_data['jianli'][0]) self.view(input) def is_viewable(self, info): if info['userid'] == self.user_name: # 如果是用户自己的,当然可以查看 return True if info['def_valid'] != 1: return (False) if info['def_banned'] == 1: return (False) return True def view(self, uuid): info = self.minfo.get_by_id(uuid) if info is None: # 如果资源不存在 self.set_status(404) self.render('404_view.html') return (False) elif self.is_viewable(info): pass else: self.render('404.html') return cat_id = info['catid'][0] parent_id = cat_id[:2] + '00' parent_catname = self.mcat.get_by_id(parent_id).catname catname = self.mcat.get_by_id(cat_id).catname daohang_str = '<a href="/">数据中心</a>' daohang_str += ' > <a href="/list/{0}">{1}</a>'.format(parent_id, parent_catname) daohang_str += ' > <a href="/list/{0}">{1}</a>'.format(cat_id, catname) ts = info['def_update_time_str'] imgname = '' has_image = 0 img_url = '' if len(info['mymps_img']) > 0: imgname = info['mymps_img'][0] has_image = 1 img_url = self.static_url(imgname) # 左侧菜单 rnage2_list = self.mcat.get_range2_without_parent(parent_id) sub_menu_str = libs.core.get_sub_menu_str(rnage2_list, parent_catname) # 右侧图片广告 link_recs = self.mlink.get_links_by_catid(cat_id) out_link_str = libs.core.get_out_link_str(link_recs, self.static_url) # 自己发布的内容,不用收藏。 if self.user_name == info['userid']: # operate_str = '''<div id="g_fy" ><a href="/edit/{0}">编辑</a> # <a href="/tuiguang/{0}" >推广</a> # <a href="/zhiding/{0}" >置顶</a> # </div> # '''.format(uuid) operate_str = '' else: operate_str = '''<span><a onclick="js_show_page('/user/shoucang/{0}')">收藏</a></span>'''.format(uuid) # 在DIV中的个人简历 jianli_str = '' if parent_id == '0700': jianli_str = self.gen_jianli_str() kwd = { 'img_url': img_url, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'timeit': ts, 'daohangstr': daohang_str, 'has_image': has_image, 'parentid': parent_id, 'parentlist': self.mcat.get_parent_list(), 'sub_menu': sub_menu_str, 'linkstr': out_link_str, 'oprt_str': operate_str, 'jianli_str': jianli_str, # 'maskip': maskip, } self.update_info_when_view(info) self.render('view/view_%s.html' % (info['catid'][0]), kwd=kwd, post_info=info) def gen_jianli_str(self): # 查看页面时,根据用户的信息,生成简历。 tmp1_tou = ''' <div id='inline_content' style='padding:10px; background:#fff; border: 2px solid #000088'> <form action='' method="post" > <legend>请选择使用哪份简历</legend> ''' jianlis = self.minfo.get_user_jianli(self.user_name) if jianlis.count() == 0: tmp1_tou += ''' <p>目前没有求职简历</p> <a href="/publish/0700">创建求职简历 </a> </div> ''' else: # 第一次为 checked check_str = 'checked' for jianli in jianlis: tmp1_uuvv = '''<label>简历</label><input type="radio" {2} name="jianli" value="{0}" >{1} <br /> '''.format(jianli['def_uid'], jianli['title'][0], check_str) check_str = '' tmp1_tou += tmp1_uuvv tmp1_tou += '''<button type="submit" class="ajax pure-button pure-button-primary" >确定</button></p> </form></div> ''' # tmp1_tou += tmp1_hou return (tmp1_tou) def update_info_when_view(self, info): uuid = info['def_uid'] self.minfo.update_view_count(uuid) # 根据时间判断,如果超时,则取消对应的权限 timestamp = libs.tool.get_timestamp() if timestamp > info['def_tuiguang_out_time']: print('a') self.minfo.dis_tuiguang(uuid) if timestamp > info['def_zhiding_out_time']: print('b') self.minfo.dis_zhiding(uuid) if timestamp > info['def_refresh_out_time']: print('c') self.minfo.dis_fresh(uuid)
class LinkHandler(base_handler.BaseHandler): def initialize(self, hinfo=''): self.init_condition() self.mlink = MLink(self.city_name) self.mcat = MCatalog() def get(self, input=''): # Todo: 验证 url_arr = input.split('/') if url_arr[0] == 'add_frame': self.to_add_frame(url_arr[1]) elif url_arr[0] == 'add': self.to_add(url_arr[1]) elif url_arr[0] == 'view': self.view(url_arr[1]) elif input == 'list': self.list() elif input.startswith('delete'): self.delete_by_id(input) elif input.startswith('edit'): self.to_edit(input) else: op, catid = input.split(r'/') if op == 'get_list': self.get_list() def view(self, parentid): linkinfo = self.mlink.get_links_by_parentid(parentid, self.user_name) if linkinfo: kwd = { 'userid': self.user_name, 'cityid': self.city_name, 'parentid': parentid, } self.render('link/view.html', kwd=kwd, linkinfo=linkinfo) @tornado.web.authenticated def delete_by_id(self, input): op, uid = input.split('/') self.mlink.delete_by_uid(uid) self.list() def post(self, input=''): if input == 'add': self.add() elif input.startswith('edit'): self.update() @tornado.web.authenticated def add(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) parentid = post_data['parentid'][0] if self.mlink.get_links_by_parentid(parentid, self.user_name): self.set_status(400) else: file_dict = self.request.files['link_image'][0] # 对上传的图片进行处理 file_up_str = libs.upload.upload_imgfile(file_dict) out_arr = {'img': file_up_str} out_arr['url'] = post_data['link_url'][0] out_arr['catid'] = '' out_arr['cityid'] = self.city_name out_arr['parentid'] = parentid out_arr['username'] = self.user_name self.mlink.insert_rec(out_arr) self.set_status(200) self.redirect('/link/view/{0}'.format(parentid)) @tornado.web.authenticated def update(self): post_data = {} for key in self.request.arguments: post_data[key] = self.get_arguments(key) if 'elink_image' in self.request.files: file_dict = self.request.files['elink_image'][0] file_up_str = libs.upload.upload_imgfile(file_dict) out_arr = {'img': file_up_str} else: out_arr = {'img': post_data['old_img'][0]} out_arr['url'] = post_data['elink_url'][0] out_arr['catid'] = post_data['ecatid'][0] self.mlink.update(post_data['uid'][0], out_arr) self.set_status(200) def list(self): cat_str = '''<option value='' selected >请选择</option>''' for cat_id in self.muser_info.get_vip_cats(): cat_name = self.mcat.get_by_id(cat_id).catname tmp_str = '''<option value="%s" >%s</option>''' % (cat_id, cat_name) cat_str += tmp_str infos = self.mlink.get_links_by_cityid(self.user_name, self.city_name) kwd = { 'userid': self.user_name, 'cityname': '', 'cityid': self.city_name, 'cat_str': cat_str, 'parentid': '0000', 'parentlist': self.mcat.get_parent_list(), } self.render('link/list.html', infos=infos, kwd=kwd, wuserinfo=self.muser_info.get_by_username(), wuservip=self.muser_vip.get_by_username(), ) @tornado.web.authenticated def to_add(self, parentid): kwd = { 'userid': self.user_name, 'cityid': self.city_name, # 'cityname': self.mcity.get_cityname_by_id(self.city_name), # 'city_select_str': city_select_str, 'parentid': parentid, # 'parentlist': self.mcat.get_parent_list(), } current_link = self.mlink.get_links_by_parentid(parentid, self.user_name) if current_link: self.render('link/edit.html', kwd=kwd, linkinfo = current_link) self.render('link/add.html', kwd=kwd) @tornado.web.authenticated def to_add_frame(self, parentid): kwd = { 'userid': self.user_name, 'cityid': self.city_name, # 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'parentid': parentid, # 'parentlist': self.mcat.get_parent_list(), } self.render('link/add_frame.html', kwd=kwd, wuserinfo=self.muser_info.get_by_username(), wuservip=self.muser_vip.get_by_username()) @tornado.web.authenticated def to_edit(self, input): # Generate the select options for cityid op, uid = input.split('/') # self.mlink.delete_by_uid(uid) linkinfo = self.mlink.get_by_id(uid) # self.list() tmp_s1 = '' tmp_s2 = '' tmp_s3 = '' link_cityid = linkinfo.cityid.strip() # print(link_cityid) if link_cityid == 'changchun': tmp_s1 = 'selected' elif link_cityid == 'tonghua': tmp_s2 = 'selected' elif link_cityid == 'jilin': tmp_s3 = 'selected' # city_select_str = ''' # <option value="changchun" {0}>c.长春</option> # <option value="tonghua" {1}>t.通化</option> # <option value="jilin" {2}>j.吉林</option> # '''.format(tmp_s1, tmp_s2, tmp_s3) # cat_str = '''<option value='' selected >请选择</option> ''' # print(self.vip_cat) for cat_id in self.vip_cat: cat_name = self.mcat.get_by_id(cat_id).catname tmp_str_jcc = '' if cat_id == linkinfo.catid: tmp_str_jcc = 'selected=selected' tmp_str = '''<option value="{0}" {1}>{2}</option>'''.format(cat_id, tmp_str_jcc, cat_name) cat_str += tmp_str kwd = { 'userid': self.user_name, 'cityid': self.city_name, 'cityname': self.mcity.get_cityname_by_id(self.city_name), 'cat_str': cat_str, 'parentid': '0000', 'parentlist': self.mcat.get_parent_list(), } # print(kwd) self.render('link/list.html', kwd=kwd, linkinfo=linkinfo)
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,)
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')