class ClassesHandler(PermissionHandler, StartXHandler): model_form_class = ClassesModelForm def display_course(self, model=None, is_header=None, *args, **kwargs): if is_header: return '班级' return '%s(%s期)' % (model.course.name, model.semester) def display_classes_record(self, model=None, is_header=None, *args, **kwargs): if is_header: return '上课记录' record_url = reverse('startX:generic_courserecord_list', kwargs={'class_id': model.pk}) return mark_safe('<a target="_blank" href="%s">上课记录</a>' % record_url) list_display = [ 'school', display_course, get_datetime_format('开班日期', 'start_date'), 'class_teacher', display_classes_record, get_m2m_display('任课老师', 'tech_teachers'), 'price' ] search_list = [ 'course__contains', 'semester__contains', 'school__contains' ] search_group = [ Option('school'), Option('course'), ]
class QuestionHandler(PermissionHandler, StartXHandler): model_form_class = QuestionModelForm def get_add_btn(self, request, *args, **kwargs): return None def get_urls(self): """预留的重新自定义url钩子函数,主要是覆盖掉默认的url,并设置name别名""" patterns = [ re_path(r'^list/$', self.wrapper(self.changelist), name=self.get_list_name), re_path(r'^change/(?P<pk>\d+)/$', self.wrapper(self.change_view), name=self.get_change_name), ] patterns.extend(self.extra_url()) return patterns list_display = ['student', 'question', get_datetime_format('提问时间', 'question_date'), 'tutor', 'answer', get_datetime_format('回答时间', 'answer_date') ] search_list = ['title__contains'] def get_list_display(self, request, *args, **kwargs): """ 预留的钩子函数 :return: 为不同权限的用户设置预留的扩展,自定义显示列 """ value = [] if self.list_display: value.extend(self.list_display) value.append(type(self).display_edit) return value def get_model_queryset(self, request, *args, **kwargs): user_id = request.session['userinfo']['id'] return self.model_class.objects.filter(tutor__account_id=user_id)
class ConsultRecordHandler(PermissionHandler, StartXHandler): model_form_class = ConsultRecordModelForm order_by = ['-date', 'id'] list_display = [ 'student', 'consultant', 'note', get_datetime_format('跟进日期', 'date') ] def get_urls(self): """预留的重新自定义url钩子函数,主要是覆盖掉默认的url,并设置name别名""" patterns = [ re_path(r'^list/(?P<student_id>\d+)/$', self.wrapper(self.changelist), name=self.get_list_name), re_path(r'^add/(?P<student_id>\d+)/$', self.wrapper(self.add_view), name=self.get_add_name), re_path(r'^change/(?P<student_id>\d+)/(?P<pk>\d+)/$', self.wrapper(self.change_view), name=self.get_change_name), ] patterns.extend(self.extra_url()) return patterns def save(self, request, form, is_update, *args, **kwargs): student_id = kwargs.get('student_id') student_obj = models.Student.objects.filter(id=student_id).first() if not student_obj: return HttpResponse('非法操作') tutor = student_obj.tutor if not is_update: form.instance.student = student_obj.account form.instance.consultant = tutor form.save() def get_list_display(self, request, *args, **kwargs): """ 预留的钩子函数 :return: 为不同权限的用户设置预留的扩展,自定义显示列 """ value = [] if self.list_display: value.extend(self.list_display) value.append(type(self).display_edit) return value def display_edit(self, model=None, is_header=None, *args, **kwargs): if is_header: return '操作' student_id = kwargs.get('student_id') tpl = '<a href="%s">编辑</a>' % self.reverse_change_url( pk=model.pk, student_id=student_id) return mark_safe(tpl)
class ArticleHandler(PermissionHandler, StartXHandler): model_form_class = ArticleModelForm order_by = [ 'date', '-id', ] list_display = [ 'title', 'content', get_datetime_format('发布日期', 'date'), ] search_list = ['title__contains']
class PaymentRecordHandler(PermissionHandler, StartXHandler): def get_add_btn(self, request, *args, **kwargs): return None order_by = ['-id'] list_display = [ StartXHandler.display_checkbox, 'account', 'paid_fee', 'course', get_field_display('交易类型', 'pay_type'), get_field_display('申请状态', 'confirm_status'), get_datetime_format('申请日期', 'apply_date'), get_datetime_format('确认日期', 'confirm_date'), 'confirm_user', 'note' ] def get_urls(self): """预留的重新自定义url钩子函数,主要是覆盖掉默认的url,并设置name别名""" patterns = [ re_path(r'^list/(?P<account_id>\d+)/$', self.wrapper(self.changelist), name=self.get_list_name), re_path(r'^change/(?P<account_id>\d+)/(?P<pk>\d+)/$', self.wrapper(self.change_view), name=self.get_change_name), ] patterns.extend(self.extra_url()) return patterns def display_edit(self, model=None, is_header=None, *args, **kwargs): if is_header: return '操作' account_id = kwargs.get('account_id') tpl = '<a href="%s">编辑</a>' % self.reverse_change_url( pk=model.pk, account_id=account_id) return mark_safe(tpl) def get_list_display(self, request, *args, **kwargs): """ 预留的钩子函数 :return: 为不同权限的用户设置预留的扩展,自定义显示列 """ value = [] if self.list_display: value.extend(self.list_display) value.append(type(self).display_edit) return value def get_model_queryset(self, request, *args, **kwargs): account_id = kwargs.get('account_id') return self.model_class.objects.filter(account_id=account_id) def action_multi_check(self, request, *args, **kwargs): """ 批量审批学生状态,审核确认入学 :return: """ pk_list = request.POST.getlist('pk') # 修改状态即可 for pk in pk_list: payment_obj = self.model_class.objects.filter( id=pk, confirm_status=1).first() if not payment_obj: continue payment_obj.confirm_status = 2 payment_obj.confirm_date = now() # 审批人 payment_obj.save() payment_obj.account.level = 2 payment_obj.account.save() payment_obj.account.student.student_status = 2 payment_obj.account.student.save() action_multi_check.text = "批量确认入学" def action_multi_cancel(self, request, *args, **kwargs): """ 批量审批学生状态,审核驳回 :return: """ pk_list = request.POST.getlist('pk') # 修改状态即可 for pk in pk_list: payment_obj = self.model_class.objects.filter( id=pk, confirm_status=1).first() if not payment_obj: continue payment_obj.confirm_status = 3 payment_obj.save() action_multi_cancel.text = "批量驳回申请" def action_multi_drop_out(self, request, *args, **kwargs): """ 批量审批学生状态,审核退学 :return: """ pk_list = request.POST.getlist('pk') # 修改状态即可 for pk in pk_list: payment_obj = self.model_class.objects.filter( id=pk, confirm_status=2).first() if not payment_obj: continue payment_obj.account.level = 3 payment_obj.account.save() payment_obj.account.student.student_status = 4 payment_obj.account.student.save() action_multi_drop_out.text = "批量退学" def action_multi_graduation(self, request, *args, **kwargs): """ 批量审批学生状态,审核确认毕业 :return: """ pk_list = request.POST.getlist('pk') # 修改状态即可 for pk in pk_list: payment_obj = self.model_class.objects.filter( id=pk, confirm_status=2).first() if not payment_obj: continue payment_obj.account.student.student_status = 3 payment_obj.account.student.save() action_multi_graduation.text = "批量毕业" action_list = [ action_multi_check, action_multi_cancel, action_multi_drop_out, action_multi_graduation ]
class OrderHandler(PermissionHandler, StartXHandler): order_by = ['-id'] def get_add_btn(self, request, *args, **kwargs): return None def display_orderdetail(self, model=None, is_header=None, *args, **kwargs): if is_header: return '订单详情' record_url = reverse('startX:generic_orderdetail_list', kwargs={'order_id': model.pk}) return mark_safe('<a target="_blank" href="%s">订单详情</a>' % record_url) def display_paymentrecord(self, model=None, is_header=None, *args, **kwargs): if is_header: return '缴费申请' record_url = reverse('startX:generic_paymentrecord_list', kwargs={'account_id': model.account_id}) return mark_safe('<a target="_blank" href="%s">缴费申请</a>' % record_url) def get_urls(self): """预留的重新自定义url钩子函数,主要是覆盖掉默认的url,并设置name别名""" patterns = [ re_path(r'^list/$', self.wrapper(self.changelist), name=self.get_list_name), re_path(r'^change/(?P<pk>\d+)/$', self.wrapper(self.change_view), name=self.get_change_name), ] patterns.extend(self.extra_url()) return patterns list_display = [ 'account', 'payment_amount', get_field_display('交易类型', 'payment_type'), get_field_display('订单状态', 'status'), get_datetime_format('生成时间', 'date'), get_datetime_format('付款时间', 'pay_time'), 'payment_number', 'order_nubmer', display_orderdetail, display_paymentrecord ] def get_list_display(self, request, *args, **kwargs): """ 预留的钩子函数 :return: 为不同权限的用户设置预留的扩展,自定义显示列 """ value = [] if self.list_display: value.extend(self.list_display) value.append(type(self).display_edit) return value search_list = [ 'account__contains', ]
class CourseRecordHandler(PermissionHandler, StartXHandler): model_form_class = CourseRecordModelForm def display_attendance(self, model=None, is_header=None, *args, **kwargs): if is_header: return '考勤' name = "%s:%s" % ( self.site.namespace, self.get_url_name('attendance'), ) attendance_url = reverse(name, kwargs={'course_record_id': model.pk}) tpl = '<a target="_blank" href="%s">考勤</a>' % attendance_url return mark_safe(tpl) def get_urls(self): """预留的重新自定义url钩子函数,主要是覆盖掉默认的url,并设置name别名""" patterns = [ re_path(r'^list/(?P<class_id>\d+)/$', self.wrapper(self.changelist), name=self.get_list_name), re_path(r'^add/(?P<class_id>\d+)/$', self.wrapper(self.add_view), name=self.get_add_name), re_path(r'^change/(?P<class_id>\d+)/(?P<pk>\d+)/$', self.wrapper(self.change_view), name=self.get_change_name), re_path(r'^del/(?P<class_id>\d+)/(?P<pk>\d+)/$', self.wrapper(self.delete_view), name=self.get_del_name), re_path(r'^attendance/(?P<course_record_id>\d+)/$', self.wrapper(self.attendance_view), name=self.get_url_name('attendance')), ] patterns.extend(self.extra_url()) return patterns def display_edit_del(self, model=None, is_header=None, *args, **kwargs): if is_header: return '操作' class_id = kwargs.get('class_id') tpl = '<a href="%s">编辑</a> <a href="%s">删除</a>' % ( self.reverse_change_url(pk=model.pk, class_id=class_id), self.reverse_delete_url(pk=model.pk, class_id=class_id)) return mark_safe(tpl) def get_model_queryset(self, request, *args, **kwargs): class_id = kwargs.get('class_id') return self.model_class.objects.filter(class_object_id=class_id) def save(self, request, form, is_update, *args, **kwargs): class_id = kwargs.get('class_id') if not is_update: form.instance.class_object_id = class_id form.save() def action_multi_init(self, request, *args, **kwargs): """ 批量初始化考勤记录 :param request: :param args: :param kwargs: :return: """ course_record_id_list = request.POST.getlist('pk') class_id = kwargs.get('class_id') class_object = models.Classes.objects.filter(id=class_id).first() if not class_object: return HttpResponse('班级不存在') student_object_list = class_object.student_set.all() for course_record_id in course_record_id_list: # 判断选择的上课记录是否合法 course_record_object = models.CourseRecord.objects.filter( id=course_record_id, class_object_id=class_id).first() if not course_record_object: continue # 判断此上课记录对应的考勤记录是否已经存在 study_record_exists = models.StudyRecord.objects.filter( course_record=course_record_object).exists() if study_record_exists: continue # 为每个学生在该天创建考勤记录 study_record_object_list = [ models.StudyRecord(student_id=stu.id, course_record_id=course_record_id) for stu in student_object_list ] models.StudyRecord.objects.bulk_create(study_record_object_list, batch_size=50) action_multi_init.text = '批量初始化考勤' action_list = [ action_multi_init, ] def attendance_view(self, request, course_record_id, *args, **kwargs): """ 考勤的批量设置 :param request: :param course_record_id: :param args: :param kwargs: :return: """ study_record_object_list = models.StudyRecord.objects.filter( course_record_id=course_record_id) study_model_formset = modelformset_factory(models.StudyRecord, form=StudyRecordModelForm, extra=0) if request.method == 'POST': formset = study_model_formset(queryset=study_record_object_list, data=request.POST) if formset.is_valid(): formset.save() return render(request, 'attendance.html', {'formset': formset}) formset = study_model_formset(queryset=study_record_object_list) return render(request, 'attendance.html', {'formset': formset}) list_display = [ StartXHandler.display_checkbox, 'class_object', 'day_num', 'teacher', get_datetime_format('日期', 'date'), display_attendance ]
class CheckPayMentHandler(PermissionHandler, StartXHandler): order_by = ['-id', 'confirm_status'] list_display = [StartXHandler.display_checkbox, 'customer', get_field_display('费用类型', 'pay_type'), 'paid_fee', 'classes', get_datetime_format('支付日期', 'apply_date'), get_field_display('确认状态', 'confirm_status'), 'consultant'] def get_urls(self): """只有查看和审批功能""" patterns = [ re_path(r'^list/$', self.wrapper(self.changelist), name=self.get_list_name), ] patterns.extend(self.extra_url()) return patterns def get_list_display(self, request, *args, **kwargs): """ 取消默认的编辑和删除 :return: 为不同权限的用户设置预留的扩展,自定义显示列 """ value = [] if self.list_display: value.extend(self.list_display) return value def get_add_btn(self, request, *args, **kwargs): """没有添加的功能""" return None def action_multi_check(self, request, *args, **kwargs): """ 批量审批确认 :return: """ pk_list = request.POST.getlist('pk') for pk in pk_list: payment_object = self.model_class.objects.filter(id=pk, confirm_status=1).first() if not payment_object: continue # 缴费记录 payment_object.confirm_status = 2 payment_object.save() # 客户表 payment_object.customer.status = 1 payment_object.customer.save() # 学生表 payment_object.customer.student.student_status = 2 payment_object.customer.student.save() action_multi_check.text = "批量确认" def action_multi_cancel(self, request, *args, **kwargs): """ 批量审批驳回 :return: """ pk_list = request.POST.getlist('pk') self.model_class.objects.filter(id__in=pk_list, confirm_status=1).update(confirm_status=3) action_multi_cancel.text = "批量驳回" def action_multi_drop_out(self, request, *args, **kwargs): """ 批量审批退学 :return: """ pk_list = request.POST.getlist('pk') for pk in pk_list: payment_object = self.model_class.objects.filter(id=pk, confirm_status=2).first() if not payment_object: continue # 客户表 payment_object.pay_type = 3 payment_object.save() # 学生表 payment_object.customer.student.student_status = 4 payment_object.customer.student.save() action_multi_drop_out.text = "批量退学" action_list = [action_multi_check, action_multi_cancel, action_multi_drop_out]