Ejemplo n.º 1
0
def send_sms(request):
    task_list = request.json.get('task_list')
    if not task_list:
        task_list = []
    j_task = request.json.get('task')
    if j_task:
        task_list.append(j_task)

    token = request.json['token']
    uid = redis_get_uid_by_token(token)
    if uid is None:
        return JsonResponse({
            'success': False,
            'error_code': 'Token validate failed'
        })
    result_list = []
    # print task_list
    cur_user = User.objects.get(id=uid)
    for j_task in task_list:
        task = get_task(j_task)
        task.user_id = uid
        task.suffix = cur_user.suffix
        task.save()
        taskcount, id_list = send_task_prepare_sync(task)
        result_list.append({'count': taskcount, 'id_list': id_list})
    return JsonResponse({'success': True, 'result_list': result_list})
Ejemplo n.º 2
0
def get_token(request, code):
    timestamp = request.json['timestamp']
    nonce = request.json['nonce']
    signature = request.json['signature']
    user = get_user_by_code(code)
    if user is None:
        return JsonResponse({
            'success': False,
            'error_code': 'User not found or disabled'
        })
    key = get_key(user)

    if signature != get_sha1([timestamp, nonce, key]):
        return JsonResponse({
            'success': False,
            'error_code': 'Signature validate failed'
        })
    token = redis_get_token(user)
    if token:
        return JsonResponse({'success': True, 'token': token})
    else:
        return JsonResponse({
            'success': False,
            'error_code': 'The query is too frequent'
        })
Ejemplo n.º 3
0
def si_pay_close(request, si_pay_id):
    si_pay = model_filter(request, SI_Pay.objects.all()).get(id=si_pay_id)
    if si_pay.pay_stat != 'verify':
        return JsonResponse({'success': False, 'message': u'报账单的状态是已验证的才允许执行该操作!'})

    si_pay.pay_stat = 'close'
    si_pay.close_time = datetime.datetime.now()
    si_pay.save()
    return JsonResponse({'success': True, 'message': u'确认接收发票,报账单状态变为已关闭!'})
Ejemplo n.º 4
0
def user_reset_pass(request):
    obj = request.json['object']
    user = get_object(User, code=obj.get('code'))
    if user.pwd == obj.get('old_pwd'):
        user.pwd = obj.get('pwd')
        user.save()
        return JsonResponse({'success': True, 'message': '成功!'})
    else:
        return JsonResponse({'success': False, 'message': '原密码错误!'})
Ejemplo n.º 5
0
def si_pay_attach(request, si_pay_id):
    si_pay = model_filter(request, SI_Pay.objects.all()).get(id=si_pay_id)
    if si_pay.pay_stat == 'init':
        si_contract = si_pay_allot(si_pay)
        if si_contract:
            return JsonResponse({'success': True, 'message': u'已关联合同:' + unicode(si_contract)})
        else:
            return JsonResponse({'success': False, 'message': u'没有匹配的合同'})
    else:
        return JsonResponse({'success': False, 'message': u'已关联其他合同'})
Ejemplo n.º 6
0
def send_sms(request):
    j_user = request.json.get('user')
    user = api_login(j_user.get('code'), j_user.get('pass'))
    if user:
        j_task = request.json.get('task')
        task = get_task(j_task)
        task.user_id = user.id
        task.save()
        taskcount, id_list = send_task_prepare_sync(task)
        return JsonResponse({'success': True, 'result_list': id_list})
    else:
        return JsonResponse({
            'success': False,
            'error_code': 'User not found or disabled'
        })
Ejemplo n.º 7
0
def su(request):
    uid = request.json['object']['id']
    query = User.objects.filter(id=uid)
    if query.count() == 1:
        user = query[0]
        if user.stat == 'normal':
            dept_root = user.dept.root and user.dept.root or user.dept
            admin = get_object(dept_root.dept_user_set,
                               role__type='admin',
                               admin=dept_root)
            request.session['user'] = {
                'id': user.id,
                'name': user.name,
                'code': user.code,
                'type': user.role.type,
                'dept_id': user.dept.id,
                'dept_name': user.dept.name,
                'dept_path': user.dept.path,
                'dept_root_id': dept_root.id,
                'dept_root_name': dept_root.name,
                'admin_id': admin is not None and admin.id or None,
            }
    return JsonResponse({
        'success': True,
        'message': 'Success,Please press F5!'
    })
Ejemplo n.º 8
0
def user_logout(request):
    if 'user' in request.session:
        request.session.pop('user')
        request.session.pop('urls')
    success = True
    message = '注销成功!'
    return JsonResponse({'success': success, 'message': message})
