def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') master_id = self.get_argument('master_id', '') ret = {} try: session = Session() masterdao = MasterDAO() try: row = session.query(Master, Manager, func.group_concat(MasterPreferedArea.prefered_gu)) \ .join(Manager, Master.manager_id == Manager.id) \ .outerjoin(MasterPreferedArea, MasterPreferedArea.master_id == Master.id) \ .filter(Master.id == master_id) \ .group_by(Master.id) \ .one() except NoResultFound, e: session.close() self.set_status(Response.RESULT_OK) add_err_message_to_response(ret, err_dict['err_no_record']) return result = session.query(Master, MasterTimeSlot) \ .join(MasterTimeSlot, Master.id == MasterTimeSlot.master_id) \ .filter(Master.id == master_id) \ .order_by(MasterTimeSlot.day_of_week) \ .all() mid = row.Master.id rating_clean, rating_master = masterdao.get_master_rating(mid) total_salary = masterdao.get_master_total_granted_salary(mid) last_month_salary = masterdao.get_master_last_month_granted_salary( mid) prefered_area = masterdao.get_master_prefered_area(mid) start_times = ['', '', '', '', '', '', ''] end_times = ['', '', '', '', '', '', ''] for r in result: dow = int(r.MasterTimeSlot.day_of_week) start_times[dow] = str(r.MasterTimeSlot.start_time.hour) end_times[dow] = str(r.MasterTimeSlot.end_time.hour) working_startdate = masterdao.get_master_working_start_date(mid) completed_cleaning_count = masterdao.get_master_completed_cleaning_count( mid) master_info = {} master_info['master_id'] = row.Master.id master_info['name'] = row.Master.name master_info['phone'] = row.Master.phone master_info['img'] = row.Master.img_url master_info['age'] = row.Master.age master_info['gender'] = row.Master.gender master_info['pet_alergy'] = row.Master.pet_alergy master_info['address'] = row.Master.address master_info['manager_name'] = row.Manager.name master_info['manager_phone'] = row.Manager.phone master_info['cardinal'] = row.Master.cardinal master_info['level'] = row.Master.level master_info['rating_clean'] = float(rating_clean) master_info['rating_master'] = float(rating_master) master_info['total_salary'] = int(total_salary) master_info['last_month_salary'] = int(last_month_salary) master_info[ 'prefered_area'] = prefered_area # comma separated area master_info['cs_prefered_area'] = row[2] # comma separated area master_info['start_times'] = ','.join( start_times) # comma start_time master_info['end_times'] = ','.join(end_times) # comma end_time master_info['working_startdate'] = working_startdate master_info['cleaning_count'] = completed_cleaning_count ret['response'] = master_info self.set_status(Response.RESULT_OK)
def get(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') ret = {} try: session = Session() masterdao = MasterDAO() masters = [] master_ids = masterdao.get_all_master_ids() for mid in master_ids: master_info = {} basic = masterdao.get_master_basic_info(mid) rating_clean, rating_master = masterdao.get_master_rating(mid) total_salary = masterdao.get_master_total_granted_salary(mid) last_month_salary = masterdao.get_master_last_month_granted_salary( mid) prefered_area = masterdao.get_master_prefered_area(mid) start_times, end_times = masterdao.get_master_working_time(mid) working_startdate = masterdao.get_master_working_start_date( mid) completed_cleaning_count = masterdao.get_master_completed_cleaning_count( mid) bank_name, bank_code, account_no = masterdao.get_master_account( mid) master_info['master_id'] = mid master_info['name'] = basic['name'] master_info['phone'] = basic['phone'] master_info['img'] = basic['img'] master_info['age'] = basic['age'] master_info['gender'] = basic['gender'] master_info['address'] = basic['address'] master_info['pet_alergy'] = basic['pet_alergy'] master_info['manager_name'] = basic['manager_name'] master_info['manager_phone'] = basic['manager_phone'] master_info['cardinal'] = basic['cardinal'] master_info['level'] = basic['level'] master_info['need_route'] = basic['need_route'] master_info['t_size'] = basic['t_size'] master_info['rating_clean'] = float(rating_clean) master_info['rating_master'] = float(rating_master) master_info['total_salary'] = int(total_salary) master_info['last_month_salary'] = int(last_month_salary) master_info['prefered_area'] = prefered_area master_info['prefered_area_list'] = [ area for area in prefered_area.split(',') ] master_info['start_times'] = start_times master_info['end_times'] = end_times master_info['active'] = basic['active'] master_info['working_startdate'] = working_startdate master_info['cleaning_count'] = completed_cleaning_count master_info['account'] = { 'name': bank_name, 'code': bank_code, 'account_no': account_no } masters.append(master_info) ret['response'] = masters self.set_status(Response.RESULT_OK) except Exception, e: session.rollback() print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])
def post(self): self.set_header("Content-Type", "application/json") self.set_header('Access-Control-Allow-Origin', '*') search_term = self.get_argument('search_term', '') ret = {} try: session = Session() masterdao = MasterDAO() if search_term == None or search_term == '' or len(search_term) == 1 or search_term == '010': self.set_status(Response.RESULT_OK) add_err_ko_message_to_response(ret, '잘못된 파라미터 입니다.') return print 'searching master term : ' + search_term masters = [] results = session.query(Master) \ .filter(or_(Master.phone.like(search_term + '%'), Master.name.like('%' + search_term + '%'))) \ .filter(Master.active != 0) \ .all() print results total_counts = 0 for result in results: mid = result.id print mid master_info = {} basic = masterdao.get_master_basic_info(mid) rating_clean, rating_master = masterdao.get_master_rating(mid) total_salary = masterdao.get_master_total_granted_salary(mid) last_month_salary = masterdao.get_master_last_month_granted_salary(mid) prefered_area = masterdao.get_master_prefered_area(mid) start_times, end_times = masterdao.get_master_working_time(mid) working_startdate = masterdao.get_master_working_start_date(mid) completed_cleaning_count = masterdao.get_master_completed_cleaning_count(mid) bank_name, bank_code, account_no = masterdao.get_master_account(mid) master_info['master_id'] = mid master_info['name'] = basic['name'] master_info['phone'] = basic['phone'] master_info['img'] = basic['img'] master_info['age'] = basic['age'] master_info['gender'] = basic['gender'] master_info['address'] = basic['address'] master_info['pet_alergy'] = basic['pet_alergy'] master_info['manager_name'] = basic['manager_name'] master_info['manager_phone'] = basic['manager_phone'] master_info['cardinal'] = basic['cardinal'] master_info['level'] = basic['level'] master_info['need_route'] = basic['need_route'] master_info['t_size'] = basic['t_size'] master_info['rating_clean'] = float(rating_clean) master_info['rating_master'] = float(rating_master) master_info['total_salary'] = int(total_salary) master_info['last_month_salary'] = int(last_month_salary) master_info['prefered_area'] = prefered_area master_info['prefered_area_list'] = [area for area in prefered_area.split(',')] master_info['start_times'] = start_times master_info['end_times'] = end_times master_info['active'] = basic['active'] master_info['working_startdate'] = working_startdate master_info['cleaning_count'] = completed_cleaning_count master_info['account'] = {'name' : bank_name, 'code' : bank_code, 'account_no' : account_no} masters.append(master_info) total_counts += 1 print masters ret['response'] = {'counts' : total_counts, 'masters' : masters } self.set_status(Response.RESULT_OK) except Exception, e: session.rollback() print_err_detail(e) self.set_status(Response.RESULT_SERVERERROR) add_err_message_to_response(ret, err_dict['err_mysql'])