def search_project_by_date(**kwargs): except_q = session.query(Project).filter( or_(Project.start_time > kwargs.get('end_time'), Project.end_time < kwargs.get('start_time')) ) query_result = session.query(Project).except_(except_q).order_by(desc(Project.id)).all() search_datas = ProjectManager.project_data_format(query_result) return search_datas
def add_staff(user_obj): items = session.query(User).filter(User.name == user_obj.name).all() if len(items) == 0: # 数据库中没有重名的存在,则添加 session.add(user_obj) session.commit() else: # 弹出警告 ToolsManager.information_box(u"注意", u"\"%s\"已经存在数据库中!" % unicode(user_obj.name))
def search_staff_by_project_id(project_id): staff_str = '' query_result = session.query(UserProject).filter(UserProject.project_id == project_id).\ order_by(UserProject.user_id).all() for query_meta in query_result: staff_str += query_meta.user.name + ',' if staff_str != '': staff_str = staff_str[:-1] # 去掉最后一个逗号 return staff_str
def updata_staff(dic): item = session.query(User).filter(User.id == dic.get('id')).one() item.name = dic.get('name') item.employee_id = dic.get('employee_id') item.phone_number = dic.get('phone_number') item.tel_number = dic.get('tel_number') item.birth_date = dic.get('birth_date') item.title = dic.get('title') item.position = dic.get('position') item.education = dic.get('education') item.description = dic.get('description') session.add(item) session.commit()
def updata_project(dic): item = session.query(Project).filter(Project.id == dic.get('id')).one() item.name = dic.get('name') item.search_id = dic.get('search_id') item.source_place = dic.get('source_place') item.main_designer = dic.get('main_designer') item.design_all = dic.get('design_all') item.responsible_man = dic.get('responsible_man') item.start_time = dic.get('start_time') item.end_time = dic.get('end_time') item.description = dic.get('description') session.add(item) session.commit() StaffManager.delete_staff_project_by_project_ids([item.id]) StaffManager.add_staff_project(item.id, dic.get('attendee_ids'))
def search_project_by_user_id_and_now(user_id): project_str = '' today = datetime.date.today() para = { "start_time": today, "end_time": today } from apps.project.project_manager import ProjectManager project_search_datas = ProjectManager.search_project_by_date(**para) for project_search_data in project_search_datas: project_user_search_datas = session.query(UserProject).\ filter(and_(UserProject.project_id == project_search_data[0], UserProject.user_id == user_id)).\ order_by(desc(UserProject.project_id)).all() if len(project_user_search_datas) != 0: for project_user_search_data in project_user_search_datas: project_str += project_user_search_data.project.name + ',' if project_str != '': project_str = project_str[:-1] return project_str
def search_staff_project_by_staff_name_and_data(**kwargs): search_datas = [] staff = StaffManager.get_one_item_by_user_name(kwargs.get('name')) if staff not in (None, ''): query_result = session.query(UserProject).filter(UserProject.user_id == staff.id).\ order_by(desc(UserProject.project_id)).all() for query_meta in query_result: if query_meta.project.start_time > kwargs.get('end_time') \ or query_meta.project.end_time < kwargs.get('start_time'): pass else: search_data_meta = [] search_data_meta.append(query_meta.user.name) search_data_meta.append(query_meta.project.name) search_data_meta.append(query_meta.project.start_time) search_data_meta.append(query_meta.project.end_time) staff_str = StaffManager.search_staff_by_project_id(query_meta.project.id) search_data_meta.append(staff_str) search_datas.append(search_data_meta) return search_datas
def get_one_item_by_project_id(item_id): item = session.query(Project).filter(Project.id == item_id).one() return item
def get_all_project(): query = session.query(Project).order_by(desc(Project.id)).all() return query
def delete_project(ids_list): session.query(Project).filter(Project.id.in_(ids_list)).delete(synchronize_session=False) session.commit()
def get_all_staff(): query_result = session.query(User).order_by(User.id).all() return query_result
def get_one_item_by_user_name(item_name): try: item = session.query(User).filter(User.name == item_name).one() return item except: return None
def delete_staff_project_by_staff_project_id(user_id, project_id): session.query(UserProject).\ filter(and_(UserProject.user_id == user_id, UserProject.project_id == project_id)).delete()
def delete_staff_project_by_staff_ids(user_ids): session.query(UserProject).filter(UserProject.user_id.in_(user_ids)).delete(synchronize_session=False) session.commit()
def search_project_by_name(project_name): query_result = session.query(Project).filter(Project.name.like('%%%%%s%%%%' % project_name)).order_by(desc(Project.id)).all() search_datas = ProjectManager.project_data_format(query_result) return search_datas
def delete_staff(ids_list): session.query(User).filter(User.id.in_(ids_list)).delete(synchronize_session=False) session.commit()
def get_one_item_by_user_id(user_id): item = session.query(User).filter(User.id == user_id).one() return item