Ejemplo n.º 9
0
def si_pay_package_rest(request):
    package = request.json.get('object').get('package')
    si_pay_list = model_filter(request, SI_Pay.objects.all().filter(pay_stat='close', package__isnull=True))
    for si_pay in si_pay_list:
        si_pay.package = package
        si_pay.save()
    return JsonResponse({'success': True, 'message': u'报帐批次%s新建成功,报账单数量%s!' % (package, si_pay_list.count())})
Ejemplo n.º 10
0
def msg_send_count(request):
    now = datetime.datetime.now()
    month = now.month
    model1 = load_cls('sms.models.MsgSend')
    model2 = load_cls('sms.models.MsgSend%02d' % month)
    now = datetime.datetime.strptime(now.strftime('%Y%m%d%H' + '0000'),
                                     '%Y%m%d%H%M%S')
    now = now + datetime.timedelta(hours=1)
    lastday = now - datetime.timedelta(hours=24)
    hour_count = [0] * 24
    for model in [model1, model2]:
        qs = model.objects.filter(msg_ack_time__lt=now,
                                  msg_ack_time__gte=lastday)
        qs = model_filter(request, qs)
        data_set = qs.extra(select={
            'hour': 'EXTRACT(hour from msg_ack_time)'
        }).values('hour').annotate((Count('id')))
        for data in data_set:
            hour_count[data['hour']] += data['id__count']
    result_set = []
    for hour in range(now.hour, 24) + range(now.hour):
        result = {'hour': str(hour), 'count': hour_count[hour]}
        result_set.append(result)
    return JsonResponse({
        'object_count': len(result_set),
        'object_list': result_set
    })
Ejemplo n.º 11
0
def grp_tree(request):
    grp_list = AddressGroup.objects.all()
    grp_list = model_filter(request, grp_list)

    dept_list = Dept.objects.all().filter(
        root_id=request.session.get('user').get('dept_root_id'))

    addr_grp_tree = get_grp_tree(dept_list, grp_list, [], None)

    return JsonResponse(addr_grp_tree)
Ejemplo n.º 12
0
def role_perm(request):
    obj = request.json['role']
    role = get_object(Role, pk=obj.get('id'))
    role_perm_list = role.perm.all()
    perm_list = Permission.objects.all()

    model_check(request, role)
    perm_list = model_filter(request, perm_list)

    perm_tree = get_perm_tree_checked(perm_list, role_perm_list, [], None)
    return JsonResponse(perm_tree)
Ejemplo n.º 13
0
def user_perm(request):
    user = request.session.get('user')
    user = User.objects.get(pk=user.get('id'))

    perm_list = Permission.objects.all()
    perm_list = model_filter(request, perm_list)

    menu_list, ajax_list = menu_or_ajax(perm_list)
    request.session['urls'] = [ajax.value for ajax in ajax_list]

    perm_tree = get_perm_tree(menu_list, visited=[], root=None)
    return JsonResponse(perm_tree)
Ejemplo n.º 14
0
def si_pay_verify(request, si_pay_id):
    si_pay = model_filter(request, SI_Pay.objects.all()).get(id=si_pay_id)
    if si_pay.pay_stat != 'allot':
        return JsonResponse({'success': False, 'message': u'报账单的状态是已分配的才允许执行该操作!'})

    tax_del_sum = 0
    tax_add_sum = 0
    for si_invoice in si_pay.si_invoice_set.all():
        tax_del_sum += si_invoice.tax_del
        tax_add_sum += si_invoice.tax_add
        if si_invoice.tax_rate != si_pay.tax_rate:
            return JsonResponse({'success': False, 'message': u'发票%s税率与报表不一致!' % (si_invoice.no)})
            # if si_invoice.si_name not in [si_pay.si_name, si_pay.si_name.replace('VSP', '')]:
            #    return JsonResponse({'success': False, 'message': u'发票%s供应商名称与报表不一致!' % (si_invoice.no)})
    if tax_del_sum != si_pay.tax_del:
        return JsonResponse({'success': False, 'message': u'发票不含税价合计与报表不一致!'})
    if abs(tax_add_sum - si_pay.tax_add) > 0.2:
        return JsonResponse({'success': False, 'message': u'发票含税价合计与报表差异过大!'})
    if len(SI_EmptyPay.objects.all()) == 0:
        return JsonResponse({'success': False, 'message': u'空报账单号码资源不足,请联系部门报帐员!'})

    si_emptypay = SI_EmptyPay.objects.all()[0]
    si_pay.pay_no = si_emptypay.pay_no
    si_emptypay.delete()

    si_pay.pay_stat = 'verify'
    si_pay.verify_time = datetime.datetime.now()
    si_pay.save()
    return JsonResponse({'success': True, 'message': u'验证发票成功,可打印黏贴单!'})
