コード例 #1
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def setHot(request):
    """
    设置某个老师为热门或者非热门
    :param request:
    :return:
    """
    id = request.data.get('id',None)
    userType = request.data.get('user',None)
    method = request.data.get('type',None)
    if userType == "parent":
        if method:
            #设为热门
            resNum = ParentOrder.objects.filter(tea_id = id).update(hot_not=1)
        else:
            resNum = ParentOrder.objects.filter(tea_id = id).update(hot_not=0)
    elif userType == "teacher":
        if method:
            #设为热门
            resNum = Teacher.objects.filter(tea_id = id).update(hot_not=1)
        else:
            resNum = Teacher.objects.filter(tea_id = id).update(hot_not=0)
    else:
        return JsonError(u"输入数据的user值不对")
    if resNum == 1:
        return JsonResponse()
    else:
        return JsonError("not found")
コード例 #2
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def setPass(request):
    """
    审核某个家长或老师简历,是否通过
    :param request:
    {
      "id":1,
      "type":0,
      "user":"******"
    }
    :return:
    """
    id = request.data.get('id',None)
    method = request.data.get('type',None)
    userType = request.data.get('user',None)
    if userType == "parent":
        if method:
            resNum = ParentOrder.objects.filter(pd_id = id).update(pass_not=2)
        else:
            resNum = ParentOrder.objects.filter(pd_id = id).update(pass_not=0)
    elif userType == "teacher":

        #TODO:消息通知?
        if method:
            resNum = Teacher.objects.filter(tea_id = id).update(pass_not=2)
        else:
            resNum = Teacher.objects.filter(tea_id = id).update(pass_not=0)
    if resNum == 1:
        return JsonResponse()
    else:
        return JsonError("not found")
コード例 #3
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def updateInfo(request):
    """
    更新某个家长或者老师用户信息
    :param request:
    {
      "id":1,
      "userInfo":{"name":"管理员修改过"},
      "user":"******"
    }
    :return:
    """
    id = request.data.get('id',None)
    userType = request.data.get('user',None)
    temp = request.data.dict()  if (type(request.data.get('userInfo', {})) != type({})) else request.data.get('userInfo', {})
    now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    temp['update_time']= now
    changeObejct(temp)
    if userType == "parent":
        resNum = ParentOrder.objects.filter(pd_id = id).update(**temp)
    elif userType == "teacher":
        resNum = Teacher.objects.filter(tea_id = id).update(**temp)
    else:
        return JsonError(u"输入数据的user值不对")
    if resNum == 1:
        return JsonResponse()
    else:
        return JsonError("not found")
コード例 #4
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def remindFeedBack(request):
    """
    提醒某个用户提交反馈
    :param request:
    :return:
    """
    id = request.data.get('id',None)
    userType = request.data.get('user',None)
    user = AuthUser.objects.get(username=request.user.username)
    message_title = u"好学吧家教邀请您填写反馈意见!"
    message_content = u"好学吧家教邀请您填写反馈意见!"
    if userType == "parent":
        objs = ParentOrder.objects.filter(pd_id = id)
    elif userType == "teacher":
        objs = Teacher.objects.filter(tea_id = id)
    else:
        return JsonError(u"输入数据的user值不对")
    if len(objs):
        obj = objs[0]
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        message = Message(sender=user, receiver=obj.wechat, message_title=message_title,
                          message_content=message_content,status=0,update_time=now,create_time=now)
        message.save()
        return JsonResponse()
    else:
        return JsonError(u"找不到用户!")
コード例 #5
0
def getOrder(request):
    user = AuthUser.objects.get(username=request.user.username)
    t = user.teacher_set.all()
    pd = user.parentorder_set.all()
    size = int(request.data.get("size", 0))
    start = int(request.data.get("start", 0)) * size
    if len(t) > 0:
        #老师的订单详情
        oas = OrderApply.objects.filter(
            tea=t[0]).order_by('-update_time')[start:size]
        results = []
        for oa in oas:
            oa.name = oa.pd.name
            oa.result = getParentResult(oa)
        return Response(OrderApplySerializer(oas, many=True).data)

    elif len(pd) > 0:
        #家长的订单详情
        oas = OrderApply.objects.filter(
            pd=pd[0]).order_by('-update_time')[start:size]
        results = []
        for oa in oas:
            oa.name = oa.tea.name
            oa.result = getTeacherResult(oa)
        return Response(OrderApplySerializer(oas, many=True).data)
    else:
        return JsonResponse([])
