Example #1
0
def edit(request):
    '''修改物料'''
    try:
        rp = request.POST
        # 检查物料工号是否重复
        mods = MASTER_MODEL.objects.filter(mat_no=rp['mat_no'],
                                           is_visible=True)
        if len(mods) and int(mods[0].id) != int(rp['id']):
            raise Material_exist_err

        # 写入物料数据
        new_mat = MASTER_MODEL.objects.get(id=rp['id'])
        new_mat.mat_no = rp['mat_no']
        new_mat.mat_name = rp['mat_name']
        new_mat.company = rp['company']
        new_mat.work_group = rp['work_group']
        new_mat.contact = rp['contact']
        new_mat.save()

        # 成功信息
        msg = '操作成功!已成功修改物料"%s"。' % new_mat.mat_name
        info_back = {'type': 1, 'msg': msg}
        return HttpResponse(json.dumps(info_back))

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #2
0
def menu_per(request):
    '''获取菜单树(当前权限范围)'''
    try:
        return get_menu(request, False)
    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #3
0
def change(request, model, field, value, opname, mname):
    '''修改条目状态通用方法
    change(request, MASTER_MODEL, 'is_enable', True, '启用', MASTER_NAME)
    '''
    try:
        # 解析并去重上传的id
        data = json.loads(request.POST['ids'])
        ids = set(data)  # 无序不重复集合

        # 修改条目
        for n in ids:
            g = model.objects.get(id=int(n))
            if g is not None:
                setattr(g, field, value)
                g.save()

        # 成功信息
        message = '操作成功!已成功%s %s 个%s。' % (opname, len(ids), mname)
        code = 1

    except Exception as e:
        errlog.errlog_add(request, str(e))
        message = '操作失败!错误:%s。' % str(e)
        code = 3

    finally:
        return restful.result(code=code, message=message)
Example #4
0
def add(request):
    '''新增施工单位'''
    try:
        rp = request.POST
        # 检查施工单位代码是否重复
        mods = MASTER_MODEL.objects.filter(cons_mark=rp['cons_mark'],
                                           is_visible=True)
        if len(mods):
            raise Constructor_exist_err
        new_cons = MASTER_MODEL()
        new_cons.cons_mark = rp['cons_mark']
        new_cons.cons_name = rp['cons_name']
        new_cons.manager = rp['manager']
        new_cons.tel = rp['tel']
        new_cons.save()
        # 成功信息
        msg = '操作成功!已成功添加施工单位"%s"。' % new_cons.cons_name
        info_back = {'type': 1, 'msg': msg}
        return HttpResponse(json.dumps(info_back))

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #5
0
def menu_all(request):
    '''获取菜单树(全部)'''
    try:
        return get_menu(request, True)
    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #6
0
def edit(request):
    '''修改角色'''
    try:
        rp = request.POST
        # 检查角色名是否重复
        mods = MASTER_MODEL.objects.filter(id=rp['id'], is_visible=True)
        if len(mods) and mods[0].id != int(rp['id']):
            raise Group_exist_err

        # 写入角色信息
        new_group = MASTER_MODEL.objects.get(id=rp['id'])
        new_group.group_name = rp['group_name']
        new_group.permission_account = str(rp['permission_account'])
        new_group.permission_moudle = str(rp['permission_moudle'])
        if int(rp.get('permission_edit_master', 0)):
            new_group.permission_edit_master = True
        else:
            new_group.permission_edit_master = False
        new_group.save()

        # 成功信息
        msg = '操作成功!已成功修改角色"%s"。' % new_group.group_name
        info_back = {'type': 1, 'msg': msg}
        return HttpResponse(json.dumps(info_back))

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #7
0
def tree(request):
    '''获取 周转库 树'''
    try:
        first_classes = []
        first_class_nodes = []
        second_class_nodes = []

        whs = Warehouse.objects.filter(is_visible=True, is_enable=True)
        for c in whs:
            first_classes.append(c.first_class)
        first_classes = list(set(first_classes))

        for f in first_classes:
            first_class_node = {
                'id': f,
                'text': f,
                'children': [],
            }
            first_class_nodes.append(first_class_node)

        for c in whs:
            second_class_node = {
                'id': c.second_class,
                'text': c.second_class,
                # 'children': [],
            }
            for fc in first_class_nodes:
                if c.first_class == fc['id']:
                    fc['children'].append(second_class_node)

        return HttpResponse(json.dumps(first_class_nodes))

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #8
0
def add(request):
    '''新增用户'''
    try:
        rp = request.POST
        # 检查用户名是否重复
        mods = MASTER_MODEL.objects.filter(user_name=rp['user_name'],
                                           is_visible=True)
        if len(mods):
            raise User_exist_err

        # 写入用户信息
        new_user = MASTER_MODEL()
        new_user.user_name = rp['user_name']
        new_user.real_name = rp['real_name']
        group = Group.objects.get(group_name=rp['group_name'])
        new_user.group = group
        new_user.department = rp.get('department', '')
        new_user.tel = rp.get('tel', '')
        new_user.password = PASSWORD_FIRST
        new_user.save()

        # 成功信息
        msg = '操作成功!已成功添加用户"%s"。' % new_user.user_name
        info_back = {'type': 1, 'msg': msg}
        return HttpResponse(json.dumps(info_back))

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #9
0
def logout(request):
    '''重新登陆'''
    try:
        request.session.flush()
        return redirect(reverse('login'))
    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #10
