예제 #1
0
def overview(request):
    ret_vars = {}

    if session.check_is_login(request):
        user_name = session.get_user_name(request)
        ret_vars['username'] = user_name

        user = models.User.objects.get(name=user_name)
        user_message = models.User_Message.objects.values('message_id').filter(
            user_id=user.id)
        user_message_list = [i['message_id'] for i in user_message]
        message_list = models.Message.objects.exclude(id__in=user_message_list)
        message_count = models.Message.objects.count()
        device_count = models.Device.objects.count()
        devices = models.Device.objects.all()
        device_points = []
        for d in devices:
            device_points.append(
                [d.location_x, d.location_y, d.video_url, d.hint])

        ret_vars['message_list'] = serializers.serialize('json', message_list)
        ret_vars['device_count'] = device_count
        ret_vars['un_deal'] = message_count - len(user_message)
        ret_vars['user_deal'] = len(user_message)
        ret_vars['device_points'] = json.dumps(device_points)
        print(user_message)

        return render(request, 'overview.html', ret_vars)

    return redirect('/login')
예제 #2
0
def getUserConf(request):
    response = HttpResponse()

    if not session.check_is_login(request):
        response.status_code = 400
        response.content = '没有登陆'
        return response

    if request.method == "GET":

        user_name = request.session["user_name"]
        user = models.User.objects.get(name=user_name)

        response.content = json.dumps({
            "layout": user.layout,
            "email": user.email,
            "wechatOpenId": user.wechat_id,
            "telephone": user.phone
        })
        response.status_code = 200

    else:
        response.status_code = 400
        response.content = "Wrong Method"

    return response
예제 #3
0
def get_messages(request):
    response = HttpResponse()

    if not session.check_is_login(request):
        response.status_code = 400
        response.content = 'Not Login'
        return response

    if request.method == "GET":
        limit = generate_parameter(request, "limit")
        offset = generate_parameter(request, "offset")
        type = generate_parameter(requests, "type")
        limit = int(limit)
        offset = int(offset)

        if type == "unread":
            pass

        user_name = get_user_name(request)

        print(user_name)

    else:
        response.status_code = 400
        response.content = "Wrong Method"
예제 #4
0
def login_controller(request: wsgi.WSGIRequest):
    response = HttpResponse()

    if session.check_is_login(request):
        response.status_code = 200
        response.content = '已登录'

    if request.method == "POST":
        print(request.body)
        data = json.loads(request.body)
        user_name = data.get('username')
        password = data.get('password')
        # user_name = request.GET.get('param')
        # password  = request.GET.get('password')

        try:
            user = get_user_by_user_name(user_name)
            if user.password == password:
                session.set_session(request, True, user.name, user.id)
                response.status_code = 200
                response.content = "欢迎你\n" + user.name
            else:
                response.status_code = 400
                response.content = '用户名或密码不正确'
        except models.User.DoesNotExist:
            response.status_code = 400
            response.content = 'User not exists'

    else:
        response.status_code = 400
        response.content = "Wrong method"

    return response
예제 #5
0
def conf(request):
    ret_vars = {}

    if session.check_is_login(request):
        ret_vars['username'] = request.session['user_name']

        return render(request, 'conf.html', ret_vars)

    return redirect('/login')
예제 #6
0
def logout(request):
    # the logout function

    if not session.check_is_login(request):
        return redirect('/login/')

    request.session.flush()

    return redirect('/login/')
예제 #7
0
def check_is_login_and_get_username_controller(request):
    response = HttpResponse()
    if session.check_is_login(request):
        response.status_code = 200
        user_name = session.get_user_name(request)
        print(user_name)
        utils.serve_data_response(response, user_name)
    else:
        response.status_code = 400
        response.content = 'Not login'
    return response
예제 #8
0
def MessageAmount(request):
    response = HttpResponse()

    if not session.check_is_login(request):
        response.status_code = 400
        response.content = '没有登陆'
        return response

    response.content = models.Message.objects.all().count()
    print(response.content)
    response.status_code = 200
    return response
예제 #9
0
def monitor(request):
    ret_vars = {}

    if session.check_is_login(request):
        user_name = session.get_user_name(request)
        ret_vars['username'] = user_name
        user = models.User.objects.get(name=user_name)
        video_list = models.Video.objects.filter(user_id=user.id)
        ret_vars['video_list'] = serializers.serialize('json', video_list)
        ret_vars['default_layout'] = user.layout

        return render(request, 'monitor.html', ret_vars)

    return redirect('/login')
예제 #10
0
def dealFalse(request):
    response = HttpResponse()

    if not session.check_is_login(request):
        response.status_code = 400
        response.content = '没有登陆'
        return response

    if request.method == 'POST':

        id_array = request.POST['data'].split(',')

        print(id_array)
        user = models.User.objects.get(name=session.get_user_name(request))

        try:

            for id in id_array:
                message = models.Message.objects.get(id=id)
                if models.User_Message.objects.filter(
                        user_id=user, message_id=message).exists():
                    models.User_Message.objects.filter(
                        user_id=user,
                        message_id=message).update(true_or_false=False)
                else:
                    models.User_Message.objects.create(
                        user_id=user,
                        message_id=models.Message.objects.get(id=id),
                        true_or_false=False)
        except:
            response.status_code = 500
            raise Exception()

        else:
            response.status_code = 200

        return response

    else:

        response.status_code = 404
        response.content = '找不到页面'
        return response
예제 #11
0
def warning(request):
    print("This is the type")
    print(type(request))
    ret_vars = {}

    if session.check_is_login(request):
        user_name = session.get_user_name(request)
        ret_vars['username'] = user_name

        user = models.User.objects.get(name=user_name)
        user_message = models.User_Message.objects.values(
            'message_id', 'true_or_false').filter(user_id=user.id)
        print(user_message)
        user_message_dict = {}
        for i in user_message:
            print(i)
            user_message_dict[i['message_id']] = 'true'
        print(user_message_dict)
        message_list = models.Message.objects.all()

        user_message_list = [{
            'id': i.id,
            'content': i.content,
            'img_url': i.img_url,
            'device_number': i.serial_number.id,
            'device_hint': i.serial_number.hint,
            'deal': i.id in user_message_dict,
            'c_time': i.c_time.strftime('%Y-%m-%d')
        } for i in message_list]

        print(user_message_list)
        ret_vars['user_message_list'] = json.dumps(user_message_list)

        # ret_vars['message_list'] = serializers.serialize('json', message_list)

        return render(request, 'warning.html', ret_vars)

    return redirect('/login')