コード例 #6
0
def setLocations(request):
    """
    用户设置locations
    :param request:
        {
        "longitude":23.0580629881,
        "latitude":113.3853235930
        }
    :return:
    """
    try:
        longitude = float(request.data.get("longitude", -1))
        latitude = float(request.data.get("latitude", -1))
        user = AuthUser.objects.get(username=request.user.username)
        address = getAddress(latitude, longitude)
        locations = user.locations_set.all()
        if len(locations) > 0:
            l = locations[0]
            l.longitude = longitude
            l.latitude = latitude
            l.address = address
        else:
            l = Locations(longitude=longitude,
                          latitude=latitude,
                          wechat=user,
                          address=address)
        l.save()
        return JsonResponse()
    except Exception, e:
        print 'traceback.print_exc():'
        traceback.print_exc()
        return JsonError(e.message)
コード例 #7
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def getFeedBack(request):
    """
    查看反馈
    :param request:
    {
        "start":0,
        "size":6
    }
    :return:
    """
    size = int(request.data.get("size",0))
    start = int(request.data.get("start",0)) * size
    fbs = Feedback.objects.all().order_by('-create_time')[start : start + size]
    rating = ['one','two','three','four','five']
    for fb in fbs:
        user = fb.wechat
        teacher = user.teacher_set.all()
        parent =  user.parentorder_set.all()
        if len(parent):
            fb.name = parent[0].name
        if len(teacher):
            fb.name = teacher[0].name
        rate = int(fb.rate)
        for i,v in enumerate(rating):
            if i < rate:
                setattr(fb,v,True)
            else:
                setattr(fb,v,False)
    serializer = FeedbackSerializer(fbs,many=True)
    return JsonResponse(serializer.data)
コード例 #8
0
def getPayInfo(request):
    """
    获取订单的支付信息,订单开始计时
    :param request:
    :return:
    """
    payAmount = 50  #支付金额
    payAccount = 18812341235  #支付账号
    user = AuthUser.objects.get(username=request.user.username)
    teas = user.teacher_set.all()
    if len(teas):
        tea = teas[0]
        oa_id = request.data.get('oa_id', None)
        oas = OrderApply.objects.filter(oa_id=oa_id,
                                        tea=tea,
                                        finished=0,
                                        teacher_willing=1)
        print oas
        # if len(oas):
        #     oa = oas[0]
        #     oa.teacher_willing = 2
        #     oa.update_time = timezone.now()
        #     oa.save()
    else:
        return JsonError(u"你的信息不存在!")

    return JsonResponse({payAccount: payAccount, payAmount: payAmount})
