Ejemplo n.º 1
0
    def bulk_init(self, request):
        user = self.request.session.get('user_info')
        current_user_id = user.get('id')
        pks = request.POST.get('pks')
        pks = pks.split(',')
        if not pks:
            return XStarkErrorResponse('pk 参数错误').json()
        num = 0
        for nid in pks:
            courserecord = CourseRecord.objects.get(id=nid)

            exists = StudyRecord.objects.filter(
                course_record=courserecord).exists()
            if exists:
                continue

            stu_list = Student.objects.filter(classinfo=courserecord.classinfo)
            study_record_list = []
            for stu in stu_list:
                study_record_list.append(
                    StudyRecord(course_record=courserecord, student=stu))
                num += 1

            StudyRecord.objects.bulk_create(study_record_list)
        return XStarkSuccessResponse('初始化成功,执行%s次' % (str(num))).json()
Ejemplo n.º 2
0
 def bulk_reset(self, request):
     from django.contrib.auth.hashers import make_password
     pks = request.POST.get('pks')
     if not pks:
         return XStarkErrorResponse('pk 参数错误').json()
     password = request.POST.get('password') or settings.DEFAULT_PWD
     new_pwd = make_password(password, hasher='pbkdf2_sha256')
     UserInfo.objects.filter(pk__in=pks.split(',')).update(password=new_pwd)
     return XStarkSuccessResponse(new_pwd).json()
Ejemplo n.º 3
0
 def bulk_remove(self, request):
     pks = request.POST.get('pks')
     pks = pks.split(',')
     if not pks:
         return XStarkErrorResponse('pk 参数错误').json()
     user = self.request.session.get('user_info')
     current_user_id = user.get('id')
     Customer.objects.filter(id__in=pks, status=2, consultant_id=current_user_id).update(consultant=None)
     return XStarkSuccessResponse('已经移除成功').json()
Ejemplo n.º 4
0
 def bulk_reset_view(self, request):
     from django.urls import reverse
     entities = request.POST.getlist('pk')
     if not request.POST.getlist('pk'):
         return XStarkErrorResponse('请选择一项').json()
     return XStarkSuccessResponse(dialog=render_to_string('system/reset_pwd.html', {
         'action': reverse('xstark:system_userinfo_reset'),
         'form': ResetPwdForm({'pks': ','.join(entities)}),
         'users': UserInfo.objects.filter(pk__in=entities).values('name')
     }, request=request), title='将为%s位用户重置密码' % len(entities)).json()
Ejemplo n.º 5
0
    def bulk_apply(self, request):
        """
        申请客户
        :param request:
        :return:
        """
        user = self.request.session.get('user_info')
        current_user_id = user.get('id')
        pks = request.POST.get('pks')
        pks = pks.split(',')
        if not pks:
            return XStarkErrorResponse('pk 参数错误').json()
        # 事务
        with transaction.atomic():
            origin = Customer.objects.filter(pk__in=pks, consultant__isnull=True).select_for_update()
            if len(origin) == len(pks):
                Customer.objects.filter(pk__in=pks).update(consultant_id=current_user_id)
                return XStarkSuccessResponse('申请成功').json()

        return XStarkErrorResponse('已被其他顾问申请(手速太慢)').json()
Ejemplo n.º 6
0
    def bulk_apply_view(self, request):
        """
        申请客户
        :param request:
        :return:
        """
        entities = request.POST.getlist('pk')
        user = self.request.session.get('user_info')
        current_user_id = user.get('id')

        privates = Customer.objects.filter(consultant_id=current_user_id, status=2).count()

        if (privates + len(entities)) > settings.MAX_PRIVATE_CUSTOMER:
            return XStarkErrorResponse('做人别太贪心').json()
        return XStarkSuccessResponse(dialog=render_to_string('service/action_confirm.html', {
            'action': reverse('xstark:service_customer_pub_apply'),
            'pks':  ','.join(entities),
            'entities': [item['name'] for item in Customer.objects.filter(pk__in=entities).values('name')],
            'submit_text': '确认申请'
        }, request=request), title='将申请以下%s位用户' % len(entities)).json()
Ejemplo n.º 7
0
    def bulk_init_view(self, request):
        """
        批量初始化
        :param request:
        :return:
        """
        entities = request.POST.getlist('pk')
        if not request.POST.getlist('pk'):
            return XStarkErrorResponse('请选择一项').json()
        # 找到选中上课记录的班级
        # 找到班级下所有人
        # 为每个人生成一条学习记录
        options = []
        for nid in entities:
            _entity = CourseRecord.objects.get(id=nid)

            exists = StudyRecord.objects.filter(course_record=_entity).exists()
            if exists:
                continue
            options.append({
                'title':
                '%s S%s Day%s' % (_entity.classinfo.course.title,
                                  _entity.classinfo.semester, _entity.day_num),
                'entities': [
                    item['customer__name'] for item in Student.objects.filter(
                        classinfo=_entity.classinfo).values('customer__name')
                ]
            })

        return XStarkSuccessResponse(dialog=render_to_string(
            'service/action_confirm.html', {
                'action': reverse('xstark:service_courserecord_init'),
                'pks': ','.join(entities),
                'entities_set': options,
                'submit_text': '确认初始化'
            },
            request=request),
                                     title='将为%s位用户初始化上课记录' %
                                     len(entities)).json()