Exemple #1
0
    def post(self, request):
        email = request.data['email']
        password = request.data['password']

        # if email or password not provided
        if not email or not password:
            return Response({"error": "email and password field empty"}, status=status.HTTP_400_BAD_REQUEST)

        user = User.objects.filter(email=email).first()

        pass_exist = user.check_password(password)
        if not user or not pass_exist:
            return Response({"error": "email/password combination was wrong"}, status=status.HTTP_401_UNAUTHORIZED)

        payload = {
            'id': user.id,
            'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=60),
            'iat': datetime.datetime.utcnow()
        }

        token = jwt.encode(payload, 'secret',
                           algorithm='HS256').decode('utf-8')

        response = Response({}, status=status.HTTP_200_OK)

        response.set_cookie(key='jwt', value=token, httponly=True)
        response.data = {
            'jwt': token,
            'id': user.id
        }
        return response
Exemple #2
0
    def post(self, request):
        Serializer = UserSerializer(data=request.data)
        if Serializer.is_valid(raise_exception=True):
            Serializer.save()

            # generate a token and login
            email = request.data['email']
            password = request.data['password']
            user = User.objects.filter(email=email).first()
            payload = {
                'id': user.id,
                'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=60),
                'iat': datetime.datetime.utcnow()
            }
            token = jwt.encode(payload, 'secret',algorithm='HS256').decode('utf-8')

            response = Response({}, status=status.HTTP_200_OK)

            response.set_cookie(key='jwt', value=token, httponly=True)
            response.data = {
                'jwt': token,
                'id': user.id
            }
            return response
        return Response(Serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #3
0
def crmLoginRequest(request):
    response_data = {}
    email = request.POST.get("emailID")
    password = request.POST.get("password")
    login_result = get_login(email, password)
    print "Printed: %s" % login_result
    if login_result:
        response = HttpResponse('Bharath')
        print "Response: %s" % response

        setData(request, email)
        statusCode = 200
        response_data = {
            'message': 'Data received successfully',
            'data': {},
            'status': 'success',
            'code': 200
        }
        response.set_cookie("cookie_name", "cookie_value")
    else:
        statusCode = 401
        response_data = {
            'message': 'Invalid email or password',
            'data': {
                'email': email,
                'password': password
            },
            'status': 'error',
            'code': 'ERROR'
        }

    return HttpResponse(JSONResponse(response_data), status=statusCode)
Exemple #4
0
def postsign(request):
    email = request.POST.get('email')
    passw = request.POST.get("pass")
    remembr_me = request.POST.get("remember-me")
    try:
        user = authe.sign_in_with_email_and_password(email, passw)
    except:
        message = "invalid credentials"
        return render(request, "index_login.html", {"messg": message})
    print(user['idToken'])
    print(user['localId'])
    # response = render_to_response( 'welcome.html', {"e": email})
    response = redirect("/")
    uid = user['localId']
    if not remembr_me:
        response.set_cookie('uid', uid)
    else:
        response.set_cookie('uid', uid, 2592000)
    return response
Exemple #5
0
def monitoring_list(request, question_id):

    if not request.user.is_authenticated():
        return redirect('/auth/login')

# разбор параметра
# Разделим question id на части     xxx,yyy где xxx - тип мониторинга, yyy - номер страницы пагинации
    gid = get_ids(question_id)
    type = int(gid[0])

    #   Определение доступа
    usr = auth.get_user(request)
    try:
        role = Role.objects.get(user=usr, type=type)
    except ObjectDoesNotExist:
        html_response_err = 'medicament/error_access.html'
        return render_to_response(html_response_err, {})

    if len(gid) > 1:
        page_number = int(gid[1])
    else:
        page_number = 1
    region = 0
    m = 0
    period = 0
    status = '0'
    start_filter = False
    if len(gid) >= 6:
        m = int(gid[2])
        period = int(gid[3])
        status = gid[4]
        region = int(gid[5])
        start_filter = True

    if len(gid) == 7:  # уточнение детализация в отчете
        detail = True
        detail_line = int(gid[6])
        detail_tab = ''  # имя таблицы в табличной части для детализации
    elif len(gid) == 8:
        detail = True
        detail_line = int(gid[6])
        detail_tab = gid[7]  # имя таблицы в табличной части для детализации
    else:
        detail = False
        detail_line = 0
        detail_tab = ''  # имя таблицы в табличной части для детализации
        if 'period' in request.COOKIES:
            period = (int)(request.COOKIES['period'])
            start_filter = True

    if role.role == "К" or role.role == "F":
        see_all = True  # see_all  контроль и создание новых отчетов
        user_hosp = 0
    else:
        see_all = False
        user_hosp = role.hosp
        m = role.hosp.id

# По типам документов
    tab = {}
    if type == 1:  # Лекарства
        doc = Doc1  # используемая модель
        new_doc = create_report_form1  # функция создания новых отчетов
        calc_sum = calc_sum_form1
        result = [['', 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0],
                  ['', 0, 0, 0, 0, 0, 0, 0, 0], ['', 0, 0, 0, 0, 0, 0, 0, 0]]
        html_response_rep = 'medicament/report_form1.html'  # Форма с JQuery
        export_to_excel = exp_to_excel_form1
    elif type == 2:  # кадры
        doc = Doc2  # используемая модель
        new_doc = create_report_form2  # функция создания новых отчетов
        calc_sum = calc_sum_form2
        result = [['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],['',0],\
                  ]
        html_response_rep = 'medicament/report_form2.html'
        export_to_excel = exp_to_excel_form2
    elif type == 3:  # Диспансеризация
        doc = Doc3  # используемая модель
        tab = {
            "tab1000": Doc3Tab1000,
            "tab2000": Doc3Tab2000,
            "tab3000": Doc3Tab3000,
            "tab4000": Doc3Tab4000,
            "tab5000": Doc3Tab5000,
            "tab5000": Doc3Tab5001,
            "tab6000": Doc3Tab6000,
            "tab7000": Doc3Tab7000,
        }

        new_doc = create_report_form3  # функция создания новых отчетов
        calc_sum = calc_sum_form3
        result = [['', 0], ['', 0], ['', 0], ['', 0], ['', 0], ['', 0],
                  ['', 0], ['', 0], ['', 0], ['', 0]]
        html_response_rep = 'medicament/report_form3.html'
        export_to_excel = exp_to_excel_form3

#### Далее не изменять без необходимости
    args = {}
    args.update(csrf(request))
    isOk = True
    html_response = 'medicament/document_list.html'

    if start_filter or detail or request.POST:
        if see_all and 'button_create' in request.POST:
            if 'period_new' in request.POST:
                if request.POST['period_new']:
                    periodInt = int(request.POST['period_new'])
                    datef = request.POST['datef']
                    isOk = new_doc(periodInt,
                                   datef)  # создать новые мониторинги
        if request.POST:
            page_number = 1  # после нового отбора обязательно делать так!!!
            if not see_all:
                m = user_hosp.id
            if 'region' in request.POST:
                region = int(request.POST['region'])
            if 'mo[]' in request.POST:
                mo1 = request.POST['mo[]']
                m = int(mo1)
            if 'period' in request.POST:
                period = int(request.POST['period'])
            if 'status' in request.POST:
                status = request.POST['status']
        is_filter = False

        if period > 0:
            stat = statistic()
            stat.rec_all = doc.objects.filter(period=period).count()

        if see_all and region > 0:
            args['doc_list'] = doc.objects.filter(hosp__region=region)
            is_filter = True
        if m > 0:
            if is_filter:
                args['doc_list'] = args['doc_list'].filter(hosp=m)
            else:
                args['doc_list'] = doc.objects.filter(hosp=m)
                is_filter = True
            is_filter = True
        if period > 0:
            if is_filter:
                args['doc_list'] = args['doc_list'].filter(period=period)
            else:
                args['doc_list'] = doc.objects.filter(period=period)
                is_filter = True
        if status != '0':
            if is_filter:
                args['doc_list'] = args['doc_list'].filter(status=status)
            else:
                args['doc_list'] = doc.objects.filter(status=status)
                is_filter = True
        if not is_filter:
            args['doc_list'] = doc.objects.all()
# после выборки по фильтрам если надо считать отчет, то вызываю сответствующую функцию
        if detail or (see_all and period > 0
                      and 'button_report' in request.POST):
            html_response = html_response_rep
            args['period_name'] = Period.objects.get(pk=period)
            if region > 0:
                args['region_name'] = Region.objects.get(pk=region)

            args[
                'detail_tab'] = detail_tab  # имеет доп смысл как стартовая вкладка
            if detail:
                args['detail_line'] = detail_line
                args['detail'] = True
                if detail_tab.startswith(
                        'tab'
                ):  ### ВНИМАНИЕ секции табличных частей должны вызывать detail_tab с именами tab*
                    row_id = int(detail_line)
                    args['tab'] = tab[detail_tab].objects.filter(
                        doc__period=period, row=row_id)
                    t = tab[detail_tab].objects.filter(doc__period=period,
                                                       row=row_id)
#                    assert False
            result = calc_sum(args['doc_list'])
        if see_all and 'button_export' in request.POST:
            #            assert False
            stat.rec_fltr = args['doc_list'].count()
            stat.rec_complete = args['doc_list'].filter(status='F').count()
            stat.rec_soglas = args['doc_list'].filter(status='W').count()
            stat.rec_correct = args['doc_list'].filter(status='C').count()
            stat.rec_edit = args['doc_list'].filter(status='E').count()
            file_name = export_to_excel(args['doc_list'], period, region, 0,
                                        stat)
            return redirect("/monitor/export/" + file_name)

    else:  # Первый вход по GET
        if see_all:
            args['doc_list'] = doc.objects.all()
        else:
            args['doc_list'] = doc.objects.filter(hosp=user_hosp)


# во всех случаях
    args['doc_type'] = Doc_type.objects.get(pk=type)

    if not see_all:
        args['mo_list'] = Hosp.objects.filter(id=user_hosp.id)
    else:
        args['mo_list'] = Hosp.objects.all()
        args['region_list'] = Region.objects.all()
    args['period_list'] = Period.objects.all()
    args['first_name'] = auth.get_user(request).first_name
    args['right_all'] = see_all
    args['isOk'] = isOk

    #    filtr = [m,period,status]
    args['page_number'] = page_number
    args['period'] = period
    args['status'] = status
    args['hosp'] = m
    args['region'] = region
    args['type'] = type

    args['result'] = result
    #   сортировка
    args['doc_list'] = args['doc_list'].order_by('-date_mod')
    #   пагинатор
    cur_page = Paginator(args['doc_list'], NUM_RECORD_ON_PAGE)
    args['doc_page'] = cur_page.page(page_number)

    # 21/08/2015
    #   return render_to_response(html_response, args)
    response = render_to_response(html_response, args)

    response.set_cookie("period", period, 2678400)
    return response