コード例 #9
0
def uploadScreenshot(request):
    """
    上传订单截图
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    teas = user.teacher_set.all()
    pic = request.data.get('pic', None)
    oa_id = int(request.data.get('oa_id', -1))
    if len(teas):
        tea = teas[0]
        order_applys = OrderApply.objects.filter(oa_id=oa_id, tea=tea)
        if len(order_applys):
            name = changeSingleBaseToImg(pic)
            order_apply = order_applys[0]
            order_apply.screenshot_path = name
            order_apply.finished = 2
            order_apply.update_time = timezone.now()
            order_apply.save()
            return JsonResponse()
        else:
            return JsonError(u"找不到该订单")
    else:
        return JsonError(u"出错,你的老师信息不存在,请重新调调查问卷!")
コード例 #10
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def sendPhone(request):
    """
    发送联系方式给某个老师
    :param request:{"tea_id":1,"tel":18812345678,"oa_id":3}
    :return:
    """
    tea_id = request.data.get('tea_id',None)
    oa_id = request.data.get('oa_id',None)
    tel = request.data.get('tel',None)
    teas = Teacher.objects.filter(tea_id=tea_id)
    oas = OrderApply.objects.filter(oa_id=oa_id)
    user = AuthUser.objects.get(username=request.user.username)
    if len(teas) and len(oas):
        tea = teas[0]
        oa = oas[0]
        pd_name  = oa.pd.name
        message_title = u"向您发送了" + pd_name +u"家长的联系方式!"
        message_content = pd_name + u"家长的联系方式是" + str(tel)
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        message = Message(sender=user, receiver=tea.wechat, message_title=message_title,
                          message_content=message_content,status=0,update_time=now,create_time=now)
        message.save()
        oa.tel = str(tel)
        oa.finished = 1
        oa.save()
        return JsonResponse()
    else:
        return JsonError(u"输入数据有误")
コード例 #11
0
def createTeacher(request):
    """
    创建老师
    :param request:
    :return:
    """
    try:
        user = AuthUser.objects.get(username=request.user.username)
        teachers = user.teacher_set.all()
        if not user.is_superuser and len(teachers) > 0:
            return JsonError("already existed")
        if request.method == 'POST':
            temp = request.data.dict() if (
                type(request.data) != type({})) else request.data
            changeObejct(temp)
            photos = temp.get('teach_show_photo', None)
            if photos and photos != "":
                temp['teach_show_photo'] = changeBaseToImg(photos)
            certificate_photo = temp.get('certificate_photo', None)
            if certificate_photo and certificate_photo != "":
                temp['certificate_photo'] = changeSingleBaseToImg(
                    certificate_photo)
            now = time.strftime('%Y-%m-%d %H:%M:%S',
                                time.localtime(time.time()))
            temp['create_time'] = now
            temp['update_time'] = now
            teacher = Teacher(**temp)
            teacher.wechat = user
            teacher.save()
        return JsonResponse({"wechat_id": teacher.wechat_id})
    except Exception, e:
        print 'traceback.print_exc():'
        traceback.print_exc()
        return JsonError(e.message)
コード例 #12
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def deleteOrder(request):
    oa_id = int(request.data.get('oa_id',0))
    oas = OrderApply.objects.filter(oa_id=oa_id)
    if len(oas):
        oa = oas[0]
        oa.delete()
        return JsonResponse()
    else:
        return JsonError(u"not found")
コード例 #13
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def setWechat(request):
    """
    绑定微信号
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    user.first_name = request.session['info']['openid']
    user.save()
    return JsonResponse()
コード例 #14
0
def getUserAddress(request):
    """

    :param request:
    :return:
    """
    longitude = float(request.data.get("longitude", -1))
    latitude = float(request.data.get("latitude", -1))
    address = getAddress(longitude, latitude)
    return JsonResponse({'address': address})
コード例 #15
0
ファイル: views.py プロジェクト: zhy0313/tutor
def uploadImgServerId(request):
    """
    上传微信端的serverId,然后下载照片存放在本地
    :param request:
    :return:
    """
    serverId = request.data.get('serverId', None)
    print downloadImg(serverId)
    print 'serverId ==================='
    print serverId
    return JsonResponse()
コード例 #16
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def loginAdmin(request):
    username = request.data.get('username',None)
    password = request.data.get('password',None)
    user = authenticate(username=username, password=password)
    if user is not None:
        # the password verified for the user
        if user.is_active:
            login(request,user)
            return JsonResponse()
    else:
        # the authentication system was unable to verify the username and password
        return JsonError('The username and password were incorrect.')
コード例 #17
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def getNum(request):
    """
    get获取家长和老师的数目
    :param request:
    :return:
    """
    teacherNum = Teacher.objects.count()
    parentNum = ParentOrder.objects.count()
    return JsonResponse({
        "teacherNum":teacherNum,
        "parentNum":parentNum
    })
コード例 #18
0
def deleteParent(request):
    """
    删除
    :param request:
    :return:
    """
    #TODO:删除外键约束
    user = AuthUser.objects.get(username=request.user.username)
    parentorder = user.parentorder_set.all()
    if len(parentorder) > 0:
        parentorder[0].delete()
        return JsonResponse()
    return JsonError("not found")
コード例 #19
0
def deleteTeacher(request):
    """
    删除
    :param request:
    :return:
    """
    #TODO:删除外键约束
    user = AuthUser.objects.get(username=request.user.username)
    teachers = user.teacher_set.all()
    if len(teachers) > 0:
        teachers[0].delete()
        return JsonResponse()
    return JsonError("not found")