Ejemplo n.º 15
0
def test(request, key):
    key = get_key_with_len(key)
    timestamp = str(time.time())
    nonce = get_random_str()
    signature = get_sha1([timestamp, nonce, key])
    return JsonResponse({
        'success': True,
        'msg': {
            'timestamp': timestamp,
            'nonce': nonce,
            'signature': signature
        }
    })
Ejemplo n.º 16
0
def recv_sms(request):
    token = request.json['token']
    uid = redis_get_uid_by_token(token)
    if uid is None:
        return JsonResponse({
            'success': False,
            'error_code': 'Token validate failed'
        })
    if redis_get_traffic_control(uid):
        redis_set_traffic_control(uid, ex=30)
        return JsonResponse({
            'success': False,
            'error_code': 'The query is too frequent'
        })
    sms_list = []
    for i in range(100):
        msg = redis_pop_obj('recv_sms', uid)
        if msg is None:
            break
        else:
            sms_list.append(msg)
    if not sms_list:
        redis_set_traffic_control(uid)
    return JsonResponse({'success': True, 'sms_list': sms_list})
Ejemplo n.º 17
0
def role_perm_update(request):
    obj = request.json['role']
    ids = request.json['ids']
    role = get_object(Role, pk=obj.get('id'))
    if ids:
        id_list = ids.split(',')
    else:
        id_list = []
    perm_list = Permission.objects.all().filter(id__in=[id for id in id_list])

    model_check(request, role)
    perm_list = model_filter(request, perm_list)

    role.perm = perm_list
    return JsonResponse({'success': True, 'message': '成功!'})
Ejemplo n.º 18
0
def addr_file(request):
    j_addr = request.json['object']
    j_file = request.FILES['object.file']
    print dir(j_file)
    file = AddressFile(
        name=j_file.name,
        file=j_file,
        group=get_object(AddressGroup, pk=j_addr.get('group_id')),
    )

    model_default(request, file)
    model_check(request, file)

    file.save()

    addr_file_process.delay(file.id)

    return JsonResponse({'success': True, 'message': '成功!'})
Ejemplo n.º 19
0
def si_pay_upload(request):
    obj = request.json.get('object')
    data = obj.get('file').read()
    tempfile = TempFile()
    tempfile.write_and_save(data)
    wb = xlrd.open_workbook(tempfile.path)
    ws = wb.sheet_by_name(u'省级集团客户业务分SI结算表')
    month = None
    count = 0
    for rowx in range(100):
        if ws.cell(rowx, 0).value.startswith(u'开始周期: '):
            month = re.findall(r'\d{6}', ws.cell(rowx, 0).value)[0]
            break
    for rowx in range(rowx + 1, 100):
        if ws.cell(rowx, 0).value == u'石家庄':
            break
    for rowx in range(rowx, 100):
        if not ws.cell(rowx, 1).value:
            break
        try:
            si_pay = SI_Pay.objects.get(prd_name=ws.cell(rowx, 1).value, si_name=ws.cell(rowx, 3).value, month=month)
        except:
            si_pay = SI_Pay()
        si_pay.prd_name = ws.cell(rowx, 1).value
        si_pay.prd_code = str(int(ws.cell(rowx, 2).value))
        si_pay.si_name = ws.cell(rowx, 3).value
        si_pay.tax_rate = str(int(ws.cell(rowx, 4).value * 100)) + '%'
        si_pay.tax_add_raw = ws.cell(rowx, 9).value
        si_pay.tax_del_raw = ws.cell(rowx, 10).value
        si_pay.tax_raw = ws.cell(rowx, 11).value
        si_pay.adjust = ws.cell(rowx, 12).value  # 8
        si_pay.tax_add = ws.cell(rowx, 13).value  # 9
        si_pay.tax_del = ws.cell(rowx, 14).value  # 10
        si_pay.tax = ws.cell(rowx, 15).value  # 11
        si_pay.tax_compute = ws.cell(rowx, 16).value  # 12
        si_pay.month = month
        if not si_pay.user:
            si_pay.user_id = request.session.get('user').get('id')
        si_pay.save()
        count += 1
        if si_pay.pay_stat == 'init':
            si_pay_allot(si_pay)
    tempfile.close()
    return JsonResponse({'success': True, 'message': u'成功上传%s份报账单' % count})
