Esempio n. 1
0
def status(request):
    """
    部门项目的禁用与启用
    :param request:
    :return:
    """
    post = request.POST

    type = post.get('tid')
    psw = post.get('psw')
    password = request.user.password        # 验证管理员密码
    res = check_password(psw,password)
    if not res:
        return ajax_ok(data={"error":u'密码输入错误',"status":0})

    if int(type[0]) == 2: # 参数混淆传递后台区分

        p = Position.objects.filter(pk=type[1:]).last()
        if int(p.status) == 1:
            status = 0
        else:
            status = 1
        Position.objects.filter(pk=p.id).update(status=status)
    else:
        d = Depatment.objects.filter(pk=type[1:]).last()
        if int(d.status) == 1:
            status = 0
        else:
            status = 1
        Depatment.objects.filter(pk=d.id).update(status=status)
    return ajax_ok(data={"error":u'',"status":1})
Esempio n. 2
0
def coll(request):
    """收藏专用接口
    ajax请求
    """
    aid = request.GET.get('aid')
    uid = request.user.id
    if Coll.objects.filter(uid=uid, aid=aid).exists():
        return ajax_ok(data=dict(status=0))

    num = Article.objects.filter(pk=aid).update(coll=F('coll') + 1)

    Coll.objects.create(uid=uid, aid=aid, add_time=now)
    return ajax_ok(data=dict(status=1, num=num))
Esempio n. 3
0
def sign(request):
    """签到"""

    uid = request.user.id

    begain_time = today_time + 3600 * 9  # 当前九点的时间错
    end_time = today_time + 3600 * 9 + 3600 / 2  # 九点半的时间错

    now = int(time.time())
    if UserSign.objects.filter(uid=request.user.id,
                               addtime__gt=today_time).exists():  # 当天已签到的不能再签到
        status = -1
        return ajax_ok(dict(status=status))
    if now <= end_time:
        status = 1
    else:
        status = 2

    UserSign.objects.create(uid=uid, status=status, addtime=now)

    return ajax_ok(dict(status=status))
Esempio n. 4
0
def info(request):
    user = request.user
    position = user.position if user.position else u'暂无职位'
    department = user.depart if user.depart else u'暂无部门'
    time1 = time.strftime("%Y/%m/%d %H:%M",
                          user.last_login.timetuple())  # 上课时间
    data = dict(name=user.first_name,
                uid=user.id,
                position1=position,
                department=department,
                level=user.user_type,
                time1=time1)
    return ajax_ok(data)
Esempio n. 5
0
def info_2(request):
    uid = request.POST.get('uid')
    user = User.objects.get(id=uid)
    position = user.position if user.position else u'暂无职位'
    department = user.depart if user.depart else u'暂无部门'
    phone = user.phone
    adress = user.adress
    data = dict(name=user.first_name,
                uid=user.id,
                position1=position,
                department=department,
                level=user.user_type,
                adress=adress,
                phone=phone)

    return ajax_ok(data)
Esempio n. 6
0
def praise(request):
    """"""
    type = request.GET.get('type')
    uid = request.user.id
    aid = request.get.get('aid')
    status = 0
    num = 0
    if Praise.objects.filter(uid=uid, artcile=int(aid),
                             type=int(type)).exists():
        status = 0
    if int(type) == 1:
        Praise.objects.create(uid=uid, artcile=aid, type=1, num=1)
        status = 1
        Article.objects.filter(pk=aid).update(praise=F('praise') + 1)
        num = Article.objects.filter(pk=aid).last().praise
    if int(type) == 2:
        Praise.objects.create(uid=uid, artcile=aid, type=2, num=1)
        status = 1
        ArticleTalk.objects.filter(pk=aid).update(praise=F('praise') + 1)
        num = ArticleTalk.objects.filter(pk=aid).last().praise
    return ajax_ok(dict(status=status, num=num))
