def search_parameter(request, search_type=None): report_skill_main_classes = ReportSkillMainClass.objects.\ filter().values("id", "skill_main_class_code", "skill_main_class_name").order_by('-id') report_skill_main_list = json.dumps([], ensure_ascii=False) if len(report_skill_main_classes) > 0: tmp_list = [] for i in report_skill_main_classes: tmp_list.append(i) # result['data'] = serializers.serialize('json', objects) report_skill_main_list = json.dumps(tmp_list, ensure_ascii=False) report_skill_result = ReportSkill.objects.\ filter().values("skill_id", "skill_name", "skill_main_class", "skill_main_class_name").order_by('-skill_id') report_skill_list = json.dumps([], ensure_ascii=False) if len(report_skill_result) > 0: tmp_list = [] for i in report_skill_result: tmp_list.append(i) # result['data'] = serializers.serialize('json', objects) report_skill_list = json.dumps(tmp_list, ensure_ascii=False) teacher_tmp = None role_name = request.session.get('role_name', None) # 用户名 if role_name is not None: if role_name in 'teacher': username = request.session.get('username', None) # 用户名 if username: register_user_info = RegisterUserInfo.objects.get(username=username) user_info_tmp = UserInfo.objects.get(register_user_info=register_user_info) teacher_tmp = TeacherInfo.objects.get(user_info=user_info_tmp) teacher_tmp = teacher_tmp.id else: pass print('role') print(role_name) print(teacher_tmp) title_msg = "所有学员的条件查询" student_search = StudentSearchForm(request.GET) user_search = UserInfoSearchForm(request.GET) page_search = PageSearchForm(request.GET) teacher_infos = TeacherInfo.objects.all() school_terms = SchoolTerm.objects.filter().order_by('-id') school_terms_values = school_terms.values() tmp_list = [] print(school_terms_values) if len(school_terms_values) > 0: for i in school_terms_values: tmp_json = {} tmp_json['id_str'] = i['id'] tmp_json['school_term_name'] = i['school_term_name'] tmp_json['school_term_start'] = date_encoder(i['school_term_start']) tmp_json['school_term_end'] = date_encoder(i['school_term_end']) tmp_list.append(tmp_json) print(tmp_list) per_page = 10 page = 1 if page_search.is_valid(): if page_search.cleaned_data.get('per_page', None): per_page = page_search.cleaned_data.get('per_page', None) if page_search.cleaned_data.get('page', None): page = page_search.cleaned_data.get('page', None) if student_search.is_valid(): if user_search.is_valid(): # 用户信息 kwargs = {} # kwargs['confirm_status'] = 1, # kwargs['chemical_worker'] = 1, user_info = UserInfo() real_name = user_search.cleaned_data.get('real_name', None) if real_name: user_info.real_name = real_name kwargs['user_info__real_name__icontains'] = real_name work_unit = user_search.cleaned_data.get('work_unit', None) if work_unit: user_info.work_unit = work_unit kwargs['user_info__work_unit__icontains'] = work_unit education_degree = user_search.cleaned_data.get('education_degree', None) if education_degree: user_info.education_degree = education_degree if type(education_degree) == str: if int(education_degree) > 0: kwargs['user_info__education_degree__id'] = int(education_degree) else: kwargs['user_info__education_degree__id'] = education_degree # 学生信息 student_info = StudentInfo() identification_level = student_search.cleaned_data.get('identification_level', None) declaration_of_occupation = student_search.cleaned_data.get('declaration_of_occupation', None) teacher_info = student_search.cleaned_data.get('teacher_info', None) print('teacher_info') print(teacher_info) school_term = student_search.cleaned_data.get('school_term', None) if identification_level: student_info.identification_level = identification_level if type(identification_level) == str: if int(identification_level) > 0: kwargs['identification_level'] = int(identification_level) else: kwargs['identification_level'] = identification_level else: identification_level = 0 if declaration_of_occupation: student_info.declaration_of_occupation = declaration_of_occupation kwargs['declaration_of_occupation__icontains'] = declaration_of_occupation student_infos_all_term_count = 0 if teacher_info: if teacher_info != 0: if type(teacher_info) == str: if int(teacher_info) > 0: kwargs['teacher_info'] = int(teacher_info) student_info.teacher_info = TeacherInfo.objects.get(id=int(teacher_info)) else: kwargs['teacher_info'] = teacher_info student_info.teacher_info = TeacherInfo.objects.get(id=teacher_info) student_infos_all_term_count = StudentInfo.objects.filter(teacher_info=teacher_info).count() else: if teacher_tmp: teacher_info = teacher_tmp else: teacher_info = 0 last_school_term = SchoolTerm.objects.last() if school_term: if type(school_term) == str: if int(school_term) > 0: kwargs['school_term'] = int(school_term) student_info.school_term = SchoolTerm.objects.get(id=int(school_term)) else: kwargs['school_term'] = school_term student_info.school_term = SchoolTerm.objects.get(id=school_term) else: if last_school_term: last_school_term = SchoolTerm.objects.last() school_term = last_school_term.id kwargs['school_term'] = school_term student_info.school_term = SchoolTerm.objects.get(id=school_term) report_skill_main_tmp = student_search.cleaned_data.get('skill_main_class', None) if report_skill_main_tmp: if type(report_skill_main_tmp) == str: if int(report_skill_main_tmp) > 0: kwargs['skill_main_class'] = int(report_skill_main_tmp) student_info.skill_main_class = report_skill_main_tmp else: kwargs['skill_main_class'] = report_skill_main_tmp student_info.report_skill_main = report_skill_main_tmp else: skill_main_class = 0 report_skill_tmp = student_search.cleaned_data.get('skill_main_class', None) if report_skill_tmp: if type(report_skill_tmp) == str: if int(report_skill_tmp) > 0: kwargs['report_skill'] = int(report_skill_tmp) student_info.report_skill = report_skill_tmp else: kwargs['report_skill'] = report_skill_tmp student_info.teacher_info = report_skill_tmp else: report_skill = 0 if report_skill_main_tmp: report_skill_main = report_skill_main_tmp else: report_skill_main = 0 if report_skill_tmp: report_skill = report_skill_tmp else: report_skill = 0 student_info.user_info = user_info print(search_type) print(kwargs) print(school_term) print(StudentInfo.objects.filter(review_status=1,cancel_status=2,**kwargs)) if search_type == 'wait_confirm': student_infos = StudentInfo.objects.filter(review_status=1, cancel_status=2, **kwargs).order_by('-id') elif search_type == 'electronic_communication': student_infos = StudentInfo.objects.filter(confirm_status=1, cancel_status=2, **kwargs).order_by('-id') elif search_type == 'all_student': student_infos = StudentInfo.objects.filter(confirm_status=1, cancel_status=2, **kwargs).order_by('-id') elif search_type == 'teacher_search_wait_review': student_infos = StudentInfo.objects.filter(teacher_info=teacher_info, **kwargs).order_by('-id') else: student_infos = StudentInfo.objects.filter(confirm_status=1, cancel_status=2, **kwargs).order_by('-id') print('student_infos') print(student_infos) paginator = Paginator(student_infos, per_page) contacts = paginator.get_page(page) # return render_result(request, "page_main_controller/administrator/all_student_base_info.html", # {'title_msg': title_msg, "contacts": contacts, 'student_info': student_info, # 'teacher_infos': teacher_infos, 'teacher_info': teacher_info, 'school_terms': school_terms, # 'school_term': school_term, 'identification_level': identification_level}) print('-----------------------') param_result = {'no_term': True, 'tmp_list':tmp_list, 'report_skill_main_list':report_skill_main_list, 'report_skill_list':report_skill_list, 'last_school_term':last_school_term, 'student_info':student_info, 'contacts':contacts, 'teacher_infos':teacher_infos, 'school_terms':school_terms, 'school_term':school_term, 'teacher_info':teacher_info, 'identification_level':identification_level, 'report_skill_main':report_skill_main, 'no_term': True, 'report_skill':report_skill, 'student_infos_all_term_count':student_infos_all_term_count, 'current_term_student_len': len(student_infos)} if len(school_terms) == 0: # param_result = param_result = {'school_term': None} return param_result else: return {'user_search_error_class':user_search.error_class, 'user_search_errors':user_search.errors} else: return {'student_search_error_class':student_search.error_class, 'student_search_errors':student_search.errors}
def spin_format(student_infos=None, skill_main_class_name=None, skill_main_class_code=None): """ 纺织通信类 :return: """ try: document_root = os.path.join(BASE_DIR, 'document') filepath = document_root + "/spin_format.xlsx" # system_type = platform.system() # if 'indows' in system_type: # filepath = "D:/PycharmProjects/lelingzdy/baoming/webapp/utils/fujian04_excel_format.xlsx" # else: # filepath = "/opt/python3_space/lelingzdy/baoming/webapp/utils/fujian04_excel_format.xlsx" original_data = pd.read_excel(filepath, encoding='utf-8') # rb打开该excel,formatting_info=True表示打开excel时并保存原有的格式 rb = xlrd.open_workbook(filepath, formatting_info=True) # 创建一个可写入的副本 wb = xlutils.copy.copy(rb) if not student_infos: skill_main_classies = ReportSkillMainClass.objects.filter(skill_main_class_name__icontains='纺织').\ filter(skill_main_class_name__icontains='服装').values('id') if len(skill_main_classies) > 0: print(skill_main_classies[0]) print(skill_main_classies[0]['id']) student_infos = StudentInfo.objects.filter(confirm_status=1, skill_main_class=skill_main_classies[0]['id']) tmp_array = [] if len(student_infos) > 0: tmp_num = 0 for student in student_infos: identification_level = str(student.identification_level) if len(identification_level) > 0: identification_level = worker_level[str(student.identification_level)] else: identification_level = '' # 原证书编号 original_certificate_number = student.original_certificate_number if original_certificate_number: pass else: original_certificate_number = "" # 文化程度 education_degree = student.user_info.education_degree if education_degree: education_name = student.user_info.education_degree.education_name else: education_name = '' tmp_num = tmp_num + 1 # tmp_dict = {'index': str(tmp_num), # 'r_e': student.user_info.real_name, # 'id_number': student.user_info.id_number, # 'sa': get_sex(student.user_info.sex), # 'school': student.user_info.middle_school, # 'f_occ': student.declaration_of_occupation, # 's_w_d': student.user_info.start_working_date, # 'id_level': identification_level, # 'jsll': '', # 'sjcz': '', # 'o_cer_num': original_certificate_number, # 'issuance_time': issuance_time} # tmp_list.append(tmp_dict) # 原级别 primary_level = str(student.primary_level) if len(student.primary_level) > 0: primary_level = worker_level[str(student.primary_level)] else: primary_level = '' if student.user_info.start_working_date: start_working_date = date_encoder(student.user_info.start_working_date) else: start_working_date = '' if student.issuance_time: issuance_time = date_encoder(student.issuance_time) else: issuance_time = '' career_life = student.career_life original_certificate_worker_year = student.original_certificate_worker_year apprentice_year = student.apprentice_year apprentice_month = student.apprentice_month flag_working_time = False if student.identification_level == "3": working_year = '' elif student.identification_level == "4": if original_certificate_worker_year: if original_certificate_worker_year > 0: working_year = '' flag_working_time = True else: flag_working_time = True else: flag_working_time = True else: flag_working_time = True if flag_working_time: if not career_life: if apprentice_year: if apprentice_year > 0: working_year = str(apprentice_year) else: if apprentice_month: if apprentice_month > 0: working_year = str(apprentice_month) + "月" else: working_year = '' else: working_year = '' else: working_year = career_life else: pass # 文化程度 education_degree = student.user_info.education_degree if education_degree: education_name = student.user_info.education_degree.education_name else: education_name = '' # 身份证住址 rt_id_addr = RichText('') id_card_address = student.user_info.id_card_address if str(id_card_address).__len__() > 8: rt_id_addr.add(id_card_address, size=10) # 字体大小 elif str(id_card_address).__len__() > 13: rt_id_addr.add(id_card_address, size=8) # 字体大小 elif str(id_card_address).__len__() > 16: rt_id_addr.add(id_card_address, size=6) # 字体大小 else: rt_id_addr.add(id_card_address, size=14) # 字体大小 tmp_array.append([tmp_num, student.user_info.real_name,#中文名 get_sex(student.user_info.sex),#性别 student.user_info.work_unit,#工作单位 student.user_info.id_number,#身份证号 education_name,#文化程度 working_year,#工作年限 identification_level,#级别 student.declaration_of_occupation,#职业工种 student.original_certificate_number,#原职业工种 primary_level,#原职业等级 ''#符合申报条件第多少项 ]) num = 0 print('len:::' + str(len(original_data))) for row in range(0, len(original_data)): if row > 3: out_sheet = wb.get_sheet(0) if num < len(tmp_array): set_out_cell(out_sheet, 0, row, tmp_array[num][0]) set_out_cell(out_sheet, 1, row, tmp_array[num][1]) set_out_cell(out_sheet, 2, row, tmp_array[num][2]) set_out_cell(out_sheet, 3, row, tmp_array[num][3]) set_out_cell(out_sheet, 4, row, tmp_array[num][4]) set_out_cell(out_sheet, 5, row, tmp_array[num][5]) set_out_cell(out_sheet, 6, row, tmp_array[num][6]) set_out_cell(out_sheet, 7, row, tmp_array[num][7]) set_out_cell(out_sheet, 8, row, tmp_array[num][8]) set_out_cell(out_sheet, 9, row, tmp_array[num][9]) set_out_cell(out_sheet, 10, row, tmp_array[num][10]) set_out_cell(out_sheet, 11, row, tmp_array[num][11]) else: set_out_cell(out_sheet, 0, row, num + 1) num = num + 1 day_string = str(time.strftime('%Y/%m/%d', time.localtime(time.time()))) file_root = MEDIA_ROOT + "/files/" day_files_path = file_root + 'spin' + "/files/" + day_string if os.path.exists(day_files_path): pass else: os.makedirs(day_files_path) uuid_string = str(uuid.uuid4()) file_day_files_path = day_files_path + "/" + uuid_string + ".xlsx" wb.save(file_day_files_path) if os.path.exists(file_day_files_path): file_manage = FileManage() file_manage.file_name = "纺织类模板-" + day_string file_manage.file_uuid = uuid_string file_manage.file_path = file_day_files_path file_manage.save() # 附件1 生成非化工类学员化名册成功, return str(file_manage.file_uuid) else: return None else: return None except Exception as e: print(e) raise e
def reporter_chemical_not_list(student_infos=None): """ 非化学类的 :return: """ try: document_root = os.path.join(BASE_DIR, 'document') filepath = document_root + "/fujian04_excel_format.xlsx" # system_type = platform.system() # if 'indows' in system_type: # filepath = "D:/PycharmProjects/lelingzdy/baoming/webapp/utils/fujian04_excel_format.xlsx" # else: # filepath = "/opt/python3_space/lelingzdy/baoming/webapp/utils/fujian04_excel_format.xlsx" original_data = pd.read_excel(filepath, encoding='utf-8') # rb打开该excel,formatting_info=True表示打开excel时并保存原有的格式 rb = xlrd.open_workbook(filepath, formatting_info=True) # 创建一个可写入的副本 wb = xlutils.copy.copy(rb) if not student_infos: student_infos = StudentInfo.objects.filter(confirm_status=1, chemical_worker=2) tmp_array = [] if len(student_infos) > 0: tmp_num = 0 for student in student_infos: identification_level = str(student.identification_level) if len(identification_level) > 0: identification_level = worker_level[str( student.identification_level)] else: identification_level = '' # 原证书编号 original_certificate_number = student.original_certificate_number if original_certificate_number: pass else: original_certificate_number = "" # 文化程度 education_degree = student.user_info.education_degree if education_degree: education_name = student.user_info.education_degree.education_name else: education_name = '' tmp_num = tmp_num + 1 # tmp_dict = {'index': str(tmp_num), # 'r_e': student.user_info.real_name, # 'id_number': student.user_info.id_number, # 'sa': get_sex(student.user_info.sex), # 'school': student.user_info.middle_school, # 'f_occ': student.declaration_of_occupation, # 's_w_d': student.user_info.start_working_date, # 'id_level': identification_level, # 'jsll': '', # 'sjcz': '', # 'o_cer_num': original_certificate_number, # 'issuance_time': issuance_time} # tmp_list.append(tmp_dict) # 原级别 primary_level = str(student.primary_level) if len(student.primary_level) > 0: primary_level = worker_level[str(student.primary_level)] else: primary_level = '' if student.user_info.start_working_date: start_working_date = date_encoder( student.user_info.start_working_date) else: start_working_date = '' if student.issuance_time: issuance_time = date_encoder(student.issuance_time) else: issuance_time = '' tmp_array.append([ tmp_num, student.user_info.real_name, student.user_info.id_number, get_sex(student.user_info.sex), '', education_name, student.declaration_of_occupation, start_working_date, identification_level, '', '', '', original_certificate_number, issuance_time ]) num = 0 print('len:::' + str(len(original_data))) for row in range(0, len(original_data)): if row > 3: out_sheet = wb.get_sheet(0) if num < len(tmp_array): set_out_cell(out_sheet, 0, row, tmp_array[num][0]) set_out_cell(out_sheet, 1, row, tmp_array[num][1]) set_out_cell(out_sheet, 2, row, tmp_array[num][2]) set_out_cell(out_sheet, 3, row, tmp_array[num][3]) set_out_cell(out_sheet, 4, row, tmp_array[num][4]) set_out_cell(out_sheet, 5, row, tmp_array[num][5]) set_out_cell(out_sheet, 6, row, tmp_array[num][6]) set_out_cell(out_sheet, 7, row, tmp_array[num][7]) set_out_cell(out_sheet, 8, row, tmp_array[num][8]) set_out_cell(out_sheet, 9, row, tmp_array[num][9]) set_out_cell(out_sheet, 10, row, tmp_array[num][10]) set_out_cell(out_sheet, 11, row, tmp_array[num][11]) set_out_cell(out_sheet, 12, row, tmp_array[num][12]) set_out_cell(out_sheet, 13, row, tmp_array[num][13]) else: set_out_cell(out_sheet, 0, row, num + 1) num = num + 1 day_string = str( time.strftime('%Y/%m/%d', time.localtime(time.time()))) file_root = MEDIA_ROOT + "/files/" day_files_path = file_root + 'reporter_chemical_not_list' + "/files/" + day_string if os.path.exists(day_files_path): pass else: os.makedirs(day_files_path) uuid_string = str(uuid.uuid4()) file_day_files_path = day_files_path + "/" + uuid_string + ".xlsx" wb.save(file_day_files_path) if os.path.exists(file_day_files_path): file_manage = FileManage() file_manage.file_name = "非化工类学员报名表-" + day_string file_manage.file_uuid = uuid_string file_manage.file_path = file_day_files_path file_manage.save() # 附件1 生成非化工类学员化名册成功, return str(file_manage.file_uuid) else: return None else: return None except Exception as e: print(e) raise e
def teacher_search_wait_review(request): student_search = StudentSearchForm(request.POST) user_search = UserInfoSearchForm(request.POST) school_terms = SchoolTerm.objects.filter().order_by('-id') school_terms_values = school_terms.values() tmp_list = [] if len(school_terms_values) > 0: for i in school_terms_values: tmp_json = {} tmp_json['id_str'] = i['id'] tmp_json['school_term_name'] = i['school_term_name'] tmp_json['school_term_start'] = date_encoder(i['school_term_start']) tmp_json['school_term_end'] = date_encoder(i['school_term_end']) tmp_list.append(tmp_json) teacher_info = TeacherInfo.objects.get( user_info__register_user_info__username=request.session.get('username', None)) last_school_term = SchoolTerm.objects.last() if student_search.is_valid(): if user_search.is_valid(): # 用户信息 kwargs = {} # kwargs['confirm_status'] = 1, # kwargs['chemical_worker'] = 1, user_info = UserInfo() real_name = user_search.cleaned_data.get('real_name', None) if real_name: user_info.real_name = real_name kwargs['user_info__real_name__icontains'] = real_name education_degree = user_search.cleaned_data.get('education_degree', None) if education_degree: user_info.education_degree = education_degree if type(education_degree) == str: if int(education_degree) > 0: kwargs['user_info__education_degree__id'] = int(education_degree) else: kwargs['user_info__education_degree__id'] = education_degree # 学生信息 student_info = StudentInfo() identification_level = student_search.cleaned_data.get('identification_level', None) declaration_of_occupation = student_search.cleaned_data.get('declaration_of_occupation', None) school_term = student_search.cleaned_data.get('school_term', None) if identification_level: student_info.identification_level = identification_level if type(identification_level) == str: if int(identification_level) > 0: kwargs['identification_level'] = int(identification_level) else: kwargs['identification_level'] = identification_level if declaration_of_occupation: student_info.declaration_of_occupation = declaration_of_occupation kwargs['declaration_of_occupation__icontains'] = declaration_of_occupation if school_term: if type(school_term) == str: if int(school_term) > 0: kwargs['school_term'] = int(school_term) student_info.school_term = SchoolTerm.objects.get(id=int(school_term)) else: kwargs['school_term'] = school_term student_info.school_term = SchoolTerm.objects.get(id=school_term) else: pass student_info.user_info = user_info print(kwargs) student_infos = StudentInfo.objects.filter(teacher_info=teacher_info, **kwargs).order_by('-id') paginator = Paginator(student_infos, 10) page = request.GET.get('page') contacts = paginator.get_page(page) title_msg = "学员报名资料(非化工)" if len(school_terms) <= 0: return render_result(request, "index.html", {'title_msg': title_msg, 'need_login': False, 'no_term': False}) else: # return render(request, "page_main_controller/teacher/report_student_info_list_teacher.html", # {'title_msg': title_msg, "contacts": contacts, 'student_info': student_info, # 'school_terms': school_terms,'no_term': True, # 'last_school_term': last_school_term, 'identification_level': identification_level}) return render_result(request, "page_main_controller/teacher/report_student_info_list_teacher.html", {'title_msg': title_msg, 'need_login': False, 'tmp_list': json.dumps(tmp_list, ensure_ascii=False), 'last_school_term': last_school_term, 'student_info': student_info, 'no_term': True, 'contacts': contacts, 'school_terms': school_terms, 'school_term': school_term, 'identification_level': identification_level}) else: print(user_search.error_class, user_search.errors) else: print(student_search.error_class, student_search.errors)
def electronic_communication_format(student_infos=None, skill_main_class_name=None, skill_main_class_code=None): """ 电子通信类 :return: """ try: document_root = os.path.join(BASE_DIR, 'document') filepath = document_root + "/electronic_communication_format.xlsx" # system_type = platform.system() # if 'indows' in system_type: # filepath = "D:/PycharmProjects/lelingzdy/baoming/webapp/utils/fujian04_excel_format.xlsx" # else: # filepath = "/opt/python3_space/lelingzdy/baoming/webapp/utils/fujian04_excel_format.xlsx" original_data = pd.read_excel(filepath, encoding='utf-8') # rb打开该excel,formatting_info=True表示打开excel时并保存原有的格式 rb = xlrd.open_workbook(filepath, formatting_info=True) # 创建一个可写入的副本 wb = xlutils.copy.copy(rb) if not student_infos: skill_main_classies = ReportSkillMainClass.objects.filter(skill_main_class_name__icontains='电子').\ filter(skill_main_class_name__icontains='通信').values('id') if len(skill_main_classies) > 0: print(skill_main_classies[0]) print(skill_main_classies[0]['id']) student_infos = StudentInfo.objects.filter( confirm_status=1, skill_main_class=skill_main_classies[0]['id']) # report_skills = ReportSkill.objects.filter(skill_main_class=skill_main_classies[0]).values('skill_id') # if len(report_skills) > 0: # report_conditions = ReportCondition.objects.filter(condition_for_skill__in=report_skills).values('condition_id') # student_infos = StudentInfo.objects.filter(confirm_status=1, condition_selected__in=report_conditions) # equipments = Equipment.objects.filter(rack__in = skill_main_classies) # student_infos = StudentInfo.objects.filter(confirm_status=1, chemical_worker=2) tmp_array = [] if len(student_infos) > 0: tmp_num = 0 for student in student_infos: identification_level = str(student.identification_level) if len(identification_level) > 0: identification_level = worker_level[str( student.identification_level)] else: identification_level = '' # 原证书编号 original_certificate_number = student.original_certificate_number if original_certificate_number: pass else: original_certificate_number = "" # 文化程度 education_degree = student.user_info.education_degree if education_degree: education_name = student.user_info.education_degree.education_name else: education_name = '' tmp_num = tmp_num + 1 # tmp_dict = {'index': str(tmp_num), # 'r_e': student.user_info.real_name, # 'id_number': student.user_info.id_number, # 'sa': get_sex(student.user_info.sex), # 'school': student.user_info.middle_school, # 'f_occ': student.declaration_of_occupation, # 's_w_d': student.user_info.start_working_date, # 'id_level': identification_level, # 'jsll': '', # 'sjcz': '', # 'o_cer_num': original_certificate_number, # 'issuance_time': issuance_time} # tmp_list.append(tmp_dict) # 原级别 primary_level = str(student.primary_level) if len(student.primary_level) > 0: primary_level = worker_level[str(student.primary_level)] else: primary_level = '' if student.user_info.start_working_date: start_working_date = date_encoder( student.user_info.start_working_date) else: start_working_date = '' if student.issuance_time: issuance_time = date_encoder(student.issuance_time) else: issuance_time = '' career_life = student.career_life original_certificate_worker_year = student.original_certificate_worker_year apprentice_year = student.apprentice_year apprentice_month = student.apprentice_month flag_working_time = False if student.identification_level == "3": working_year = '' elif student.identification_level == "4": if original_certificate_worker_year: if original_certificate_worker_year > 0: working_year = '' flag_working_time = True else: flag_working_time = True else: flag_working_time = True else: flag_working_time = True if flag_working_time: if not career_life: if apprentice_year: if apprentice_year > 0: working_year = str(apprentice_year) else: if apprentice_month: if apprentice_month > 0: working_year = str( apprentice_month) + "月" else: working_year = '' else: working_year = '' else: working_year = career_life else: pass # 文化程度 education_degree = student.user_info.education_degree if education_degree: education_name = student.user_info.education_degree.education_name else: education_name = '' # 身份证住址 rt_id_addr = RichText('') id_card_address = student.user_info.id_card_address if str(id_card_address).__len__() > 8: rt_id_addr.add(id_card_address, size=10) # 字体大小 elif str(id_card_address).__len__() > 13: rt_id_addr.add(id_card_address, size=8) # 字体大小 elif str(id_card_address).__len__() > 16: rt_id_addr.add(id_card_address, size=6) # 字体大小 else: rt_id_addr.add(id_card_address, size=14) # 字体大小 tmp_array.append([ student.declaration_of_occupation, #职业工种 identification_level, #级别 '', #身份类型 '', #证件号码 student.user_info.real_name, #中文名 '', #英文名 get_sex(student.user_info.sex), #性别 student.user_info.birthday, #生日 student.user_info.work_unit, #工作单位 '', #从事职业 student.user_info.nation_info.nation_name, #民族 str(working_year) + '年', #工作年限 education_name, #文化程度 student.user_info.start_working_date, #参加工作日期 '', #考生来源 '', #来源省份 '', #来源地区 '', #现役军人 '', #下岗人员 '', #失业人员 '', #残疾人员 '', #农民工 '', #两劳人员 '', #其他 '', #在校学生 student.user_info.contact_number, #联系电话 student.user_info.fixed_telephone, #手机 student.user_info.id_card_address, #身份地址 student.user_info.address, #常驻地址 '', #邮政编码 '', #政治面貌 '', #报名点 student.declaration_of_occupation, #鉴定科目 '', #鉴定类型 student.original_certificate_number, #原证书号 '', #申报条件 student.explain, #报名备注 '', #补贴类型 '', #补贴证件类型 '', #补贴证件号码 '' #预报考点 ]) num = 0 if len(original_data) == 0: row_data = len(tmp_array) else: row_data = len(original_data) for row in range(0, row_data): print(row) print('第几行.....') # if row > 0: out_sheet = wb.get_sheet(0) row = row + 1 if num < len(tmp_array): set_out_cell(out_sheet, 0, row, tmp_array[num][0]) set_out_cell(out_sheet, 1, row, tmp_array[num][1]) set_out_cell(out_sheet, 2, row, tmp_array[num][2]) set_out_cell(out_sheet, 3, row, tmp_array[num][3]) set_out_cell(out_sheet, 4, row, tmp_array[num][4]) set_out_cell(out_sheet, 5, row, tmp_array[num][5]) set_out_cell(out_sheet, 6, row, tmp_array[num][6]) set_out_cell(out_sheet, 7, row, tmp_array[num][7]) set_out_cell(out_sheet, 8, row, tmp_array[num][8]) set_out_cell(out_sheet, 9, row, tmp_array[num][9]) set_out_cell(out_sheet, 10, row, tmp_array[num][10]) set_out_cell(out_sheet, 11, row, tmp_array[num][11]) set_out_cell(out_sheet, 12, row, tmp_array[num][12]) set_out_cell(out_sheet, 13, row, tmp_array[num][13]) set_out_cell(out_sheet, 14, row, tmp_array[num][14]) set_out_cell(out_sheet, 15, row, tmp_array[num][15]) set_out_cell(out_sheet, 16, row, tmp_array[num][16]) set_out_cell(out_sheet, 17, row, tmp_array[num][17]) set_out_cell(out_sheet, 18, row, tmp_array[num][18]) set_out_cell(out_sheet, 19, row, tmp_array[num][19]) set_out_cell(out_sheet, 20, row, tmp_array[num][20]) set_out_cell(out_sheet, 21, row, tmp_array[num][21]) set_out_cell(out_sheet, 22, row, tmp_array[num][22]) set_out_cell(out_sheet, 23, row, tmp_array[num][23]) set_out_cell(out_sheet, 24, row, tmp_array[num][24]) set_out_cell(out_sheet, 25, row, tmp_array[num][25]) set_out_cell(out_sheet, 26, row, tmp_array[num][26]) set_out_cell(out_sheet, 27, row, tmp_array[num][27]) set_out_cell(out_sheet, 28, row, tmp_array[num][28]) set_out_cell(out_sheet, 29, row, tmp_array[num][29]) set_out_cell(out_sheet, 30, row, tmp_array[num][30]) set_out_cell(out_sheet, 31, row, tmp_array[num][31]) set_out_cell(out_sheet, 32, row, tmp_array[num][32]) set_out_cell(out_sheet, 33, row, tmp_array[num][33]) set_out_cell(out_sheet, 34, row, tmp_array[num][34]) set_out_cell(out_sheet, 35, row, tmp_array[num][35]) set_out_cell(out_sheet, 36, row, tmp_array[num][36]) set_out_cell(out_sheet, 37, row, tmp_array[num][37]) set_out_cell(out_sheet, 38, row, tmp_array[num][38]) set_out_cell(out_sheet, 39, row, tmp_array[num][39]) else: set_out_cell(out_sheet, 0, row, num + 1) num = num + 1 day_string = str( time.strftime('%Y/%m/%d', time.localtime(time.time()))) file_root = MEDIA_ROOT + "/files/" day_files_path = file_root + 'electronic_communication' + "/files/" + day_string if os.path.exists(day_files_path): pass else: os.makedirs(day_files_path) uuid_string = str(uuid.uuid4()) file_day_files_path = day_files_path + "/" + uuid_string + ".xlsx" wb.save(file_day_files_path) # 保存数据 print("系统::" + file_day_files_path) if os.path.exists(file_day_files_path): file_manage = FileManage() file_manage.file_name = "电子通信模板-" + day_string file_manage.file_uuid = uuid_string file_manage.file_path = file_day_files_path file_manage.save() # 附件1 生成非化工类学员化名册成功, return str(file_manage.file_uuid) else: return None else: return None except Exception as e: print(e) raise e
def report_info_review(request): """ 管理员确认学员信息列表 :param request: :return: """ title_msg = '学生填报信息待审核列表' username = request.session.get('username', None) # 用户名 register_user_infos = RegisterUserInfo.objects.filter(username=username) school_terms = SchoolTerm.objects.filter().order_by('-id') school_terms_values = school_terms.values() tmp_list = [] print(school_terms_values) if len(school_terms_values) > 0: for i in school_terms_values: tmp_json = {} tmp_json['id_str'] = i['id'] tmp_json['school_term_name'] = i['school_term_name'] tmp_json['school_term_start'] = date_encoder( i['school_term_start']) tmp_json['school_term_end'] = date_encoder(i['school_term_end']) tmp_list.append(tmp_json) print(tmp_list) if len(register_user_infos) > 0: register_user_info = register_user_infos[0] # 消息 user_info = UserInfo.objects.get(register_user_info=register_user_info) system_messages_receiver = SystemMessage.objects.filter( receiver=user_info, hidden_status_receiver=2).order_by('-id') not_confirm = system_messages_receiver.filter( feedback_status=2).count() # 消息 if register_user_info: user_infos = UserInfo.objects.filter( register_user_info=register_user_info) if len(user_infos) > 0: teacher_infos = TeacherInfo.objects.filter( user_info=user_infos[0]) if len(teacher_infos) > 0: student_infos = StudentInfo.objects.filter( record_status='1', teacher_info=teacher_infos[0]).order_by('-id') paginator = Paginator(student_infos, 10) # page = request.GET.get('page') page = 1 contacts = paginator.get_page(page) if len(school_terms) <= 0: return render_result( request, "index.html", { 'title_msg': title_msg, 'need_login': False, 'no_term': False }) else: last_school_term = SchoolTerm.objects.last() # return render(request, # "page_main_controller/teacher/report_student_info_list_teacher.html", # {'title_msg': title_msg, 'need_login': False,'school_terms': school_terms, # 'last_school_term': last_school_term, 'no_term': True, # 'contacts': contacts, 'not_confirm': not_confirm}) return render_result( request, "page_main_controller/teacher/report_student_info_list_teacher.html", { 'title_msg': title_msg, 'need_login': False, 'last_school_term': last_school_term, 'no_term': True, 'contacts': contacts, 'school_terms': school_terms, 'tmp_list': json.dumps(tmp_list, ensure_ascii=False), 'not_confirm': not_confirm, 'school_term': 0, 'identification_level': 0 }) # # return render(request, "page_main_controller/teacher/report_student_info_list_teacher.html", # {'title_msg': title_msg, "contacts": contacts}) else: message = '系统提示:获取当前用户基本信息失败,请重新登陆后尝试,或联系管理员' return render_result(request, "page_main_controller/message.html", { 'title_msg': title_msg, 'message': message }) else: message = '系统提示:获取当前用户失败,请重新登陆后尝试,或联系管理员.' return render_result(request, "page_main_controller/message.html", { 'title_msg': title_msg, 'message': message }) else: message = '系统提示:获取当前用户失败,请重新登陆后尝试,或联系管理员' return render_result(request, "page_main_controller/message.html", { 'title_msg': title_msg, 'message': message })
def search_parameter(request, search_type=None): teacher_tmp = None role_name = request.session.get('role_name', None) # 用户名 if role_name is not None: if role_name in 'teacher': username = request.session.get('username', None) # 用户名 if username: register_user_info = RegisterUserInfo.objects.get( username=username) user_info_tmp = UserInfo.objects.get( register_user_info=register_user_info) teacher_tmp = TeacherInfo.objects.get(user_info=user_info_tmp) else: pass print('role') print(role_name) print(teacher_tmp) title_msg = "所有学员的条件查询" student_search = StudentSearchForm(request.GET) user_search = UserInfoSearchForm(request.GET) page_search = PageSearchForm(request.GET) teacher_infos = TeacherInfo.objects.all() school_terms = SchoolTerm.objects.filter().order_by('-id') school_terms_values = school_terms.values() tmp_list = [] print(school_terms_values) if len(school_terms_values) > 0: for i in school_terms_values: tmp_json = {} tmp_json['id_str'] = i['id'] tmp_json['school_term_name'] = i['school_term_name'] tmp_json['school_term_start'] = date_encoder( i['school_term_start']) tmp_json['school_term_end'] = date_encoder(i['school_term_end']) tmp_list.append(tmp_json) print(tmp_list) per_page = 10 page = 1 if page_search.is_valid(): if page_search.cleaned_data.get('per_page', None): per_page = page_search.cleaned_data.get('per_page', None) if page_search.cleaned_data.get('page', None): page = page_search.cleaned_data.get('page', None) if student_search.is_valid(): if user_search.is_valid(): # 用户信息 kwargs = {} # kwargs['confirm_status'] = 1, # kwargs['chemical_worker'] = 1, user_info = UserInfo() real_name = user_search.cleaned_data.get('real_name', None) if real_name: user_info.real_name = real_name kwargs['user_info__real_name__icontains'] = real_name work_unit = user_search.cleaned_data.get('work_unit', None) if work_unit: user_info.work_unit = work_unit kwargs['user_info__work_unit__icontains'] = work_unit education_degree = user_search.cleaned_data.get( 'education_degree', None) if education_degree: user_info.education_degree = education_degree if type(education_degree) == str: if int(education_degree) > 0: kwargs['user_info__education_degree__id'] = int( education_degree) else: kwargs[ 'user_info__education_degree__id'] = education_degree # 学生信息 student_info = StudentInfo() identification_level = student_search.cleaned_data.get( 'identification_level', None) declaration_of_occupation = student_search.cleaned_data.get( 'declaration_of_occupation', None) teacher_info = student_search.cleaned_data.get( 'teacher_info', None) school_term = student_search.cleaned_data.get('school_term', None) if identification_level: student_info.identification_level = identification_level if type(identification_level) == str: if int(identification_level) > 0: kwargs['identification_level'] = int( identification_level) else: kwargs['identification_level'] = identification_level else: identification_level = 0 if declaration_of_occupation: student_info.declaration_of_occupation = declaration_of_occupation kwargs[ 'declaration_of_occupation__icontains'] = declaration_of_occupation student_infos_all_term_count = 0 if teacher_info: if teacher_info != 0: if type(teacher_info) == str: if int(teacher_info) > 0: kwargs['teacher_info'] = int(teacher_info) student_info.teacher_info = TeacherInfo.objects.get( id=int(teacher_info)) else: kwargs['teacher_info'] = teacher_info student_info.teacher_info = TeacherInfo.objects.get( id=teacher_info) student_infos_all_term_count = StudentInfo.objects.filter( teacher_info=teacher_info).count() else: if teacher_tmp: teacher_info = teacher_tmp else: teacher_info = 0 last_school_term = SchoolTerm.objects.last() if school_term: if type(school_term) == str: if int(school_term) > 0: kwargs['school_term'] = int(school_term) student_info.school_term = SchoolTerm.objects.get( id=int(school_term)) else: kwargs['school_term'] = school_term student_info.school_term = SchoolTerm.objects.get( id=school_term) else: if last_school_term: last_school_term = SchoolTerm.objects.last() school_term = last_school_term.id kwargs['school_term'] = school_term student_info.school_term = SchoolTerm.objects.get( id=school_term) report_skill_main_tmp = student_search.cleaned_data.get( 'skill_main_class', None) if report_skill_main_tmp: if type(report_skill_main_tmp) == str: if int(report_skill_main_tmp) > 0: kwargs['skill_main_class'] = int(report_skill_main_tmp) student_info.skill_main_class = report_skill_main_tmp else: kwargs['skill_main_class'] = report_skill_main_tmp student_info.report_skill_main = report_skill_main_tmp else: skill_main_class = 0 report_skill_tmp = student_search.cleaned_data.get( 'skill_main_class', None) if report_skill_tmp: if type(report_skill_tmp) == str: if int(report_skill_tmp) > 0: kwargs['report_skill'] = int(report_skill_tmp) student_info.report_skill = report_skill_tmp else: kwargs['report_skill'] = report_skill_tmp student_info.teacher_info = report_skill_tmp else: report_skill = 0 if report_skill_main_tmp: report_skill_main = report_skill_main_tmp else: report_skill_main = 0 if report_skill_tmp: report_skill = report_skill_tmp else: report_skill = 0 student_info.user_info = user_info print('rrrrrrrrrrrrrrrrrrr') print(kwargs) print(school_term) print(teacher_info) if search_type == 'teacher_search_wait_review': student_infos = StudentInfo.objects.filter( teacher_info=teacher_info, **kwargs).order_by('-id') else: student_infos = StudentInfo.objects.filter( **kwargs).order_by('-id') student_infos_all_term_count = StudentInfo.objects.filter( teacher_info=teacher_info).count() paginator = Paginator(student_infos, per_page) contacts = paginator.get_page(page) if teacher_tmp: teacher_info = teacher_tmp if len(school_terms) <= 0: return render_result(request, "index.html", { 'title_msg': title_msg, 'need_login': False, 'no_term': False }) else: param_result = { 'tmp_list': tmp_list, 'report_skill_main_list': report_skill_main_list, 'report_skill_list': report_skill_list, 'last_school_term': last_school_term, 'student_info': student_info, 'contacts': contacts, 'teacher_infos': teacher_infos, 'school_terms': school_terms, 'school_term': school_term, 'teacher_info': teacher_info, 'identification_level': identification_level, 'report_skill_main': report_skill_main, 'report_skill': report_skill, 'student_infos_all_term_count': student_infos_all_term_count, 'current_term_student_len': len(student_infos) } return param_result else: print(user_search.error_class, user_search.errors) message = '系统提示:获取当前用户失败,请重新登陆后尝试,或联系管理员.' else: print(student_search.error_class, student_search.errors) message = '系统提示:参数传输错误.' + str(student_search.errors) return render_result(request, "page_main_controller/message.html", { 'title_msg': title_msg, 'message': message })