Ejemplo n.º 20
0
def user_login(request):
    obj = request.json['object']

    query = User.objects.filter(code=obj['code'])
    success = False
    message = ""
    if query.count() == 1:
        user = query[0]
        if user.pwd == obj['pwd']:
            if user.stat == 'normal':
                if request.session.get('verify_expire', 0) > time.time():
                    if request.session.get('verify_code') == obj.get('verify'):
                        request.session.pop('verify_expire')
                        request.session.pop('verify_code')
                        dept_root = user.dept.root and user.dept.root or user.dept
                        admin = get_object(dept_root.dept_user_set,
                                           role__type='admin',
                                           admin=dept_root)
                        request.session['user'] = {
                            'id': user.id,
                            'name': user.name,
                            'code': user.code,
                            'type': user.role.type,
                            'dept_id': user.dept.id,
                            'dept_name': user.dept.name,
                            'dept_path': user.dept.path,
                            'dept_root_id': dept_root.id,
                            'dept_root_name': dept_root.name,
                            'admin_id': admin is not None and admin.id or None,
                        }
                        success = True
                    else:
                        message = '验证码错误!'
                else:
                    message = "验证码过期!"
            else:
                message = "账户被锁定!"
        else:
            message = "密码错误!"
    else:
        message = "账号不存在!"

    return JsonResponse({'success': success, 'message': message})
Ejemplo n.º 21
0
def user_verify(request, method):
    obj = request.json['object']

    query = User.objects.filter(code=obj['code'])
    success = False
    user = None
    if query.count() == 1:
        user = query[0]
        if user.pwd == obj['pwd']:
            if user.stat == 'normal':
                success = True
            else:
                message = "账户被锁定!"
        else:
            message = "密码错误!"
    else:
        message = "账号不存在!"

    verify_code = get_random_num(6)
    request.session['verify_code'] = verify_code
    request.session['verify_expire'] = time.time() + 60 * 5

    if success:
        if method == 'sms' and user_has_cmpp2cfg(user):
            j_task = {
                'type': 'default',
                'name': '系统验证码',
                'priority': 1,
                'content': verify_code,
                'phones': user.phone,
                'suffix': user.suffix,
            }
            task = get_task(j_task)
            task.user_id = user.id
            task.save()
            send_task_prepare_sync(task)
            message = '获取短信验证码成功!'
        else:  # elif method == 'email':
            send_mail([user.email], u'系统验证码', verify_code)
            message = '获取Email验证码成功!'
    return JsonResponse({'success': success, 'message': message})
Ejemplo n.º 22
0
    def decorator(*args, **kwargs):
        request, args = args[0], args[1:]
        function(request, *args, **kwargs)

        return JsonResponse({'success': True, 'message': '操作成功!'})
Ejemplo n.º 23
0
    def decorator(*args, **kwargs):
        request, args = args[0], args[1:]
        json = request.json

        export = kwargs.get('export')
        if 'export' in kwargs:
            kwargs.pop('export')

        if export == None:
            page = int(json['page'])
            start = int(json['start'])
            limit = int(json['limit'])

        query = json.get('query')

        query_field = kwargs.get('query_field', [])
        if 'query_field' in kwargs:
            kwargs.pop('query_field')

        hide_field = kwargs.get('hide_field', [])
        if 'hide_field' in kwargs:
            kwargs.pop('hide_field')

        order_by = kwargs.get('order_by', None)
        if 'order_by' in kwargs:
            kwargs.pop('order_by')

        qs = function(request, *args, **kwargs)

        if query:
            q = Q(**{'id' + '__contains': query})
            for field in query_field:
                q = q | Q(**{field + '__contains': query})
            qs = qs.filter(q)

        if order_by:
            qs = qs.order_by(order_by)

        if export == None:
            obj_count = qs.count()
            model_list = qs[start:limit + start]
        else:
            model_list = qs

        obj_list = []
        model = None
        for model in model_list:
            if isinstance(model, Model):
                obj = model.__dict__
                for key in obj.keys():
                    if hasattr(model, 'get_%s_display' % key):
                        obj[key + '_display'] = getattr(
                            model, 'get_%s_display' % key)()
                    if key.endswith('_id'):
                        key = key[:-3]
                        if hasattr(model, key):
                            val = getattr(model, key)
                            if isinstance(val, Model):
                                obj[key] = str(val)
                if 'name' not in obj:
                    obj['name'] = unicode(model)
            else:  # model is dict
                obj = model
            for key in obj.keys():
                if key.startswith('_') or key in hide_field:
                    obj.pop(key)
            obj_list.append(obj)

        if export == None:
            return JsonResponse({
                'object_list': obj_list,
                'object_count': obj_count
            })
        else:
            return export_excel(model, obj_list)
Ejemplo n.º 24
0
def user_info(request):
    user = request.session.get('user')
    return JsonResponse({'user': user})