Esempio n. 1
0
class CheckPaymentHandler(PermissionHandler, Handler):

    order_list = ['-id', 'confirm_status']

    search_list = [
        'consultant__nickname__contains',
        'class_list__course__title__contains', 'customer__name__contains'
    ]

    search_group = [SearchOption('pay_type'), SearchOption('confirm_status')]

    def get_urls(self):
        patterns = [
            path('list/',
                 self.wrapper(self.list_view),
                 name=self.get_list_url_name),
        ]

        patterns.extend(self.extra_urls())

        return patterns

    def action_multi_check(self, request, *args, **kwargs):

        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.save()

            payment_obj.customer.status_choices = 1
            payment_obj.customer.save()

            payment_obj.customer.student.student_status = 2
            payment_obj.customer.student.save()

    action_multi_check.text = '批量确认'

    def action_multi_cancel(self, request, *args, **kwargs):

        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 = '批量驳回'

    action_list = [action_multi_check, action_multi_cancel]

    list_display = [
        Handler.display_checkbox, 'customer',
        get_choice_text('费用类型', 'pay_type'), 'paid_fee', 'class_list',
        get_datetime_text('缴费日期', 'apply_date'),
        get_choice_text('状态', 'confirm_status'), 'consultant'
    ]
Esempio n. 2
0
class ClassListHandler(PermissionHandler, Handler):

    has_add_btn = True
    model_form_class = ClassListModelForm
    search_list = ['school__title__contains', 'course__title__contains',]
    search_group = [SearchOption('school'), SearchOption('course')]

    def display_class(self, obj=None, is_header=None, *args, **kwargs):
        if is_header:
            return '班级'
        return '%s %s期' % (obj.course.title, obj.semester)

    def display_class_record(self, obj=None, is_header=None, *args, **kwargs):
        if is_header:
            return '上课记录'
        record_url = reverse('stark:web_courserecord_list', kwargs={'class_id': obj.pk})
        return mark_safe("<a target='_blank' href='%s'>上课记录</a>" % record_url)

    list_display = ['school', display_class, 'price', get_datetime_text('开班日期', 'start_date'), 'class_teacher',
                    get_m2m_text('任课老师', 'tec_teacher'), display_class_record, Handler.display_edit, Handler.display_del]
Esempio n. 3
0
class PayRecordHandler(PermissionHandler, Handler):

    has_add_btn = True

    def get_list_display(self, request, *args, **kwargs):

        value = []
        if self.list_display:
            value.extend(self.list_display)
        return value

    def get_urls(self):

        patterns = [
            re_path(r'^list/(?P<customer_id>\d+)/$',
                    self.wrapper(self.list_view),
                    name=self.get_list_url_name),
            re_path(r'^add/(?P<customer_id>\d+)/$',
                    self.wrapper(self.add_view),
                    name=self.get_add_url_name)
        ]

        patterns.extend(self.extra_urls())

        return patterns

    def get_queryset(self, request, *args, **kwargs):

        current_user_id = request.session['user_info']['id']
        customer_id = kwargs.get('customer_id')
        obj = self.model_class.objects.filter(
            customer__consultant_id=current_user_id, customer_id=customer_id)

        return obj

    def get_model_form_class(self, is_add, request, pk, *args, **kwargs):

        customer_id = kwargs.get('customer_id')
        student_exists = models.Student.objects.filter(
            customer_id=customer_id).exists()

        if not student_exists:
            return StudentPaymentRecordModel
        return PaymentModel

    def save(self, request, form, is_update, *args, **kwargs):

        current_user_id = request.session['user_info']['id']
        customer_id = kwargs.get('customer_id')

        obj_exists = models.Customer.objects.filter(
            id=customer_id, consultant_id=current_user_id).exists()

        if not obj_exists:
            return HttpResponse('非法操作')

        form.instance.customer_id = customer_id
        form.instance.consulant_id = current_user_id
        form.save()

        class_list = form.cleaned_data['class_list']
        fetch_student = models.Student.objects.filter(
            customer_id=customer_id).first()

        if not fetch_student:

            qq = form.cleaned_data['qq']
            mobile = form.cleaned_data['mobile']
            emergency_contract = form.cleaned_data[' emergency_contract']
            student_object = models.Student.objects.create(
                qq=qq,
                mobile=mobile,
                emergency_contract=emergency_contract,
                customer_id=customer_id)
            student_object.class_list.add(class_list.id)
        else:
            fetch_student.class_list.add(class_list.id)

    list_display = [
        get_choice_text('费用类型', 'pay_type'), 'paid_fee', 'class_list',
        get_datetime_text('申请日期', 'apply_date'), 'consultant',
        get_choice_text('状态', 'confirm_status')
    ]