Esempio n. 7
0
def user_manage_update(request):
    """修改员工信息 返回模板
    删除用ajax请求

    """
    if request.method == 'POST':
        post = request.POST
        id = int(post.get('id'))
        name = post.get('name').encode('utf8')
        phone = int(post.get('phone'))
        position = post.get('position')
        depart = post.get('depart')
        level = post.get('level').split(':')[-1]
        print position,depart
        p_id = int(position)
        d_id = int(depart)
        adress = post.get('adress')
        if p_id == 0 and d_id != 0:
            d_name = Depatment.objects.filter(pk=d_id).last().name.encode('utf8')
            User.objects.filter(pk=id).update(first_name=name, phone=phone, user_type=level, d_id=d_id,
                                              depart=d_name, adress=adress)
        elif p_id == 0 and d_id == 0:
            User.objects.filter(pk=id).update(first_name=name, phone=phone, user_type=level, adress=adress)
        elif p_id != 0 and d_id == 0:
            p_name = Position.objects.filter(pk=p_id).last().name.encode('utf8')
            User.objects.filter(pk=id).update(first_name=name, phone=phone, user_type=level, p_id=p_id,
                                              position=p_name, adress=adress)
        else:
            d_name = Depatment.objects.filter(pk=d_id).last().name.encode('utf8')
            p_name = Position.objects.filter(pk=p_id).last().name.encode('utf8')
            User.objects.filter(pk=id).update(first_name=name, phone=phone, user_type=level, p_id=p_id, d_id=d_id,
                                              position=p_name, depart=d_name, adress=adress)
        return redirect('/other/user/manage/')
    else:
        type = int(request.GET.get('type'))
        uid = request.GET.get('uid')

        if type == 1:  # type 1 删除 2 返回签到信息
            User.objects.filter(pk=uid).update(status=-1)
        return ajax_ok()
Esempio n. 8
0
def room_manage(request):
    """
    教室管理页面
    多功能合一
    type 1 删除 2 禁用 3启用 4新增 0 首页 5搜索
    """
    type = int(request.GET.get('type',0))
    # status 0 禁用 1启用 2 正在使用 3删除
    if type == 0:
        if request.method == 'POST':
            post = request.POST
            search = int(post.get('search'))

            search_text = post.get('search_txt')
            try:

                if search == 1:
                    res = MeetingRoom.objects.filter(pk=int(search_text), status__gte=0).values('id', 'name', 'type',
                                                                                            'status','num',
                                                                                            'add_time').order_by(
                        '-status')
                elif search == 2:
                    res = MeetingRoom.objects.filter(name__icontains=search_text, status__gte=0).values('id', 'name',
                                                                                                    'type','num',
                                                                                                    'status',
                                                                                                    'add_time').order_by(
                        '-status')
                elif search == 3:
                    content = 1 if '会议' in search_text else 2
                    res = MeetingRoom.objects.filter(type=content, status__gte=0).values('id', 'name','num',
                                                                                                   'type', 'status',
                                                                                                   'add_time').order_by(
                        '-status')
            except:
                request.session['error'] = '错误'
                return redirect('/other/room/manage/')  # 搜索错误返回首页
            data = get_rooms(res)
            return render(request, 'others/user_info/room_manage.html',
                          context={"data": data, "room_num": len(data),"value":search,"content":search_text})
        else:
            error = request.session['error']
            request.session['error'] = ''
            res = MeetingRoom.objects.filter(status__gte=0).values('id','name','type','num','status','add_time').order_by('-status')
            data = get_rooms(res)
            return render(request,'others/user_info/room_manage.html',context={"data":data,"room_num":len(data),"error":error})
    if type == 1:

        cid = int(request.POST.get('id'))
        MeetingRoom.objects.filter(pk=cid).update(status=-1) # 删除
        return ajax_ok()
    if type == 2:
        cid = int(request.POST.get('id'))
        MeetingRoom.objects.filter(pk=cid).update(status=0)  # 禁用
        return ajax_ok()
    if type == 3:
        cid = int(request.POST.get('id'))
        MeetingRoom.objects.filter(pk=cid).update(status=1)  # 启用
        return ajax_ok()
    if type == 4:
        post = request.POST
        name = post.get('name')
        type = post.get('type')
        zaizhong = post.get('zaizhong') # 容纳人数
        status = post.get('status')
        MeetingRoom.objects.create(name=name,num=zaizhong,type=type,status=status,add_time=int(time.time()))
        return redirect('/other/room/manage/')