コード例 #20
0
ファイル: views.py プロジェクト: zhy0313/tutor
def generate_signature(request):
    """
    生成jssdk所需的_signature
    :param request: {"timestamp":"1482652615","nonceStr":"yinzishao","url":"http://www.yinzishao.cn/testjs"}
    :return:
    """
    timestamp = request.data.get('timestamp', None)
    nonceStr = request.data.get('nonceStr', None)
    url = request.data.get('url', None)

    if not url:
        url = request.META['HTTP_REFERER']
    return JsonResponse(
        {"signature": generate_jsapi_signature(timestamp, nonceStr, url)})
コード例 #21
0
def readMessage(request):
    """
    阅读消息,将status改为1
    :param request:
    {
        "msg_id":1
    }
    :return:
    """
    msg_id = request.data.get("msg_id", None)
    user = AuthUser.objects.get(username=request.user.username)
    now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
    msg = Message.objects.filter(msg_id=msg_id, receiver = user).update(status=1,update_time=now)
    return JsonResponse()
コード例 #22
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def handleUserOrder(request):
    """
    管理员处理订单
    :param request:
    {
     "oa_id": 1         订单ID
     "user":teacher/parent,           修改老师还是家长的意愿
     "willing": 0/1/2      0/1/2  0:拒绝 1:待处理 2:接受
     }
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    oa_id = int(request.data.get('oa_id',0))
    userType = request.data.get('user',None)
    willing = request.data.get('willing',None)
    try:
        oa = OrderApply.objects.get(oa_id = oa_id)
        if userType == 'teacher':
            #TODO:管理员暂时无法处理老师的订单
            if willing == 0:
                oa.teacher_willing = 0
                oa.finished = 1
            if willing == 2:
                oa.teacher_willing = 2
        if userType == 'parent':
            #将家长意愿修改为拒绝
            if willing == 0:
                oa.parent_willing = 0
                oa.finished = 1
                message_title = oa.pd.name + u"拒绝了你的报名!"
                message_content = oa.pd.name +  u"拒绝了你的报名!请到“我的家长”处查看详细信息!"

            if willing == 2:
                oa.parent_willing = 2
                oa.finished = 0
                message_title = oa.pd.name + u"接受了你的报名!"
                message_content = oa.pd.name +  u"接受了你的报名!请到“我的家长”处查看详细信息!"

            now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
            message = Message(sender=user, receiver=oa.tea.wechat, message_title=message_title,
                              message_content=message_content,status=0,update_time=now,create_time=now)
            oa.save()
            message.save()
        return JsonResponse()
    except Exception,e:
        print 'traceback.print_exc():'; traceback.print_exc()
        return JsonError(e.message)
コード例 #23
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def deleteBanner(request):
    try:
        image = request.data.get('image',None)
        img = Config.objects.filter(key='image')[0]
        imgs = img.value.split(',')
        url = Config.objects.filter(key='url')[0]
        urls = url.value.split(',')
        idx = imgs.index(image)
        del imgs[idx]
        del urls[idx]
        url.value = ",".join(urls)
        img.value = ",".join(imgs)
        url.save()
        img.save()
        return JsonResponse()
    except Exception,e:
        print e
        return JsonError(e.message)
コード例 #24
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def deleteUser(request):
    """
    删除用户
    :param request: {"id":1,"user":"******"}
    :return:
    """
    #TODO:删除外键约束
    userType = request.data.get('user',None)
    id = request.data.get('id',None)
    if userType == "parent":
        obj = ParentOrder.objects.filter(pd_id=id)
    elif userType == "teacher":
        obj = Teacher.objects.filter(tea_id=id)
    else:
        return JsonError(u"输入数据的user值不对")
    if len(obj):
        obj[0].delete()
    else:
        return JsonError(u"找不到该用户")
    return JsonResponse()
コード例 #25
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def getInfo(request):
    """
    获取某个家长或者老师的信息
    :param request:
    {
      "id":1,
      "format":true/false,
      "user":"******"
    }
    :return:
    """
    id = request.data.get('id',None)
    format = request.data.get('format',None)
    userType = request.data.get('user',None)
    if userType == "parent":
        pds = ParentOrder.objects.filter(pd_id = id)
        if len(pds):
            serializer = ParentOrderSerializer(pds[0])
            result = serializer.data
        else:
            return JsonError("not found")
        if format:
            getParentOrderObj(result)
        else:
            changeTime(result)
    elif userType == "teacher":
        teas = Teacher.objects.filter(tea_id=id)
        if len(teas):
            serializer = TeacherSerializer(teas[0])
            result = serializer.data
        else:
            return JsonError("not found")
        if format:
            getTeacherObj(result)
        else:
            defaultChangeTeachShowPhoto(result)
            changeTime(result)

    else:
        return JsonError(u"输入数据的user值不对")
    return JsonResponse(result)
コード例 #26
0
def updateParentOrder(request):
    """
    更新家长订单
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    parentorder = user.parentorder_set.all()
    if request.method == 'POST' and len(parentorder) > 0:
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        temp = request.data.dict()  if (type(request.data) != type({})) else request.data
        changeObejct(temp)
        temp['update_time']= now
        temp['pass_not'] =1
        po = user.parentorder_set.update(**temp)
        return JsonResponse()
        # serializer = ParentOrderSerializer(user.parentorder_set.all()[0])
        # result = serializer.data
        # getParentOrderObj(result)
        # return Response(result)
    return JsonError("not found")