Esempio n. 4
0
class ClassRecordHandler(PermissionHandler, Handler):
    has_add_btn = True

    model_form_class = CourseRecordModelForm

    def get_urls(self):
        patterns = [
            re_path(r'^list/(?P<class_id>\d+)/$',
                    self.wrapper(self.list_view),
                    name=self.get_list_url_name),
            re_path(r'add/(?P<class_id>\d+)/$',
                    self.wrapper(self.add_view),
                    name=self.get_add_url_name),
            re_path(r'^edit/(?P<class_id>\d+)/(?P<pk>\d+)/$',
                    self.wrapper(self.edit_view),
                    name=self.get_edit_url_name),
            re_path(r'^del/(?P<class_id>\d+)/(?P<pk>\d+)/$',
                    self.wrapper(self.del_view),
                    name=self.get_del_url_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_urls())

        return patterns

    def action_multi_init(self, request, *args, **kwargs):
        course_record_id_list = request.POST.getlist('pk')  # 选择的考勤记录id
        class_id = kwargs.get('class_id')
        class_obj = models.ClassList.objects.filter(id=class_id).first()

        if not class_obj:
            return HttpResponse('班级不存在!')
        student_obj_list = class_obj.student_set.all()  # 反向关联,查询班级的学生

        for course_record in course_record_id_list:

            # 判断对应班级的上课记录是否存在
            course_record_obj = models.CourseRecord.objects.filter(
                id=course_record, class_object_id=class_id).first()

            if not course_record_obj:
                continue

            # 判断对应的考勤记录是否存在
            student_record_obj = models.StudyRecord.objects.filter(
                course_record=course_record_obj).exists()
            if student_record_obj:
                continue

            # 创建考勤记录
            student_record_obj_list = [
                models.StudyRecord(student_id=stu.id,
                                   course_record_id=course_record)
                for stu in student_obj_list
            ]

            models.StudyRecord.objects.bulk_create(student_record_obj_list,
                                                   batch_size=50)

        return

    action_multi_init.text = '批量初始化考勤'

    action_list = [action_multi_init]

    def get_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 display_attendance(self, obj=None, is_header=None, *args, **kwargs):

        if is_header:

            return '考勤'
        name = '%s:%s' % (self.stark_site.namespace,
                          self.get_url_name('attendance'))
        attendance_url = reverse(name, kwargs={'course_record_id': obj.pk})

        return mark_safe("<a target='_blank' href='%s'>考勤</a>" %
                         attendance_url)

    def attendance_view(self, request, course_record_id, *args, **kwargs):

        student_record_obj_list = models.StudyRecord.objects.filter(
            course_record_id=course_record_id)
        student_model_formset = modelformset_factory(
            models.StudyRecord, form=StudentRecordModelForm, extra=0)

        if request.method == 'POST':
            formset = student_model_formset(queryset=student_record_obj_list,
                                            data=request.POST)

            if formset.is_valid():
                formset.save()

            return render(request, 'attendance.html', {'formset': formset})

        formset = student_model_formset(queryset=student_record_obj_list)

        return render(request, 'attendance.html', {'formset': formset})

    list_display = [
        Handler.display_checkbox, 'class_object', 'day_num', 'teacher',
        get_datetime_text('时间', 'date'), display_attendance,
        Handler.display_edit, Handler.display_del
    ]