0
def constructor(request):
    '''加载施工单位管理页面'''
    try:
        return render(request, 'constructor.html')

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #11
0
def group(request):
    '''加载角色管理页面'''
    try:
        return render(request, 'group.html')

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #12
0
def loginlog(request):
    '''加载系统登录日志管理页面'''
    try:
        return render(request, 'loginlog.html')

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #13
0
def warehouse(request):
    '''加载周转库管理页面'''
    try:
        return render(request, 'warehouse.html')

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #14
0
def user(request):
    '''加载用户管理页面'''
    try:
        return render(request, 'user.html')

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #15
0
def material(request):
    '''加载物料管理页面'''
    try:
        return render(request, 'material.html')

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #16
0
def do_login(request):
    '''执行登陆'''
    try:
        # 读取POST信息
        rp = request.POST
        user_name_post = rp['user_name']
        password_post = rp['password']

        # 查找用户和用户状态
        w = "user_name='%s'" % user_name_post
        user_model_list = User.objects.extra(
            where=[w, "is_visible=1", "is_enable=1"])
        if not (user_model_list):
            raise Login_err

        # 校验密码
        password_cur = user_model_list[0].password
        if (password_cur != password_post):
            raise Login_err

        # 检查角色状态
        gp = Group.objects.get(id=user_model_list[0].group_id)
        if not (gp.is_visible and gp.is_enable):
            raise Login_err

        # 加载用户信息到session
        user_info = user_model_list[0].todict()
        permission_moudle = gp.permission_moudle
        permission_account = gp.permission_account
        permission_edit_master = str(gp.permission_edit_master)

        # 转换成查询条件格式
        pers = permission_moudle.split(',')
        if type(pers) is list:
            permission_moudle = '; '.join(pers)
        pers = permission_account.split(',')
        if type(pers) is list:
            permission_account = '; '.join(pers)

        user_info.update({
            'permission_moudle': permission_moudle,
            'permission_account': permission_account,
            'permission_edit_master': permission_edit_master,
        })
        request.session['user_info'] = user_info

        # 写入登录日志
        loginlog.loginlog_add(request)
        info_back = {'state': 1}

    except Exception as e:
        info_back = {'state': 0, 'err': str(e)}
        errlog.errlog_add(request, str(e))

    finally:
        return HttpResponse(json.dumps(info_back))
Example #17
0
def down_excel_template(request):
    '''下载EXCEL数据导入模板'''
    try:
        fields_import = import_fields[MASTER_MODEL.__name__]
        response = importer.get_template(request, fields_import)
        return response

    except Exception as e:
        errlog.errlog_add(request, str(e))
        message = '操作失败!错误:%s。' % str(e)
        code = 3
        return restful.result(code=code, message=message)
Example #18
0
def down_excel_template(request):
    '''下载EXCEL数据导入模板'''
    try:
        fields_import = import_fields[MASTER_MODEL.__name__]
        response = importer.get_template(request, fields_import)
        return response

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #19
0
def lists(request):
    '''获得分组列表'''
    try:
        groups = Group.objects.filter(is_visible=True)
        li = []
        for g in groups:
            li.append({'id': g.id, 'text': g.group_name})
        return HttpResponse(json.dumps(li))

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #20
0
def login(request):
    '''加载登录页面'''
    try:
        # 项目名,版权信息,提示信息
        context = {
            'PROJECT_NAME': PROJECT_NAME,
            'COPYRIGHT': COPYRIGHT,
        }
        return render(request, 'login.html', context)
    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #21
0
def index(request):
    '''加载主页'''
    try:
        # 加载用户信息到session
        context = {
            'PROJECT_NAME': PROJECT_NAME,
            'COPYRIGHT': COPYRIGHT,
            'user_info': request.session['user_info'],
        }
        return render(request, 'index.html', context)
    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #22