コード例 #27
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def checkWechat(request):
    """
    检查绑定的微信账号
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    if user.first_name == '':
        return JsonResponse({"success":3})
        return JsonResponse(u'没有绑定微信')
    elif request.session['info']['openid'] != user.first_name:
        return JsonResponse({"success":2})
        return JsonResponse(u'管理员绑定微信账号跟您登录的账号不符,是否重新绑定')
    else:
        return JsonResponse({"success":1})
        return JsonResponse(u'登录跟绑定一致')
コード例 #28
0
def createParentOrder(request):
    """
    创建家长订单
    :param request:
    :return:
    """
    user = AuthUser.objects.get(username=request.user.username)
    parentorder = user.parentorder_set.all()
    #TODO:管理员创建多个会有什么连锁反应
    #TODO:这个以后会加个限制,不让同时创建老师和家长
    if not user.is_superuser and len(parentorder) > 0:
        return JsonError("already existed")
    if request.method == 'POST':
        temp = request.data.dict()  if (type(request.data) != type({})) else request.data
        changeObejct(temp)
        now = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
        temp['create_time']= now
        temp['update_time']= now
        po = ParentOrder(**temp)
        po.wechat = user
        po.save()
    return JsonResponse({"wechat_id":po.wechat_id})
コード例 #29
0
ファイル: admin.py プロジェクト: zhy0313/tutor
def getCheckList(request):
    """
    获取审核页面的信息
    :param request:{"selected":1,"start":0,"size":6}
    :return:
    """

    selected = request.data.get('selected',None)    #当为1时:简历投递, 2:家长需求
    format = request.data.get('format',None)
    size = int(request.data.get("size",0))
    start = int(request.data.get("start",0)) * size
    res = []
    if selected == 1:
        teas = Teacher.objects.filter(pass_not = 1).order_by('-update_time')[start:start+size]
        serializer = TeacherSerializer(teas,many=True)
        result = serializer.data
        for r in result:
            temp = {
                "name": r['name'],
                "create_time":r['create_time'],
                "tea_id": r["tea_id"]
            }
            res.append(temp)
    elif selected == 2:
        pds = ParentOrder.objects.filter(pass_not = 1).order_by('-update_time')[start:start+size]
        serializer = ParentOrderSerializer(pds,many=True)
        result = serializer.data

        for r in result:
            temp = {
                "name": r['name'],
                "create_time":r['create_time'],
                "pd_id": r["pd_id"]
            }
            res.append(temp)


    return JsonResponse(res)
コード例 #30
0
ファイル: views.py プロジェクト: zhy0313/tutor
def getText(request):
    """
    获取系统一些配置信息
    :param request:
    :return:
    """
    key = request.data.get('key', None)
    result = {}
    try:
        for k in key:
            if k == "getImg":
                value = []
                image = Config.objects.filter(key='image')[0].value
                url = Config.objects.filter(key='url')[0].value
                imgs = image.split(',') if image != "" else []
                urls = url.split(',') if image != "" else []
                for i, v in enumerate(imgs):
                    value.append({"img": v, "url": urls[i]})
            else:
                value = Config.objects.get(key=k).value
            result[k] = value
        return JsonResponse(result)
    except Exception, e:
        return JsonError(e.message)