0
def loginlog_add(request):
    '''添加登陆日志'''
    try:
        log = Loginlog()
        log.user_id = request.session['user_info']['id']
        rip = request.META.get('HTTP_X_FORWARDED_FOR')
        if not rip:
            rip = request.META.get("REMOTE_ADDR")
        log.login_ip = rip
        log.login_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        log.save()
    except Exception as e:
        errlog.errlog_add(request, str(e))
Example #23
0
def clean_querys(request):
    '''清理缓存'''
    try:
        model = MASTER_MODEL
        query_mark = MASTER_NAME
        operator.clean_querys(request, model, query_mark)
        msg = '操作成功!已成功执行缓存清理操作。'
        info_back = {'type': 1, 'msg': msg}

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #24
0
def clean_querys(request):
    '''清理缓存'''
    try:
        model = MASTER_MODEL
        query_mark = MASTER_NAME
        operator.clean_querys(request, model, query_mark)
        message = '操作成功!已成功执行缓存清理操作。'
        code = 1
        return restful.result(code=code, message=message)

    except Exception as e:
        errlog.errlog_add(request, str(e))
        message = '操作失败!错误:%s。' % str(e)
        code = 3
        return restful.result(code=code, message=message)
Example #25
0
def export_excel(request):
    '''导出EXCEL'''
    try:
        model = MASTER_MODEL
        query_mark = MASTER_NAME
        fields_export = export_fields[MASTER_MODEL.__name__]
        joins = join_fields[MASTER_MODEL.__name__]

        response = reader.export_excel(request, model, query_mark,
                                       fields_export, joins)
        return response

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #26
0
def load_data(request):
    '''获取分页数据'''
    try:
        model = MASTER_MODEL
        query_mark = MASTER_NAME
        page_num = int(request.GET['page'])
        row_num = int(request.GET['rows'])
        joins = join_fields[MASTER_MODEL.__name__]

        data = reader.load(request, model, query_mark, page_num, row_num,
                           joins)
        return HttpResponse(data)

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #27
0
def upload_excel(request):
    '''上传EXCEL导入施工单位数据'''
    try:
        model = MASTER_MODEL
        query_mark = MASTER_NAME
        file = request.FILES.get('file_upload')
        fields_import = import_fields[MASTER_MODEL.__name__]
        joins = join_fields[MASTER_MODEL.__name__]

        result = importer.read_excel(request, model, query_mark, file,
                                     fields_import, joins)
        return HttpResponse(result)

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}
        return HttpResponse(json.dumps(info_back))
Example #28
0
def lists(request):
    '''获得施工单位代码列表'''
    try:

        pa = request.session['user_info']['permission_wh']
        pa = pa.split('; ')
        if type(pa) is not list:
            pa = [pa]

        conss = MASTER_MODEL.objects.filter(is_visible=True, is_enable=True)
        li = []
        for p in conss:
            li.append({'cons_mark': p.cons_mark, 'cons_name': p.cons_name})
        print(li)
        return HttpResponse(json.dumps(li))

    except Exception as e:
        errlog.errlog_add(request, str(e))
        return HttpResponse(str(e))
Example #29
0
def import_data(request):
    '''执行工厂数据导入'''
    try:
        model = MASTER_MODEL
        query_mark = MASTER_NAME
        fields_import = import_fields[MASTER_MODEL.__name__]

        res = importer.import_rows(request, model, query_mark, fields_import)

        context = (MASTER_NAME, res['insert'], MASTER_NAME, res['update'])
        message = '操作成功!新增%s %d 个,更新%s %d 个。' % context
        code = 1

    except Exception as e:
        errlog.errlog_add(request, str(e))
        message = '操作失败!错误:%s。' % str(e)
        code = 3

    finally:
        return restful.result(code=code, message=message)
Example #30
0
def import_data(request):
    '''执行施工单位数据导入'''
    try:
        model = MASTER_MODEL
        query_mark = MASTER_NAME
        fields_import = import_fields[MASTER_MODEL.__name__]

        res = importer.import_rows(request, model, query_mark, fields_import)

        context = (MASTER_NAME, res['insert'], MASTER_NAME, res['update'])
        msg = '操作成功!新增%s %d 个,更新%s %d 个。' % context
        info_back = {'type': 1, 'msg': msg}

    except Exception as e:
        errlog.errlog_add(request, str(e))
        msg = '操作失败!错误:%s。' % str(e)
        info_back = {'type': 3, 'msg': msg}

    finally:
        return HttpResponse(json.dumps(info_back))